Open
Description
Question
I don't want to use the built-in WebSearchTool, I want to use a custom search tool.
After the program is run, it does output [debug] web_search_tool input query=xxx, but it also reports an error: agents.exceptions.MaxTurnsExceeded: Max turns (1) exceeded. How should I write my custom search function correctly?
@function_tool
def web_search_tool(query: str):
print(f"[debug] web_search_tool input query={query}")
return f"Search {query} result."
search_agent = Agent(
name="Search agent",
instructions=INSTRUCTIONS,
tools=[web_search_tool],
model_settings=ModelSettings(tool_choice="required"),
)
async def _search(self, item: WebSearchItem) -> str | None:
input = f"Search term: {item.query}\nReason for searching: {item.reason}"
try:
result = await Runner.run(
search_agent,
input,
max_turns=1
)
return str(result.final_output)
except Exception:
logger.exception("_search ex=")
return None