Skip to content

Commit a2c270f

Browse files
Update multi-agent portfolio collaboration notebook with enhanced introduction 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.
1 parent e4f1d95 commit a2c270f

File tree

5 files changed

+55
-103
lines changed

5 files changed

+55
-103
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from agents import Agent, WebSearchTool, ModelSettings
2-
from utils import load_prompt, DISCLAIMER
2+
from utils import load_prompt, DISCLAIMER, repo_path
33
from pathlib import Path
44

55
default_model = "gpt-4.1"
@@ -11,7 +11,7 @@ def build_fundamental_agent():
1111
fundamental_prompt = load_prompt("fundamental_base.md", RECENT_DAYS=RECENT_DAYS)
1212
# Set up the Yahoo Finance MCP server
1313
from agents.mcp import MCPServerStdio
14-
server_path = str(Path(__file__).resolve().parent.parent/"mcp/yahoo_finance_server.py")
14+
server_path = str(repo_path("mcp/yahoo_finance_server.py"))
1515
yahoo_mcp_server = MCPServerStdio(
1616
params={"command": "python", "args": [server_path]},
1717
client_session_timeout_seconds=300,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ async def run_all_specialists_tool(fundamental_input: SpecialistRequestInput, ma
6060
load_prompt("pm_base.md") + DISCLAIMER
6161
),
6262
model="gpt-4.1",
63+
#Reasoning model
6364
#model="o4-mini",
6465
tools=[fundamental_tool, macro_tool, quant_tool, memo_edit_tool, run_all_specialists_tool],
66+
# Settings for a reasoning model
6567
#model_settings=ModelSettings(parallel_tool_calls=True, reasoning={"summary": "auto", "effort": "high"}, tool_choice="auto")
6668
model_settings=ModelSettings(parallel_tool_calls=True, tool_choice="auto", temperature=0)
6769
)

examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/quant.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from agents import Agent, ModelSettings
22
from tools import run_code_interpreter, get_fred_series, read_file, list_output_files
3-
from utils import load_prompt, DISCLAIMER
3+
from utils import load_prompt, DISCLAIMER, repo_path
44
from pathlib import Path
55

66
default_model = "gpt-4.1"
@@ -10,7 +10,7 @@ def build_quant_agent():
1010
quant_prompt = load_prompt("quant_base.md")
1111
# Set up the Yahoo Finance MCP server
1212
from agents.mcp import MCPServerStdio
13-
server_path = str(Path(__file__).resolve().parent.parent /"mcp/yahoo_finance_server.py")
13+
server_path = str(repo_path("mcp/yahoo_finance_server.py"))
1414
yahoo_mcp_server = MCPServerStdio(
1515
params={"command": "python", "args": [server_path]},
1616
client_session_timeout_seconds=300,

examples/agents_sdk/multi-agent-portfolio-collaboration/multi_agent_portfolio_collaboration.ipynb

Lines changed: 48 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@
99
"\n",
1010
"## Introduction\n",
1111
"\n",
12-
"*This guide is intended for readers already familiar with OpenAI models and building LLM agents.*\n",
12+
"*This guide is for readers already familiar with OpenAI models and LLM agents, and want to see how to orchestrate a team of agents for a real-world, complex task.*\n",
1313
"\n",
14-
"Building a complex, multistep AI system often benefits from **multiple agents working in tandem**. This guide demonstrates how to orchestrate a team of agents using the OpenAI Agents SDK, through the example of a **portfolio research workflow**. Here, specialized agents (Macro, Fundamental, Quantitative) collaborate under a Portfolio Manager agent to solve a challenging investment analysis problem. We focus on high-level architecture, tool usage, and best practices for multi-agent collaboration, with all code and assets drawn from this repo.\n",
14+
"**What You'll Learn**\n",
1515
"\n",
16-
"By the end of this guide, you'll understand how to design a multi-agent system, choose collaboration patterns, configure various tool types for each agent, and run the system with tracing for observability.\n",
16+
"In this notebook, you'll learn how to use the OpenAI Agents SDK to design and implement a complex multi-agent collaboration system. Specifically, you'll see how to:\n",
17+
"- Build a workflow where multiple specialist agents (Macro, Fundamental, Quantitative) collaborate under a Portfolio Manager agent to solve a challenging investment research problem.\n",
18+
"- Use the \"agents as a tool\" approach, where a central agent orchestrates and calls other agents as tools for specific subtasks.\n",
19+
"- Leverage all major tool types supported by the SDK (custom Python functions, managed tools like Code Interpreter and WebSearch, and external MCP servers) in a single, integrated workflow.\n",
20+
"- Apply best practices for modularity, parallelism, and observability in agentic patterns.\n",
21+
"\n",
22+
"**Why this matters**\n",
23+
"\n",
24+
"The \"agents as a tool\" pattern is a powerful way to build transparent, auditable, and scalable multi-agent collaboration . This example demonstrates how to combine deep specialization, parallel execution, and robust orchestration using the OpenAI Agents SDK.\n",
25+
"\n",
26+
"By the end of this guide, you'll have a clear blueprint for building your own multi-agent workflows for research, analysis, or any complex task that benefits from expert collaboration.\n"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "ed547489",
32+
"metadata": {},
33+
"source": [
1734
"\n",
1835
"---\n",
1936
"\n",
@@ -29,13 +46,27 @@
2946
"8. [Breaking Down the Head Portfolio Manager Agent](#breaking-down-the-head-portfolio-manager-agent)\n",
3047
"9. [Example Output](#example-output)\n",
3148
"10. [Best Practices When Building Agents](#best-practices-when-building-agents)\n",
32-
"11. [Further Reading & Best Practices](#further-reading--best-practices)\n",
49+
"11. [Further Reading & Best Practices](#further-reading--best-practices)\n"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "26670dad",
55+
"metadata": {},
56+
"source": [
3357
"\n",
3458
"---\n",
3559
"\n",
3660
"## What is Multi-Agent Collaboration?\n",
3761
"\n",
38-
"**Multi-agent collaboration** means multiple autonomous agents (LLM \"nodes\") coordinate to achieve an overarching goal that would be difficult for a single agent to handle. Instead of one monolithic prompt, each agent handles a specific subtask or expertise area, and an orchestration layer connects these agent \"nodes\" into a coherent workflow. This approach is useful for complex systems – for example, a financial analysis might be broken into macro-economic analysis, fundamental company analysis, and quantitative signal analysis, each handled by a different agent specialist. The agents share information and their results are combined to produce a final outcome.\n",
62+
"**Multi-agent collaboration** means multiple autonomous agents (LLM \"nodes\") coordinate to achieve an overarching goal that would be difficult for a single agent to handle. Instead of one monolithic prompt, each agent handles a specific subtask or expertise area, and an orchestration layer connects these agent \"nodes\" into a coherent workflow. This approach is useful for complex systems – for example, a financial analysis might be broken into macro-economic analysis, fundamental company analysis, and quantitative signal analysis, each handled by a different agent specialist. The agents share information and their results are combined to produce a final outcome.\n"
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"id": "4d5f3a58",
68+
"metadata": {},
69+
"source": [
3970
"\n",
4071
"### Collaboration Patterns: Handoff vs. Agent-as-Tool\n",
4172
"\n",
@@ -53,7 +84,14 @@
5384
"\n",
5485
"Our system follows a **hub-and-spoke design**. The **Portfolio Manager agent** is the hub (central coordinator), and the **specialist agents** are the spokes. The user's query (e.g. \"How would a planned interest rate reduction affect my GOOGL holdings?\") goes first to the Portfolio Manager. The Portfolio Manager agent is prompted to break down the problem and delegate to the appropriate specialist agents. It treats each specialist as a callable tool, invoking them for their portion of the analysis. All three report back to the Portfolio Manager, which then synthesizes a final answer for the user.\n",
5586
"\n",
56-
"![Multi-Agent Investment Report Workflow](static/agent_architecture.png)\n",
87+
"![Multi-Agent Investment Report Workflow](static/agent_architecture.png)\n"
88+
]
89+
},
90+
{
91+
"cell_type": "markdown",
92+
"id": "a7a2ef1e",
93+
"metadata": {},
94+
"source": [
5795
"\n",
5896
"---\n",
5997
"\n",
@@ -345,106 +383,19 @@
345383
"id": "c74d9ac0",
346384
"metadata": {},
347385
"source": [
386+
"---\n",
387+
"\n",
348388
"## Example Output\n",
349389
"\n",
350390
"Here's an example of an investment report generated through the workflow. See [`static/example_output/investment_report.md`](static/example_output/investment_report.md) for the full output, and the `static/example_output/` folder for referenced images and CSVs."
351391
]
352392
},
353393
{
354394
"cell_type": "code",
355-
"execution_count": 1,
395+
"execution_count": null,
356396
"id": "9fe6e452",
357397
"metadata": {},
358-
"outputs": [
359-
{
360-
"data": {
361-
"text/markdown": [
362-
"# Investment Memo: Alphabet Inc. (GOOGL) – Impact of Planned Interest Rate Reduction (May 2025)\n",
363-
"\n",
364-
"## Executive Summary\n",
365-
"\n",
366-
"Alphabet Inc. (GOOGL) currently trades at \\$171.42 per share, with a market capitalization of \\$1.88 trillion and a P/E ratio of 16.91. The investment thesis is moderately constructive: while a planned interest rate reduction by the Federal Reserve is a mild tailwind, it is not the primary driver of GOOGL's price action. The most original, differentiated insight—fully aligned with our firm's vision—is that GOOGL's direct sensitivity to interest rates is modest (max weekly correlation with 10Y yield is ~0.29), and the real risk/reward hinges on the sustainability of AI-driven growth, sector rotation, and regulatory headwinds. This thesis is supported by robust technicals, strong fundamentals, and overwhelmingly positive analyst sentiment, but is tempered by the risk that AI optimism fades or macro/regulatory shocks emerge. The consensus view is justified by evidence: GOOGL's business remains resilient, but the variant view—where rate cuts fail to stimulate tech or sector rotation caps returns—should not be ignored. Key risks include regulatory action, macroeconomic uncertainty, and the potential for a shift in the AI narrative. In the best case, GOOGL could reach \\$200–\\$210 by year-end 2025; in the worst case, a retest of \\$160–\\$170 is plausible. This memo embodies the firm's vision by focusing on scenario planning, original quantitative analysis, and a critical assessment of consensus and variant views.\n",
367-
"\n",
368-
"## Fundamentals Perspective\n",
369-
"\n",
370-
"Alphabet's core business is driven by its dominance in digital advertising (Google Search, YouTube) and its growing cloud and AI segments. As of the latest quarter (Q1 2025), revenue was \\$90.2 billion, net income \\$34.5 billion, and EPS \\$2.81, with net margin at 38.3%. Margins have improved over the past year, and the company's scale and leadership in AI and cloud provide a durable moat. However, recent analyst price targets have been revised downward (Bernstein: \\$165, UBS: \\$209, Wolfe: \\$210), reflecting caution around regulatory and macroeconomic risks. The consensus view is justified: while Alphabet's financial strength and innovation are clear, regulatory scrutiny and macro headwinds (e.g., reduced ad budgets in downturns) are real risks. The most original insight is the company's ability to adapt and innovate, potentially mitigating some risks. The analysis is evidence-based, with recent quarterly data showing stable or improving margins:\n",
371-
"\n",
372-
"| Date | Revenue | Net Income | Gross Profit | Total Expenses | EPS | Net Margin (%) | Gross Margin (%) | Operating Margin (%) |\n",
373-
"|:-----------|-----------:|-------------:|---------------:|-----------------:|------:|-----------------:|-------------------:|-----------------------:|\n",
374-
"| 2025-03-31 | 9.0234e+10 | 3.454e+10 | 5.3873e+10 | 5.9628e+10 | 2.81 | 38.28 | 59.70 | 33.92 |\n",
375-
"| 2024-12-31 | 9.6469e+10 | 2.6536e+10 | 5.5856e+10 | 6.5497e+10 | 2.15 | 27.51 | 57.90 | 32.11 |\n",
376-
"| 2024-09-30 | 8.8268e+10 | 2.6301e+10 | 5.1794e+10 | 5.9747e+10 | 2.12 | 29.80 | 58.68 | 32.31 |\n",
377-
"| 2024-06-30 | 8.4742e+10 | 2.3619e+10 | 4.9235e+10 | 5.7317e+10 | 1.89 | 27.87 | 58.10 | 32.36 |\n",
378-
"| 2024-03-31 | 8.0539e+10 | 2.3662e+10 | 4.6827e+10 | 5.5067e+10 | 1.89 | 29.38 | 58.14 | 31.63 |\n",
379-
"\n",
380-
"Recent analyst sentiment is overwhelmingly positive, with 56 Buy, 12 Hold, and 0 Sell recommendations currently:\n",
381-
"\n",
382-
"| period | Buy | Hold | Sell |\n",
383-
"|:-------------|------:|-------:|-------:|\n",
384-
"| Current | 56 | 12 | 0 |\n",
385-
"| 1 Month Ago | 55 | 12 | 0 |\n",
386-
"| 2 Months Ago | 55 | 12 | 0 |\n",
387-
"| 3 Months Ago | 53 | 12 | 0 |\n",
388-
"\n",
389-
"The fundamental view is aligned with the firm vision by focusing on evidence, scenario planning, and not simply following consensus. The main divergence from the firm vision would be if the analysis failed to consider the impact of regulatory or macro shocks, but this is addressed here.\n",
390-
"\n",
391-
"## Macro Perspective\n",
392-
"\n",
393-
"The macroeconomic environment is mixed. U.S. real GDP is expanding (\\$23.5 trillion, Q1 2025), unemployment is low (4.2%), and inflation remains elevated (CPI: 320.3). The Federal Reserve has kept rates at 4.25–4.50%, with a patient stance and a focus on evolving risks. The U.S. dollar is strong (DXY: 123.4), and recent tariffs have introduced uncertainty. Investors are rotating from U.S. tech to Asian equities, reflecting concerns about high valuations and better growth prospects abroad. The consensus macro view is that rate cuts will support tech valuations, but the variant view—supported by our firm's vision—is that sector rotation and trade policy could offset these benefits. Tail-risk scenarios include a base case where rate cuts support GOOGL (\\$180–\\$190 target), and a downside where trade tensions or sector rotation cap returns. The analysis is evidence-based, using FRED data and recent policy statements, and explicitly considers both best- and worst-case scenarios. The macro view is fully aligned with the firm vision by challenging consensus and planning for multiple outcomes.\n",
394-
"\n",
395-
"## Quantitative Perspective\n",
396-
"\n",
397-
"Quantitative analysis confirms that GOOGL's direct sensitivity to interest rates is modest. The mean weekly correlation with the 10Y Treasury yield is 0.29, and with the Fed Funds rate is 0.05, indicating that rate changes are not the primary driver of GOOGL's returns. Technicals are robust: GOOGL is above key moving averages, momentum is positive, and volatility is moderate. Scenario analysis shows that a rate cut is a mild tailwind, but if the move is already priced in or if technicals break down, a 5–10% pullback is possible. Analyst sentiment is strongly positive, and fundamentals (revenue, margins) are improving. Quantitative summary statistics:\n",
398-
"\n",
399-
"| Metric | Value |\n",
400-
"|:----------------------------------------|----------:|\n",
401-
"| Mean daily corr (FEDFUNDS, GOOGL) | 0.05 |\n",
402-
"| Mean daily reg slope (FEDFUNDS, GOOGL) | 0.02 |\n",
403-
"| Mean daily corr (DGS10, GOOGL) | 0.13 |\n",
404-
"| Mean daily reg slope (DGS10, GOOGL) | 0.05 |\n",
405-
"| Mean weekly corr (FEDFUNDS, GOOGL) | 0.05 |\n",
406-
"| Mean weekly reg slope (FEDFUNDS, GOOGL) | 0.03 |\n",
407-
"| Mean weekly corr (DGS10, GOOGL) | 0.29 |\n",
408-
"| Mean weekly reg slope (DGS10, GOOGL) | 0.09 |\n",
409-
"\n",
410-
"Key charts and images:\n",
411-
"\n",
412-
"![GOOGL Daily Returns](static/example_output/googl_daily_returns.png)\n",
413-
"![GOOGL Moving Averages](static/example_output/googl_moving_averages.png)\n",
414-
"![GOOGL RSI](static/example_output/googl_rsi.png)\n",
415-
"![GOOGL Rolling Volatility](static/example_output/googl_rolling_volatility.png)\n",
416-
"![Cumulative Return Comparison](static/example_output/cumulative_return_comparison.png)\n",
417-
"![Rolling Volatility Comparison](static/example_output/rolling_volatility_comparison.png)\n",
418-
"![Rolling Corr/Reg Daily Fed Funds](static/example_output/rolling_corr_reg_daily_fedfunds.png)\n",
419-
"![Rolling Corr/Reg Daily 10Y](static/example_output/rolling_corr_reg_daily_dgs10.png)\n",
420-
"![Rolling Corr/Reg Weekly Fed Funds](static/example_output/rolling_corr_reg_weekly_fedfunds.png)\n",
421-
"![Rolling Corr/Reg Weekly 10Y](static/example_output/rolling_corr_reg_weekly_dgs10.png)\n",
422-
"![GOOGL Quarterly Trends](static/example_output/GOOGL_quarterly_trends.png)\n",
423-
"![GOOGL Quarterly Margins](static/example_output/GOOGL_quarterly_margins.png)\n",
424-
"![GOOGL Analyst Recommendations Trend](static/example_output/GOOGL_analyst_recommendations_trend.png)\n",
425-
"\n",
426-
"The quantitative view is original in its focus on scenario analysis and the modest rate sensitivity, and is aligned with the firm vision by not simply following consensus. Limitations include the short post-pandemic data window and the fact that GOOGL's price is driven by multiple factors (AI, ad market, regulation) beyond rates.\n",
427-
"\n",
428-
"## Portfolio Manager Perspective\n",
429-
"\n",
430-
"The PM synthesis is that all three specialist sections converge on a moderately constructive outlook, with a realistic year-end 2025 price target of \\$190–\\$210. The most original insight is that GOOGL's direct rate sensitivity is modest, and the real risk is whether AI-driven growth can continue or if sector rotation and regulatory headwinds will cap returns. The quant section is strong in highlighting robust technicals and sentiment, but also the risk of a \\$160–\\$170 retest in downside scenarios. The fundamental and macro sections emphasize the importance of monitoring regulatory and trade policy. If underweight large-cap tech, now is a reasonable entry point, but position sizing should reflect the risk of sector rotation or macro disappointment. The variant view—rate cuts failing to stimulate tech or a shift in AI narrative—should not be ignored. Position sizing and risk management are key, fully in line with the firm's vision of scenario planning and differentiated insight.\n",
431-
"\n",
432-
"## Recommendation & Answer to the Question\n",
433-
"\n",
434-
"The recommendation is to maintain or modestly increase exposure to GOOGL, especially if underweight large-cap tech, with a year-end 2025 price target of \\$200–\\$210 in the base case. This embodies the firm vision by focusing on original, evidence-based scenario analysis, not simply following consensus. The recommendation is justified by robust fundamentals, positive technicals, and strong analyst sentiment, but is tempered by the risk of sector rotation, regulatory action, or a shift in the AI narrative. If these risks materialize, a retest of \\$160–\\$170 is possible. Sizing and risk management should reflect these scenarios. This approach is differentiated, evidence-driven, and fully aligned with the firm's vision.\n",
435-
"\n",
436-
"**END_OF_MEMO**\n",
437-
"\n",
438-
"*DISCLAIMER: I am an AI language model, not a registered investment adviser. Information provided is educational and general in nature. Consult a qualified financial professional before making any investment decisions.*"
439-
],
440-
"text/plain": [
441-
"<IPython.core.display.Markdown object>"
442-
]
443-
},
444-
"metadata": {},
445-
"output_type": "display_data"
446-
}
447-
],
398+
"outputs": [],
448399
"source": [
449400
"# Render the actual investment report generated by the workflow\n",
450401
"from pathlib import Path\n",

registry.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
# should build pages for, and indicates metadata such as tags, creation date and
55
# authors for each page.
66

7-
<<<<<<< HEAD
87
- title: Multi-Agent Portfolio Collaboration with OpenAI Agents SDK
98
path: examples/agents_sdk/multi-agent-portfolio-collaboration/multi_agent_portfolio_collaboration.ipynb
10-
date: 2025-05-27
9+
date: 2025-05-28
1110
authors:
1211
- rajpathak-openai
1312
- chelseahu-openai

0 commit comments

Comments
 (0)