Skip to content

Commit 8490023

Browse files
authored
docs: add prompt template setup steps and MCP server manager guide (#2362)
1 parent 7a89ad5 commit 8490023

16 files changed

Lines changed: 136 additions & 0 deletions

File tree

docs/agents.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The most common properties of an agent you'll configure are:
99
- `name`: A required string that identifies your agent.
1010
- `instructions`: also known as a developer message or system prompt.
1111
- `model`: which LLM to use, and optional `model_settings` to configure model tuning parameters like temperature, top_p, etc.
12+
- `prompt`: Reference a prompt template by id (and variables) when using OpenAI's Responses API.
1213
- `tools`: Tools that the agent can use to achieve its tasks.
1314
- `mcp_servers`: MCP servers that provide tools to the agent. See the [MCP guide](mcp.md).
1415
- `reset_tool_choice`: Whether to reset `tool_choice` after a tool call (default: `True`) to avoid tool-use loops. See [Forcing tool use](#forcing-tool-use).
@@ -29,6 +30,65 @@ agent = Agent(
2930
)
3031
```
3132

33+
## Prompt templates
34+
35+
You can reference a prompt template created in the OpenAI platform by setting `prompt`. This works with OpenAI models using the Responses API.
36+
37+
To use it, please:
38+
39+
1. Go to https://platform.openai.com/playground/prompts
40+
2. Create a new prompt variable, `poem_style`.
41+
3. Create a system prompt with the content:
42+
43+
```
44+
Write a poem in {{poem_style}}
45+
```
46+
47+
4. Run the example with the `--prompt-id` flag.
48+
49+
```python
50+
from agents import Agent
51+
52+
agent = Agent(
53+
name="Prompted assistant",
54+
prompt={
55+
"id": "pmpt_123",
56+
"version": "1",
57+
"variables": {"poem_style": "haiku"},
58+
},
59+
)
60+
```
61+
62+
You can also generate the prompt dynamically at run time:
63+
64+
```python
65+
from dataclasses import dataclass
66+
67+
from agents import Agent, GenerateDynamicPromptData, Runner
68+
69+
@dataclass
70+
class PromptContext:
71+
prompt_id: str
72+
poem_style: str
73+
74+
75+
async def build_prompt(data: GenerateDynamicPromptData):
76+
ctx: PromptContext = data.context.context
77+
return {
78+
"id": ctx.prompt_id,
79+
"version": "1",
80+
"variables": {"poem_style": ctx.poem_style},
81+
}
82+
83+
84+
agent = Agent(name="Prompted assistant", prompt=build_prompt)
85+
result = await Runner.run(
86+
agent,
87+
"Say hello",
88+
context=PromptContext(prompt_id="pmpt_123", poem_style="limerick"),
89+
)
90+
```
91+
3292
## Context
3393

3494
Agents are generic on their `context` type. Context is a dependency-injection tool: it's an object you create and pass to `Runner.run()`, that is passed to every agent, tool, handoff etc, and it serves as a grab bag of dependencies and state for the agent run. You can provide any Python object as the context.

docs/config.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ from agents import set_tracing_export_api_key
3838
set_tracing_export_api_key("sk-...")
3939
```
4040

41+
If you need to attribute traces to a specific organization or project when using the default exporter, set these environment variables before your app starts:
42+
43+
```bash
44+
export OPENAI_ORG_ID="org_..."
45+
export OPENAI_PROJECT_ID="proj_..."
46+
```
47+
4148
You can also set a tracing API key per run without changing the global exporter.
4249

4350
```python

docs/mcp.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,37 @@ async with MCPServerStdio(
243243
print(result.final_output)
244244
```
245245

246+
## 5. MCP server manager
247+
248+
When you have multiple MCP servers, use `MCPServerManager` to connect them up front and expose the connected subset to your agents.
249+
250+
```python
251+
from agents import Agent, Runner
252+
from agents.mcp import MCPServerManager, MCPServerStreamableHttp
253+
254+
servers = [
255+
MCPServerStreamableHttp(name="calendar", params={"url": "http://localhost:8000/mcp"}),
256+
MCPServerStreamableHttp(name="docs", params={"url": "http://localhost:8001/mcp"}),
257+
]
258+
259+
async with MCPServerManager(servers) as manager:
260+
agent = Agent(
261+
name="Assistant",
262+
instructions="Use MCP tools when they help.",
263+
mcp_servers=manager.active_servers,
264+
)
265+
result = await Runner.run(agent, "Which MCP tools are available?")
266+
print(result.final_output)
267+
```
268+
269+
Key behaviors:
270+
271+
- `active_servers` includes only successfully connected servers when `drop_failed_servers=True` (the default).
272+
- Failures are tracked in `failed_servers` and `errors`.
273+
- Set `strict=True` to raise on the first connection failure.
274+
- Call `reconnect(failed_only=True)` to retry failed servers, or `reconnect(failed_only=False)` to restart all servers.
275+
- Use `connect_timeout_seconds`, `cleanup_timeout_seconds`, and `connect_in_parallel` to tune lifecycle behavior.
276+
246277
## Tool filtering
247278

248279
Each MCP server supports tool filters so that you can expose only the functions that your agent needs. Filtering can happen at
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Codex`
2+
3+
::: agents.extensions.experimental.codex.codex
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Codex Options`
2+
3+
::: agents.extensions.experimental.codex.codex_options
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Codex Tool`
2+
3+
::: agents.extensions.experimental.codex.codex_tool
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Events`
2+
3+
::: agents.extensions.experimental.codex.events
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Exec`
2+
3+
::: agents.extensions.experimental.codex.exec
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Items`
2+
3+
::: agents.extensions.experimental.codex.items
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Output Schema File`
2+
3+
::: agents.extensions.experimental.codex.output_schema_file

0 commit comments

Comments
 (0)