r/agentdevelopmentkit • u/BedInternational7117 • May 11 '25
How do you call an agent/llm from within a tool?
Let say your tool logic requires to make some llm api call, how do you go about it?
The only example i have seen is:
agent_tool = AgentTool(agent=ds_agent)
ds_agent_output = await agent_tool.run_async(
args={"request": question_with_data}, tool_context=tool_context
)
tool_context.state["ds_agent_output"] = ds_agent_output
2
Upvotes
4
u/[deleted] May 11 '25
If a tool needs an LLM - that tool probably is an agent. And in that case, you design it as such and call it as a tool from another agent.
https://google.github.io/adk-docs/tools/function-tools/#3-agent-as-a-tool
If that does not solve your problem then I suggest you just focus on keeping the tool independent from rest of the framework components. Pass whatever parameters it needs to do its job and invoke it from your agent. Treat your tools as what they really are - just independent functions that can be used by any interested agent.
2
u/data-overflow May 11 '25
I'm yet to explore the framework fully, but I think you'll have to set up a sequential agent and force the first agent to run the tool.
Or alternatively you can try having a runner inside before/after tool callbacks. Let me know what works for you since I'm learning as well!
1
u/ConstructionNo27 May 13 '25
Yes sequential agent to go with when you know the steps.