from agentor import ToolSearch, LLM, tool
@tool
def get_weather(city: str):
"""Get the weather of a city"""
return f"The weather in {city} is sunny"
tool_search = ToolSearch()
tool_search.add(get_weather)
llm = LLM(model="gpt-5-mini")
# First pass: let the LLM call tool_search to discover the best tool.
discovery = llm.chat(
"What is the weather in London?",
instructions="You are a helpful AI Agent. You have access to a Tool search API which can search for capabilities such as weather, news, etc.",
tools=[tool_search],
call_tools=True, # Execute the tool if tool call is detected
)
print(discovery)
# Parse the tool_search output and reprompt with only the matched tool.
match = None
if discovery.outputs:
tool_output = discovery.outputs[-1].tool_output
if isinstance(tool_output, dict) and tool_output.get("type") == "tool_search_output":
match = tool_output.get("tool")
if match is None:
print("[bold red]No tool found by tool_search[/bold red]")
else:
second_instructions = (
"You already ran tool_search. Use only the provided tools; do not call "
"tool_search again."
)
result = llm.chat(
query,
instructions=second_instructions,
tools=[match],
call_tools=True,
)
print("Final result", result)