You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to dynamically add/remove tools in a tool_use_behavior="run_llm_again"-loop #767
Have you searched for related issues? Others may have had similar requests: also yes :)
Question
I'm building an agent that's often running multiple tool calls sequentially, and sometimes tool A will 'unlock' tools B, C, and D. But I so far haven't found a way to 'inject' those during an automated run_llm_again loop. And I'm really dreading writing all the logic required to manually handle the run loop.
I've attempted using the Hooks to dynamically add new tools, I've been trying to work with various different Agents as tools, where the tools of those Agents are added dynamically through the hooks. The only thing that's semi worked for me is to use the handoff feature, but then I can't give control back to the 'main' agent.
My agent's flow will normally be like:
User asks for information from Gmail
Agent Runner starts
Agent detects that there's no Gmail connection set up
Agent will call the "initiate gmail connection" tool
Response from the tool 'unlocks' all Gmail actions
Agent calls the 'get latest emails' tool
Agent streams the response
Agent Runner exits
But this is a workflow that I can't currently figure out. Is there a way?
This is a good question. I'll have to think of a long term good answer, but the short term hack is: just add the tools in the initiate_gmail_connection tool call.
Thanks @rm-openai , unfortunately, it seems that extending the tools isn't enough reason to refresh the current_span / agent_span in the _run_streamed_impl (
Activity
rm-openai commentedon May 27, 2025
This is a good question. I'll have to think of a long term good answer, but the short term hack is: just add the tools in the
initiate_gmail_connectiontool call.Afstkla commentedon May 28, 2025
Thanks @rm-openai , unfortunately, it seems that extending the tools isn't enough reason to refresh the
current_span/agent_spanin the_run_streamed_impl(openai-agents-python/src/agents/run.py
Line 518 in 6e078bf
run_llm_againloop (or I tested it wrong, ofc also possible).Any other ideas?
rm-openai commentedon Jun 2, 2025
Ah you're totally right. Let me fix this - we shouldn't be caching the tools list.
Don't cache agent tools during a run
Don't cache agent tools during a run
Don't cache agent tools during a run (#803)
rm-openai commentedon Jun 4, 2025
@Afstkla this is now fixed. I'd recommend using
is_enabledon the tool, which lets you specify a function to dynamically enable/disable behavior.Don't cache agent tools during a run (openai#803)