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
40from openai import OpenAI

client = OpenAI()

session = client.beta.agents.sessions.create(
 agent={
 "model": "gpt-6-astra",
 "instructions": "Use the OpenAI documentation MCP and web search to answer technical questions accurately. Delegate independent research tasks to subagents when useful.",
 "tools": [
 {"type": "programmatic_tool_calling"},
 {
 "type": "mcp",
 "server_label": "openai_docs",
 "transport": {
 "type": "http",
 "server_url": "https://developers.openai.com/mcp",
 },
 },
 {"type": "web_search"},
 ],
 "multi_agent": {"enabled": True, "max_concurrent_subagents": 4},
 },
 environment={
 "type": "self_hosted",
 "workspace_directory": "/workspace",
 "capability_directories": ["/workspace/capabilities/skills"],
 },
 input=[
 {
 "role": "user",
 "content": [
 {
 "type": "input_text",
 "text": "Research how to connect an MCP server to an OpenAI agent, check for recent updates, and summarize the recommended setup.",
 }
 ],
 }
 ],
)
print(session.id)