Skip to content

Multi-Agent Collaboration Notebook #1859

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

Merged
merged 16 commits into from
May 28, 2025

Conversation

rajpathak-openai
Copy link
Contributor

Summary

This project implements a multi-agent portfolio collaboration system using OpenAI’s Agents SDK. It provides a reproducible workflow for generating investment reports, including quantitative, fundamental, and macroeconomic analyses, and demonstrates best practices for collaborative financial research. The repository includes example outputs, supporting data, and Jupyter notebooks to guide users through the process.

Motivation

The goal of this project is to showcase how AI agents can be orchestrated to perform complex, collaborative financial analysis tasks. By providing clear examples, organized outputs, and reproducible workflows, this project aims to help users and organizations accelerate their own research and reporting processes. It also serves as a reference for integrating AI-driven analysis into investment decision-making, improving transparency, efficiency, and collaboration in financial research all using the Agents SDK


For new content

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

  • [X ] I have added a new entry in registry.yaml (and, optionally, in authors.yaml) so that my content renders on the cookbook website.
  • [X ] I have conducted a self-review of my content based on the contribution guidelines:
    • [ X] Relevance: This content is related to building with OpenAI technologies and is useful to others.
    • [X ] 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.
    • [ X] Spelling and Grammar: I have checked for spelling or grammatical mistakes.
    • [ X] Clarity: I have done a final read-through and verified that my submission is well-organized and easy to understand.
    • [ X] Correctness: The information I include is correct and all of my code executes successfully.
    • [ X] 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.

…revised analysis and insights on GOOGL's performance and market conditions. Adjust code interpreter instructions in tools.py for clarity and efficiency. Delete outdated output files related to previous analyses.
…undant trace information and updating image paths for output consistency. Revise investment report to include formatted monetary values for clarity and enhance overall presentation of GOOGL's market analysis.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@rajpathak-openai rajpathak-openai requested a review from Copilot May 27, 2025 19:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a complete multi-agent portfolio collaboration example, including sample outputs, prompt templates, and agent definitions for orchestrating quantitative, fundamental, and macro analyses as well as memo editing.

  • Introduced a static example investment report to demonstrate end‐to‐end output.
  • Added prompt templates (tool_retry_prompt.md, quant_base.md, macro_base.md, fundamental_base.md, pm_base.md, editor_base.md, code_interpreter.md) to guide each specialist agent.
  • Implemented agent builder code (investment_agents/*.py, config.py) and updated author metadata.

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
examples/agents_sdk/.../static/example_output/investment_report.md Added sample investment memo output
examples/agents_sdk/.../prompts/tool_retry_prompt.md New retry‐logic instructions for tool calls
examples/agents_sdk/.../prompts/quant_base.md Quantitative analyst prompt template
examples/agents_sdk/.../prompts/macro_base.md Macro strategist prompt template
examples/agents_sdk/.../prompts/fundamental_base.md Fundamental analyst prompt template
examples/agents_sdk/.../prompts/pm_base.md Portfolio manager system prompt
examples/agents_sdk/.../prompts/editor_base.md Memo editor agent prompt
examples/agents_sdk/.../prompts/code_interpreter.md Code interpreter best‐practices prompt
examples/agents_sdk/.../investment_agents/quant.py Quant agent builder
examples/agents_sdk/.../investment_agents/fundamental.py Fundamental agent builder
examples/agents_sdk/.../investment_agents/macro.py Macro agent builder
examples/agents_sdk/.../investment_agents/pm.py Head PM agent builder
examples/agents_sdk/.../investment_agents/editor.py Memo editor builder
examples/agents_sdk/.../investment_agents/config.py Bundles all agents and contains an unused helper function
authors.yaml Contains unresolved merge conflict markers
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported

@rajpathak-openai rajpathak-openai requested a review from Copilot May 27, 2025 19:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a complete multi-agent collaboration notebook with several new prompt files and agent implementations for quantitative, fundamental, macro, portfolio manager, and memo editor agents. The changes establish instructions for tool retry logic and integrate updated author metadata.

  • New investment memo output and supporting prompt files have been added.
  • All agent implementations (quant, macro, fundamental, PM, and editor) have been newly introduced.
  • The authors metadata has been updated, but unresolved merge conflict markers are present.

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/investment_report.md Adds a sample investment report markdown output.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/tool_retry_prompt.md Introduces tool call retry instructions.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/quant_base.md Provides detailed prompt for quantitative analysis.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/pm_base.md Adds prompt specifications for the portfolio manager agent.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/macro_base.md Delivers prompt instructions for macro analysis.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/fundamental_base.md Sets up fundamental analysis prompt guidelines.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/editor_base.md Defines the memo editor agent prompt.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/code_interpreter.md Outlines best practices for the code interpreter.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/quant.py Implements the quantitative analysis agent.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.py Implements the portfolio manager agent.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/macro.py Implements the macro analysis agent.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/fundamental.py Implements the fundamental analysis agent.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/editor.py Implements the memo editor agent and its tool.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/config.py Configures and bundles all investment agents together.
authors.yaml Updates author metadata but contains unresolved merge conflict markers.
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported

Co-authored-by: Copilot <[email protected]>
@rajpathak-openai rajpathak-openai requested a review from Copilot May 27, 2025 20:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a multi-agent portfolio collaboration demo with OpenAI’s Agents SDK. It adds example outputs, comprehensive system prompts, agent builder code, and updates author metadata.

  • Introduces an example investment report (investment_report.md) showcasing the multi-agent workflow.
  • Adds detailed prompts for retry logic, quantitative, fundamental, macro, PM orchestration, memo editing, and code interpreter.
  • Implements agent constructors and configuration scripts under investment_agents/ and updates authors.yaml.

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/agents_sdk/.../static/example_output/investment_report.md Added sample investment memo output
examples/agents_sdk/.../prompts/tool_retry_prompt.md Added instructions for retrying failed tool calls
examples/agents_sdk/.../prompts/quant_base.md Added Quantitative Analyst prompt
examples/agents_sdk/.../prompts/fundamental_base.md Added Fundamental Analyst prompt
examples/agents_sdk/.../prompts/macro_base.md Added Macro Strategist prompt
examples/agents_sdk/.../prompts/pm_base.md Added Portfolio Manager system prompt
examples/agents_sdk/.../prompts/editor_base.md Added Memo Editor prompt
examples/agents_sdk/.../prompts/code_interpreter.md Added Code Interpreter best‐practices prompt
examples/agents_sdk/.../investment_agents/quant.py Added Quantitative Analysis Agent builder
examples/agents_sdk/.../investment_agents/fundamental.py Added Fundamental Analysis Agent builder
examples/agents_sdk/.../investment_agents/macro.py Added Macro Analysis Agent builder
examples/agents_sdk/.../investment_agents/pm.py Added Head PM Agent builder with parallel orchestration
examples/agents_sdk/.../investment_agents/editor.py Added Memo Editor Agent builder
examples/agents_sdk/.../investment_agents/config.py Configures and bundles all agents
examples/agents_sdk/.../investment_agents/init.py Marks agents directory as a package
authors.yaml Added two new author entries
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported

quant=quant,
)

# The function `run_all_specialists_parallel` has been removed as its functionality is duplicated in `pm.py`.
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is outdated: run_all_specialists_parallel is still defined in pm.py. Please update or remove the remark to avoid confusion.

Suggested change
# The function `run_all_specialists_parallel` has been removed as its functionality is duplicated in `pm.py`.
# The function `run_all_specialists_parallel` is still defined in `pm.py`. Ensure its usage aligns with the intended functionality to avoid duplication.

Copilot uses AI. Check for mistakes.

…cution counts and outputs from code cells for cleaner presentation. Update investment analysis questions to focus on current market dynamics. Enhance Yahoo Finance server functionality by adding JSON file saving capabilities for stock info, news, and option expiration dates, including schema and preview in responses.
@rajpathak-openai rajpathak-openai requested a review from Copilot May 27, 2025 22:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a complete multi-agent portfolio collaboration example using the OpenAI Agents SDK, including example outputs, prompt templates, and agent implementations.

  • Adds a sample investment report (Markdown) showcasing the end-to-end output
  • Provides prompt definitions for quant, fundamental, macro, PM, and editor agents
  • Implements Python code to build and wire up all specialist and orchestration agents
  • Updates authors.yaml to include new contributors

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/agents_sdk/.../static/example_output/investment_report.md Sample investment memo output
examples/agents_sdk/.../prompts/*.md New prompt templates for each agent role
examples/agents_sdk/.../investment_agents/quant.py, fundamental.py, macro.py, pm.py, editor.py Agent builder code for each specialist and PM
examples/agents_sdk/.../investment_agents/config.py Bundles and orchestrates all investment agents
authors.yaml Added new author entries
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported
Comments suppressed due to low confidence (3)

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.py:43

  • [nitpick] The parameter name input shadows the built-in input function. Rename it (e.g., request_input) to avoid confusion.
async def agent_tool(input: SpecialistRequestInput):

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.py:15

  • [nitpick] The parameter input shadows the built-in. Consider renaming to request_input or similar for clarity.
async def specialist_analysis_func(agent, input: SpecialistRequestInput):

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/editor.py:32

  • [nitpick] The parameter input shadows the built-in. Rename it (for example to memo_input) to avoid built-in conflicts.
async def memo_edit_tool(ctx: RunContextWrapper, input: MemoEditorInput) -> str:

…ent_agents config and fix typo in quant_base prompt documentation.
@rajpathak-openai rajpathak-openai requested a review from Copilot May 27, 2025 22:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

A multi-agent portfolio collaboration system is added, showcasing how OpenAI Agents SDK can orchestrate quantitative, fundamental, and macro analyses into a unified investment memo.

  • Introduces a sample investment report for Alphabet Inc. demonstrating the end-to-end output
  • Defines new prompts guiding retry logic, quant, macro, fundamental, PM orchestration, and memo editing workflows
  • Implements agent builder modules for quant, macro, fundamental, PM, editor, and a config entrypoint bundling them

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/investment_report.md Adds sample Markdown investment memo output
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/tool_retry_prompt.md Retry logic instructions for failed tool calls
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/quant_base.md Quantitative analyst system prompt and tool guidelines
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/pm_base.md Portfolio manager orchestration system prompt
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/macro_base.md Macro strategist system prompt
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/fundamental_base.md Fundamental analyst system prompt
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/editor_base.md Memo editor synthesis prompt
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/code_interpreter.md Code interpreter best-practices prompt
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/quant.py Builds the Quantitative Analysis Agent
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.py Builds the Head PM Agent and orchestration tools
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/macro.py Builds the Macro Analysis Agent
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/fundamental.py Builds the Fundamental Analysis Agent
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/editor.py Builds the Memo Editor Agent and tool
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/config.py Entrypoint bundling all agents into a single structure
authors.yaml Adds new author entries
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported
Comments suppressed due to low confidence (2)

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/fundamental.py:25

  • The Fundamental Analysis Agent is configured with only the WebSearch tool but lacks the Yahoo Finance data tools required to fetch financial metrics. Include the Yahoo Finance MCP server tool in the tools list (e.g., add the MCP server client or relevant Yahoo Finance tool) so the agent can retrieve balance sheets, income statements, and other quantitative data.
tools=[WebSearchTool(search_context_size=default_search_context)],

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/config.py:10

  • The InvestmentAgentsBundle currently exposes only head_pm, fundamental, macro, and quant agents, but omits the editor agent and memo_edit_tool even though they are initialized. Consider adding fields for the editor components to the bundle so downstream code can access and test the memo editor directly.
class InvestmentAgentsBundle:

…and `read_csv_preview` into a new `read_file` function that supports multiple file types. Update relevant prompts and agent configurations to utilize the new function. Enhance notebook output to include execution tracing information for better debugging and analysis context.
@rajpathak-openai rajpathak-openai requested a review from Copilot May 28, 2025 01:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive multi-agent collaboration framework for portfolio analysis using OpenAI’s Agents SDK. Key changes include:

  • The addition of example outputs (e.g. an investment report markdown file) illustrating a complete analysis workflow.
  • New prompt files for each specialist (quantitative, fundamental, macro, PM, and memo editor) to govern agent behavior and ensure parallelized tool calls.
  • The implementation of agent code (in Python) that integrates these prompts, configures tool retry logic, and sets up the agent orchestration.

Reviewed Changes

Copilot reviewed 37 out of 41 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/investment_report.md Adds a sample investment memo demonstrating report structure.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/tool_retry_prompt.md Introduces retry instructions for failed tool calls.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/quant_base.md Defines the quantitative analyst prompt and analysis workflow.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/pm_base.md Provides guidelines for the Portfolio Manager’s prompt.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/macro_base.md Establishes the Macro Strategist prompt and required tool call pattern.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/fundamental_base.md Outlines the Lead Fundamental Analyst prompt and parallel tool usage.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/editor_base.md Specifies the Memo Editor prompt and final memo assembly process.
examples/agents_sdk/multi-agent-portfolio-collaboration/prompts/code_interpreter.md Documents best practices for code interpreter analyses.
examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/*.py Implements agents for quant, fundamental, macro, PM, and editor roles.
authors.yaml Updates author information for the new contributions.
Files not reviewed (4)
  • examples/agents_sdk/multi-agent-portfolio-collaboration/.gitignore: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/requirements.txt: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_analyst_recommendations_summary.csv: Language not supported
  • examples/agents_sdk/multi-agent-portfolio-collaboration/static/example_output/GOOGL_quarterly_summary.csv: Language not supported

…roduction and learning objectives. Adjust date in registry.yaml. Refactor fundamental and quant agent scripts to utilize a centralized path function for server configuration. Improve documentation clarity and structure throughout the notebook.
"id": "1e5b29d1",
"metadata": {},
"source": [
"# Multi-Agent Portfolio Collaboration with OpenAI Agents SDK\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought -wondering if we could make the intent of this cookbook a bit clearer by renaming it to something like "Multi-Agent Orchestration with OpenAI Agents SDK: Financial Portfolio Analysis Example."

Totally fine to keep the current title if you feel it better reflects your intent!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make this change!

@rajpathak-openai rajpathak-openai merged commit c142c66 into main May 28, 2025
1 check passed
@rajpathak-openai rajpathak-openai deleted the agents-sdk-pm-advisor-cookbook branch May 28, 2025 20:57
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.

3 participants