Open
Description
Hello,
I am wondering how we could control the agent not to exceed the maximum number of turns. Or, if we encounter this situation, can we give it a strike instruction to provide a FINAL answer based on previous thoughts/tool results?
I have added a Hook:
def make_dynamic_prompt(self, base_prompt: str, max_turns: int):
"""
Create a dynamic prompt for the agent.
"""
async def _prompt(ctx: RunContextWrapper[None], agent: Agent) -> str:
done = ctx.usage.requests
left = max(max_turns - 1 - done, 0)
suffix = f"Current turn: {self.current_turn}\nMaximum turns: {max_turns} | Turns left: {left}\n\n"
if left == 0:
suffix += "\n\nYou've reached the search limit. Please answer now."
agent.tools.clear()
agent.model_settings = replace(
agent.model_settings,
tool_choice="none"
)
return f"{base_prompt}\n\n{suffix}"
return _prompt
However, the agent mostly ignores it and encounters an error.