You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(agents): preserve both assistant and function messages during snapshot clean for Gemini API
Fixes#3759
When `enable_snapshot_clean` is enabled, the `_clean_snapshot_in_memory` method
previously only recreated the FUNCTION message (tool result) but removed both
the ASSISTANT message (tool call request) and FUNCTION message from memory.
This breaks Gemini API which requires both messages to exist together - the tool
call request must be present alongside the tool call result. Without the ASSISTANT
message, Gemini returns the error:
`GenerateContentRequest.contents[0].parts[0].function_response.name: Name cannot be empty`
Changes:
- Added `args` and `extra_content` fields to `_ToolOutputHistoryEntry` to preserve
tool call context for later reconstruction
- Modified `_register_tool_output_for_cache` to accept and store args/extra_content
- Modified `_clean_snapshot_in_memory` to recreate BOTH the ASSISTANT message
(with tool_calls) and the FUNCTION message (with result) when cleaning snapshots
- Updated `_record_tool_calling` to pass args and extra_content to the cache
registration function
This ensures proper tool call message reconstruction that is compatible with
Gemini and other APIs that require paired tool call request/response messages.
0 commit comments