Repository navigation
fix(tools): pass the caller's temp: state to an AgentTool's wrapped agent - #7596
Open
Somay-kousis wants to merge 1 commit into
Open
Somay-kousis wants to merge 1 commit into
Somay-kousis wants to merge 1 commit into
Conversation
…gent
AgentTool copied the caller's state into create_session for the nested
runner, and create_session drops temp: keys because they are never stored.
The wrapped agent then saw no temp: state: {temp:key} in its instruction
raised KeyError, {temp:key?} rendered empty, and its callbacks and tools
read None. Pass the temp: keys to the nested run_async as state_delta,
which applies them for that invocation without storing them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
AgentTool.run_asynccopies the caller's state,temp:keys included, intocreate_session(state=...)for the nested runner.create_sessiondropstemp:keys because they are never stored, so the wrapped agent can't see them.{temp:key?}in its instruction renders empty,{temp:key}raisesKeyError, and its callbacks and tools readNone.Solution:
Split the
temp:keys out of the copied state and pass them to the nestedrunner.run_asyncasstate_delta. That's the public way to settemp:state for one invocation:append_eventapplies it to the in-memory session, then trims it from the stored event. Other keys still go throughcreate_sessionas before, and nothing is persisted that wasn't before. Values that aren't JSON-serializable reach the wrapped agent unchanged, since they only live in memory.Out of scope:
temp:writes made inside the wrapped agent going back to the caller. Happy to look at that separately.Testing Plan
Unit Tests:
test_agent_tool_reads_caller_temp_stateintests/unittests/tools/test_agent_tool.py, parametrized over each way the wrapped agent reads state: a required{temp:ticket}in its instruction, an optional{temp:ticket?}, itsbefore_agent_callback, a tool it calls, aSequentialAgentwrapping anLlmAgent(the nested runner's legacy path), and an agent withinput_schema. The caller sets a stringtemp:key, atemp:key holding a non-JSON-serializable object (checked by identity) and a plain key.Before the fix:
After the fix:
pyink --checkandisort --check-onlyare clean on the changed files.mypy src/google/adk/tools/agent_tool.pyreports the same one error as on main (AgentTool(agent=agent)infrom_config, an existingBaseNodevsBaseAgentmismatch).Manual End-to-End (E2E) Tests:
The script from the issue runs a coordinator
LlmAgentwith a tool that setstemp:ticketand anAgentToolspecialist, onInMemoryRunnerwith fake models.Before:
After:
Checklist
Additional context
Open PRs touching
agent_tool.py: #6020, #7045, #7249 and #7401. None changes how the caller's state reaches the nested session. #7045 re-indents the event loop, so one of the two may need a small rebase.