8000 Max turns exceeded · Issue #844 · openai/openai-agents-python · GitHub
[go: up one dir, main page]

Skip to content
Max turns exceeded #844
Open
Open
@fitzjalen

Description

@fitzjalen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0