Skip to content

How to specify the next agent? #187

Description

@domicess
generate_sql_agent = Agent(
        name="generate sql Agent",
        instructions='''
            1. You are responsible for generating SQL statements based on user requests..
           '''
        handoffs=[sql_checker_agent],
    )

 sql_checker_agent = Agent(
        name="SQL Checker Agent",
        handoff_description="Check the SQL statement generated based on the user's request.",
        instructions='''You are responsible for checking the SQL statement generated based on the user's request.
        ''',
        tools=[task_query],
    )

I am worried that handoffs may not be triggered. I need to ensure that sql_checker_agent is called after generate_sql_agent.
In the documentation(https://openai.github.io/openai-agents-python/multi_agent/) I found this: "Chaining multiple agents by transforming the output of one into the input of the next. You can decompose a task like writing a blog post into a series of steps - do research, write an outline, write the blog post, critique it, and then improve it."
But how to implement it with code?

Activity

  1. DanieleMorotti commented on Mar 17, 2025

    @DanieleMorotti
    Contributor

    Hi, if I'm not wrong this example from the github repo may be what you're looking for.
    It first plans searches, then it actually performs them and at the end it writes a report.

  2. tameverfit commented on Mar 17, 2025

    @tameverfit

    hi @DanieleMorotti, do you have any advice on ensuring the agent can be handed off correctly when the chat history is too long?

  3. DanieleMorotti commented on Mar 17, 2025

    @DanieleMorotti
    Contributor

    Hi, I believe this issue can be addressed using standard chat techniques.
    It might be useful to summarize the conversation history to reduce token count. Perhaps you could implement an agent that automatically condenses the history once it exceeds a certain threshold.

    These are just my opinions, so take them with a grain of salt :)

  4. domicess commented on Mar 18, 2025

    @domicess
    Author

    Yes, that's exactly what I want. Do you have any plans to add some code examples like this to the documentation? I think this will help people in need more quickly.

    Hi, if I'm not wrong this example from the github repo may be what you're looking for.It first plans searches, then it actually performs them and at the end it writes a report.

  5. DanieleMorotti commented on Mar 18, 2025

    @DanieleMorotti
    Contributor

    @rm-openai may answer to this. But if you're looking for other examples, there are some in the examples directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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