MCPcopy Index your code
hub / github.com/google/adk-python / test_update_state

Function test_update_state

tests/unittests/tools/test_agent_tool.py:281–312  ·  view source on GitHub ↗

The agent tool can read and change parent state.

()

Source from the content-addressed store, hash-verified

279
280
281def test_update_state():
282 """The agent tool can read and change parent state."""
283
284 mock_model = testing_utils.MockModel.create(
285 responses=[
286 function_call_no_schema,
287 '{"custom_output": "response1"}',
288 'response2',
289 ]
290 )
291
292 tool_agent = Agent(
293 name='tool_agent',
294 model=mock_model,
295 instruction='input: {state_1}',
296 before_agent_callback=change_state_callback,
297 )
298
299 root_agent = Agent(
300 name='root_agent',
301 model=mock_model,
302 tools=[AgentTool(agent=tool_agent)],
303 )
304
305 runner = testing_utils.InMemoryRunner(root_agent)
306 runner.session.state['state_1'] = 'state1_value'
307
308 runner.run('test1')
309 assert (
310 'input: changed_value' in mock_model.requests[1].config.system_instruction
311 )
312 assert runner.session.state['state_1'] == 'changed_value'
313
314
315@mark.asyncio

Callers

nothing calls this directly

Calls 3

runMethod · 0.95
AgentToolClass · 0.90
createMethod · 0.45

Tested by

no test coverage detected