The agent tool can read and change parent state.
()
| 279 | |
| 280 | |
| 281 | def 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 |