yc1838 commited on
Commit
90d071c
·
1 Parent(s): 8a34f60

fix: stop stripping function_call from additional_kwargs to preserve gemini thought_signatures

Browse files
Files changed (1) hide show
  1. src/lilith_agent/app.py +4 -4
src/lilith_agent/app.py CHANGED
@@ -535,11 +535,11 @@ def build_react_agent(cfg: Config):
535
  response = model.invoke(prompt_msgs)
536
 
537
  # Clean up Gemini signatures and unhelpful metadata to reduce log noise and context bloat
538
- # Note: Do not pop thought_signature or __gemini_function_call_thought_signatures__
539
- # from additional_kwargs as Gemini strictly requires them to be passed back in subsequent tool calls.
 
540
  if hasattr(response, "additional_kwargs"):
541
- # Remove function_call duplicate if it exists in additional_kwargs (redundant with tool_calls)
542
- response.additional_kwargs.pop("function_call", None)
543
 
544
  if hasattr(response, "response_metadata"):
545
  response.response_metadata = _strip_response_metadata_noise(response.response_metadata)
 
535
  response = model.invoke(prompt_msgs)
536
 
537
  # Clean up Gemini signatures and unhelpful metadata to reduce log noise and context bloat
538
+ # Note: We must preserve additional_kwargs EXACTLY as returned by Gemini.
539
+ # Popping 'function_call' or signatures will cause 400 errors in subsequent turns
540
+ # because Gemini requires these tokens/signatures to be echoed back in the history.
541
  if hasattr(response, "additional_kwargs"):
542
+ pass # Keep everything including function_call and signatures
 
543
 
544
  if hasattr(response, "response_metadata"):
545
  response.response_metadata = _strip_response_metadata_noise(response.response_metadata)