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

Function test_update_artifacts

tests/unittests/tools/test_agent_tool.py:316–371  ·  view source on GitHub ↗

The agent tool can read and write artifacts.

()

Source from the content-addressed store, hash-verified

314
315@mark.asyncio
316async def test_update_artifacts():
317 """The agent tool can read and write artifacts."""
318
319 async def before_tool_agent(callback_context: CallbackContext):
320 # Artifact 1 should be available in the tool agent.
321 artifact = await callback_context.load_artifact('artifact_1')
322 await callback_context.save_artifact(
323 'artifact_2', Part.from_text(text=artifact.text + ' 2')
324 )
325
326 tool_agent = SequentialAgent(
327 name='tool_agent',
328 before_agent_callback=before_tool_agent,
329 )
330
331 async def before_main_agent(callback_context: CallbackContext):
332 await callback_context.save_artifact(
333 'artifact_1', Part.from_text(text='test')
334 )
335
336 async def after_main_agent(callback_context: CallbackContext):
337 # Artifact 2 should be available after the tool agent.
338 artifact_2 = await callback_context.load_artifact('artifact_2')
339 await callback_context.save_artifact(
340 'artifact_3', Part.from_text(text=artifact_2.text + ' 3')
341 )
342
343 mock_model = testing_utils.MockModel.create(
344 responses=[function_call_no_schema, 'response2']
345 )
346 root_agent = Agent(
347 name='root_agent',
348 before_agent_callback=before_main_agent,
349 after_agent_callback=after_main_agent,
350 tools=[AgentTool(agent=tool_agent)],
351 model=mock_model,
352 )
353
354 runner = testing_utils.InMemoryRunner(root_agent)
355 runner.run('test1')
356
357 async def load_artifact(filename: str):
358 return await runner.runner.artifact_service.load_artifact(
359 app_name='test_app',
360 user_id='test_user',
361 session_id=runner.session_id,
362 filename=filename,
363 )
364
365 assert await runner.runner.artifact_service.list_artifact_keys(
366 app_name='test_app', user_id='test_user', session_id=runner.session_id
367 ) == ['artifact_1', 'artifact_2', 'artifact_3']
368
369 assert await load_artifact('artifact_1') == Part.from_text(text='test')
370 assert await load_artifact('artifact_2') == Part.from_text(text='test 2')
371 assert await load_artifact('artifact_3') == Part.from_text(text='test 2 3')
372
373

Callers

nothing calls this directly

Calls 6

runMethod · 0.95
SequentialAgentClass · 0.90
AgentToolClass · 0.90
load_artifactFunction · 0.70
createMethod · 0.45
list_artifact_keysMethod · 0.45

Tested by

no test coverage detected