-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoai-agent_mcp.py
47 lines (37 loc) · 1.05 KB
/
oai-agent_mcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import asyncio
import logfire
from dotenv import load_dotenv
from agents import Agent, Runner
from agents.mcp import MCPServerStdio
load_dotenv()
# Configure Logfire
logfire.configure(send_to_logfire="if-token-present")
logfire.instrument_mcp()
logfire.instrument_openai_agents()
async def main(query: str = "Greet Andrew and give him the current time") -> None:
"""
Main function to run the agent
Args:
query (str): The query to run the agent with
"""
# Create and use the MCP server in an async context
async with MCPServerStdio(
params={
"command": "uv",
"args": ["run", "run_server.py", "stdio"],
}
) as server:
# Initialise the agent with the server
agent = Agent(
name="MCP agent",
model="o4-mini",
mcp_servers=[server],
)
result = await Runner.run(
starting_agent=agent,
input=query,
)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())