Skip to content

fix: include tool fields in CompletionResponse.to_dict()#54

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/justllms-repository-improvements-3ead
Draft

fix: include tool fields in CompletionResponse.to_dict()#54
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/justllms-repository-improvements-3ead

Conversation

@cursor

@cursor cursor Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

CompletionResponse.to_dict() was dropping tool-related metadata when serializing responses. This fix ensures tool calling data is preserved for logging, caching, and downstream consumers.

Feature branch: darshan/fix-completion-response-to-dict

Problem

When calling to_dict() on a CompletionResponse from a tool-calling completion, the following fields were silently omitted:

  • tool_calls inside choice messages
  • tools_used
  • tool_execution_history
  • tool_execution_cost

Solution

  • Serialize choice messages via Message.model_dump() so tool_calls, tool_call_id, and other optional fields are included
  • Conditionally include tools_used, tool_execution_cost, and tool_execution_history when set
  • Serialize tool_execution_history entries via their to_dict() method when available

Tests

Added tests/test_completion_response.py with three unit tests covering tool call serialization, tool metadata fields, and omission when unset.

CI

All checks pass locally: ruff, black, mypy, pytest (97 tests), and build.

Open in Web View Automation 

CompletionResponse.to_dict() dropped tools_used, tool_execution_history,
tool_execution_cost, and tool_calls from serialized messages. Extend
serialization to preserve tool metadata for logging and downstream
consumers, with unit tests.

Co-authored-by: Darshan Harihar <DarshanHarihar1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant