MCPcopy
hub / github.com/openai/gpt-oss / main

Function main

examples/agents-sdk-python/example.py:24–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24async def main():
25 # Set up OpenAI client for local server (e.g., Ollama)
26 openai_client = AsyncOpenAI(
27 api_key="local",
28 base_url="http://localhost:11434/v1",
29 )
30
31 # Get current working directory
32 samples_dir = str(Path.cwd())
33
34 # Create MCP server for filesystem operations
35 mcp_server = MCPServerStdio(
36 name="Filesystem MCP Server, via npx",
37 params={
38 "command": "npx",
39 "args": [
40 "-y",
41 "@modelcontextprotocol/server-filesystem",
42 samples_dir,
43 ],
44 },
45 )
46
47 # Connect to MCP server
48 await mcp_server.connect()
49
50 # Configure agents SDK
51 set_tracing_disabled(True)
52 set_default_openai_client(openai_client)
53 set_default_openai_api("chat_completions")
54
55 # Define weather tool
56 @function_tool
57 async def get_weather(location: str) -> str:
58 return f"The weather in {location} is sunny."
59
60 # Create agent
61 agent = Agent(
62 name="My Agent",
63 instructions="You are a helpful assistant.",
64 tools=[get_weather],
65 model="gpt-oss:20b-test",
66 mcp_servers=[mcp_server],
67 )
68
69 # Get user input
70 user_input = await prompt_user("> ")
71
72 # Run agent with streaming
73 result = Runner.run_streamed(agent, user_input)
74
75 # Process streaming results
76 async for event in result.stream_events():
77 if event.type == "raw_response_event":
78 continue
79 elif event.type == "agent_updated_stream_event":
80 print(f"Agent updated: {event.new_agent.name}")
81 elif event.type == "run_item_stream_event":

Callers 1

example.pyFile · 0.70

Calls 2

prompt_userFunction · 0.85
printFunction · 0.85

Tested by

no test coverage detected