Skip to content

Commit 67c9ed9

Browse files
authored
Update xai_python_multi_agent.py
1 parent ac1cce0 commit 67c9ed9

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
11

2+
from phi.agent import Agent
3+
from phi.model.openai import OpenAIChat
4+
from phi.tools.duckduckgo import DuckDuckGo
5+
from phi.tools.yfinance import YFinanceTools
6+
from phi.model.xai import xAI
7+
from phi.playground import Playground, serve_playground_app
8+
from fastapi import FastAPI
9+
10+
11+
# Create web search agent with improved instructions
12+
web_search_agent = Agent(
13+
name="Web Search Agent",
14+
role="Search the web for accurate and up-to-date information",
15+
model=xAI(id="grok-beta"),
16+
tools=[DuckDuckGo()],
17+
instructions=[
18+
"Always include sources and citations",
19+
"Verify information from multiple sources when possible",
20+
"Present information in a clear, structured format",
21+
],
22+
show_tool_calls=True,
23+
markdown=True,
24+
monitoring=True, # Enable monitoring for better debugging
25+
)
26+
27+
# Create finance agent with enhanced capabilities
28+
finance_agent = Agent(
29+
name="Finance Agent",
30+
role="Analyze and present financial data",
31+
model=xAI(id="grok-beta"),
32+
tools=[
33+
YFinanceTools(
34+
stock_price=True,
35+
analyst_recommendations=True,
36+
company_info=True,
37+
company_news=True, # Added news capability
38+
)
39+
],
40+
instructions=[
41+
"Use tables to display numerical data",
42+
"Include key financial metrics and trends",
43+
"Provide context for financial recommendations",
44+
],
45+
show_tool_calls=True,
46+
markdown=True,
47+
monitoring=True,
48+
)
49+
50+
# Create multi-agent team with improved coordination
51+
multi_ai_agent = Agent(
52+
name="Multi AI Team",
53+
team=[web_search_agent, finance_agent],
54+
model=xAI(id="grok-beta"),
55+
instructions=[
56+
"Always include sources and citations",
57+
"Use tables to display structured data",
58+
"Combine financial data with relevant market news",
59+
"Provide comprehensive analysis using both agents' capabilities",
60+
],
61+
show_tool_calls=True,
62+
markdown=True,
63+
monitoring=True,
64+
)
65+
66+
# Create playground with both agents
67+
app = Playground(agents=[multi_ai_agent]).get_app()
68+
69+
if __name__ == "__main__":
70+
serve_playground_app("multi_ai_agent:app", reload=True, port=7777)

0 commit comments

Comments
 (0)