Skip to content

Add cookbook notebook for parallel agents #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brandonbaker-openai
Copy link
Contributor

@brandonbaker-openai brandonbaker-openai commented May 1, 2025

Summary

Adds a cookbook notebook demonstrating how to run agents in parallel, chain the output from parallel calls to another agent, and visualize the execution timeline of the agents.

Motivation

Provides a very brief example of parallelizing agents, fanning out and in, and visualizing the execution timelines. Inspired by internal questions on basic parallelization patterns for agents

Timeline screenshot for reference:
Screenshot 2025-05-01 at 10 16 16 AM

For new content

When contributing new content, read through our contribution guidelines, and mark the following action items as completed:

  • I have added a new entry in registry.yaml (and, optionally, in authors.yaml) so that my content renders on the cookbook website.
  • I have conducted a self-review of my content based on the contribution guidelines:
    • Relevance: This content is related to building with OpenAI technologies and is useful to others.
    • Uniqueness: I have searched for related examples in the OpenAI Cookbook, and verified that my content offers new insights or unique information compared to existing documentation.
    • Spelling and Grammar: I have checked for spelling or grammatical mistakes.
    • Clarity: I have done a final read-through and verified that my submission is well-organized and easy to understand.
    • Correctness: The information I include is correct and all of my code executes successfully.
    • Completeness: I have explained everything fully, including all necessary references and citations.

We will rate each of these areas on a scale from 1 to 4, and will only accept contributions that score 3 or higher on all areas. Refer to our contribution guidelines for more details.

Adds a cookbook notebook demonstrating how to run agents in parallel,
chain the output from parallel calls to another agent, and visualize
the execution timeline of the agents.
@brandonbaker-openai brandonbaker-openai force-pushed the bbaker/add-parallel-agents-cookbook branch from a74d0c9 to cc148ab Compare May 1, 2025 09:22
@brandonbaker-openai brandonbaker-openai marked this pull request as ready for review May 1, 2025 12:17
@luis-oai
Copy link

luis-oai commented May 5, 2025

Hi, last week Eoin mentioned support for transforming agents into tools.

I wonder if the same can be achieved using agents as tools + parallel tools calls

e.g

meta_agent = Agent(
    name="MetaAgent",
    instructions="You are given multiple summaries labeled with Features, ProsCons, Sentiment, and a Recommendation."
    " Combine them into a concise executive summary of the product review with a 1-5 star rating for each summary area.",
   model_settings=ModelSettings(
       parallel_tool_calls=True
   ),
    tools=[
        features_agent.as_tool(
            tool_name="features",
            tool_description="Extract the key product features from the review.",
        ),
        pros_cons_agent.as_tool(
            tool_name="pros_cons",
            tool_description="List the pros and cons mentioned in the review.",
        ),
        sentiment_agent.as_tool(
            tool_name="sentiment",
            tool_description="Summarize the overall user sentiment from the review.",
        ),
        recommend_agent.as_tool(
            tool_name="recommend",
            tool_description="State whether you would recommend this product and why.",
        ),
    ],
)

@brandonbaker-openai
Copy link
Contributor Author

Hi, last week Eoin mentioned support for transforming agents into tools.

I wonder if the same can be achieved using agents as tools + parallel tools calls

e.g

meta_agent = Agent(
    name="MetaAgent",
    instructions="You are given multiple summaries labeled with Features, ProsCons, Sentiment, and a Recommendation."
    " Combine them into a concise executive summary of the product review with a 1-5 star rating for each summary area.",
   model_settings=ModelSettings(
       parallel_tool_calls=True
   ),
    tools=[
        features_agent.as_tool(
            tool_name="features",
            tool_description="Extract the key product features from the review.",
        ),
        pros_cons_agent.as_tool(
            tool_name="pros_cons",
            tool_description="List the pros and cons mentioned in the review.",
        ),
        sentiment_agent.as_tool(
            tool_name="sentiment",
            tool_description="Summarize the overall user sentiment from the review.",
        ),
        recommend_agent.as_tool(
            tool_name="recommend",
            tool_description="State whether you would recommend this product and why.",
        ),
    ],
)

Definitely think this is a potential approach (and probably the better choice when the agents are this simple). I was thinking this makes sense as a very simple demonstration of the pattern becoming useful when the agents are more complex (or your graph becomes more complex where you may want to partially fan out and combine across different layers), but open to debate on it

@brandonbaker-openai
Copy link
Contributor Author

Hi, last week Eoin mentioned support for transforming agents into tools.
I wonder if the same can be achieved using agents as tools + parallel tools calls
e.g

meta_agent = Agent(
    name="MetaAgent",
    instructions="You are given multiple summaries labeled with Features, ProsCons, Sentiment, and a Recommendation."
    " Combine them into a concise executive summary of the product review with a 1-5 star rating for each summary area.",
   model_settings=ModelSettings(
       parallel_tool_calls=True
   ),
    tools=[
        features_agent.as_tool(
            tool_name="features",
            tool_description="Extract the key product features from the review.",
        ),
        pros_cons_agent.as_tool(
            tool_name="pros_cons",
            tool_description="List the pros and cons mentioned in the review.",
        ),
        sentiment_agent.as_tool(
            tool_name="sentiment",
            tool_description="Summarize the overall user sentiment from the review.",
        ),
        recommend_agent.as_tool(
            tool_name="recommend",
            tool_description="State whether you would recommend this product and why.",
        ),
    ],
)

Definitely think this is a potential approach (and probably the better choice when the agents are this simple). I was thinking this makes sense as a very simple demonstration of the pattern becoming useful when the agents are more complex (or your graph becomes more complex where you may want to partially fan out and combine across different layers), but open to debate on it

Could also add this in as a another approach, and just present both of them

@luis-oai
Copy link

luis-oai commented May 5, 2025

Agree, I think the agent as tool approach its valid when there a 1:1 mapping with tool and agent, but for wider agent scenarios your approach is def more scalable, so maybe we can present both patterns.
In any case it would be good to verify that the wall time of both approaches are similar

@brandonbaker-openai
Copy link
Contributor Author

Added another example showing the agent as tool approach, calling out the tradeoffs between the two in 368fa9d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants