adk-samples icon indicating copy to clipboard operation
adk-samples copied to clipboard

RuntimeWarning "coroutine was never awaited" when calling tool_context.save_artifact from inside a tool

Open nileshtrivedi opened this issue 1 year ago • 3 comments

I was testing the marketing-agency agent which has a subagent logo_create with a tool called generate_image

When this is invoked, the logs show the message:

2025-05-17 09:59:43,009 - INFO - google_llm.py:145 -
LLM Response:
-----------------------------------------------------------
Text:
None
-----------------------------------------------------------
Function calls:
name: generate_image, args: {'img_prompt': 'Create a logo for a software development agency named "libgen.ai". The logo should be modern, sleek, and incorporate elements that suggest technology, artificial intelligence, or coding. The domain name "libgen.ai" should be part of the logo.'}
-----------------------------------------------------------
Raw response:
{"candidates":[{"content":{"parts":[{"function_call":{"args":{"img_prompt":"Create a logo for a software development agency named \"libgen.ai\". The logo should be modern, sleek, and incorporate elements that suggest technology, artificial intelligence, or coding. The domain name \"libgen.ai\" should be part of the logo."},"name":"generate_image"}}],"role":"model"},"finish_reason":"STOP","index":0}],"model_version":"models/gemini-2.5-pro-preview-05-06","usage_metadata":{"candidates_token_count":67,"prompt_token_count":174,"prompt_tokens_details":[{"modality":"TEXT","token_count":174}],"thoughts_token_count":64,"total_token_count":305},"automatic_function_calling_history":[]}
-----------------------------------------------------------

/Users/nt/code/libgenai/adk-samples/agents/marketing-agency/marketing_agency/sub_agents/logo_create/agent.py:51: RuntimeWarning: coroutine 'CallbackContext.save_artifact' was never awaited
  tool_context.save_artifact(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

This has nothing to do with Gemini call for image generation (I tested by writing my own tool that just loads bytes of a local image file and calls tool_context.save_artifact)

It's not just a warning. The image never gets saved as an artifact, even though the tool and the agent report that it was done successfully.

nileshtrivedi avatar May 17 '25 04:05 nileshtrivedi

FWIW, I am running this with adk web from the marketing-agency directory. My google-adk version is 0.5.0, Python version is 3.12.8.

cc: @gulliantonio @mstyer-google

nileshtrivedi avatar May 17 '25 04:05 nileshtrivedi

Looks like all the samples that use artifact operations inside tools need to be changed to support ADK v0.5.0 which has a breaking change as they updated artifact and memory service interface to be async

nileshtrivedi avatar May 17 '25 04:05 nileshtrivedi

This should be fixed by PR #103 . Re-open if you're still experiencing this.

mstyer-google avatar May 21 '25 08:05 mstyer-google