Description
Please read this first
- Have you read the docs?Agents SDK docs
- Have you searched for related issues? Others may have faced similar issues.
Describe the bug
A clear and concise description of what the bug is.
The the agent is calling the one tool I provided for multiple times until the max_turn runs out. And each function calls have different search input parameters.
And from the stream events log, it seems the function call is sucessful because retrieved text appears in the raw_item output.
I tried to make the max_turn bigger (all the way to 100), but still the agent keeps calling the tools.
Debug information
- Agents SDK version: (e.g.
v0.0.3
) 0.0.4 - Python version (e.g. Python 3.10) Python 3.13.1
Repro steps
Ideally provide a minimal python script that can be run to reproduce the bug.
I implemented a tool like this that calls an api to retrieve documents from a database.
@function_tool
def similarity_search(chat_uuid: str, text: str) -> str:
"""
docstring ignored...
"""
text_embeddings = TextEmbeddingService.similarity_search_sync(
chat_uuid=chat_uuid,
text=text,
limit=LIMIT,
threshold=THRESHOLD,
)
answer = ""
for i, text_embedding in enumerate(text_embeddings):
answer += f"[{i + 1}] {text_embedding.text}\n"
return answer
And I list it as a tool for my search agent, where BaseAgent is simply a wrapper on Agent class with an extra parameter.
class SearchAgent(BaseAgent):
def __init__(self, chat_uuid: str) -> None:
super().__init__(chat_uuid=chat_uuid)
self.name = "Search Agent"
self.instructions = (
"You are a search assistant."
"Use your tools to help the user with their questions."
"This chat_uuid is unique to you, and you can use it for function calls."
f"chat_uuid='{self.chat_uuid}'"
"Use the following routine to help the user."
"1. Identify the question asked by the user."
"2. Come up with ONE search input to gather information for the question."
"3. Call your search tools ONLY ONCE."
"4. Write a short report on your findings."
"5. Index and cite the sources you use in your answer as urls."
)
self.handoff_description = "A Search agent is a specialized agent that can search the internet or user's knowledge base for information."
self.model_settings = ModelSettings(tool_choice="required", parallel_tool_calls=False)
self.tools = [
self.similarity_search, # BUG: Stuck in a loop until max_turns is reached
]
Expected behavior
A clear and concise description of what you expected to happen.
The agent respond with a short paragraph with the retrieved results.