Skip to content

Commit df5e647

Browse files
authored
Merge branch 'main' into main
2 parents 834042e + f20aa40 commit df5e647

File tree

132 files changed

+12288
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+12288
-749
lines changed

.github/workflows/update-docs.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Update Translated Docs"
2+
3+
# This GitHub Actions job automates the process of updating all translated document pages. Please note the following:
4+
# 1. The translation results may vary each time; some differences in detail are expected.
5+
# 2. When you add a new page to the left-hand menu, **make sure to manually update mkdocs.yml** to include the new item.
6+
# 3. If you switch to a different LLM (for example, from o3 to a newer model), be sure to conduct thorough testing before making the switch.
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- 'docs/**'
14+
- mkdocs.yml
15+
16+
jobs:
17+
update-docs:
18+
if: "!contains(github.event.head_commit.message, 'Update all translated document pages')"
19+
name: Build and Push Translated Docs
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 20
22+
env:
23+
PROD_OPENAI_API_KEY: ${{ secrets.PROD_OPENAI_API_KEY }}
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
- name: Setup uv
30+
uses: astral-sh/setup-uv@v5
31+
with:
32+
enable-cache: true
33+
- name: Install dependencies
34+
run: make sync
35+
- name: Build full docs
36+
run: make build-full-docs
37+
38+
- name: Commit changes
39+
id: commit
40+
run: |
41+
git config user.name "github-actions[bot]"
42+
git config user.email "github-actions[bot]@users.noreply.github.com"
43+
git add docs/
44+
if [ -n "$(git status --porcelain)" ]; then
45+
git commit -m "Update all translated document pages"
46+
echo "committed=true" >> "$GITHUB_OUTPUT"
47+
else
48+
echo "No changes to commit"
49+
echo "committed=false" >> "$GITHUB_OUTPUT"
50+
fi
51+
52+
- name: Create Pull Request
53+
if: steps.commit.outputs.committed == 'true'
54+
uses: peter-evans/create-pull-request@v6
55+
with:
56+
commit-message: "Update all translated document pages"
57+
title: "Update all translated document pages"
58+
body: "Automated update of translated documentation"
59+
branch: update-translated-docs-${{ github.run_id }}
60+
delete-branch: true

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: Python File",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${file}"
12+
}
13+
]
14+
}

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ format:
77
uv run ruff format
88
uv run ruff check --fix
99

10+
.PHONY: format-check
11+
format-check:
12+
uv run ruff format --check
13+
1014
.PHONY: lint
1115
lint:
1216
uv run ruff check
@@ -55,5 +59,5 @@ serve-docs:
5559
deploy-docs:
5660
uv run mkdocs gh-deploy --force --verbose
5761

58-
59-
62+
.PHONY: check
63+
check: format-check lint mypy tests

README.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,119 @@ The OpenAI Agents SDK is a lightweight yet powerful framework for building multi
1212
1. [**Agents**](https://openai.github.io/openai-agents-python/agents): LLMs configured with instructions, tools, guardrails, and handoffs
1313
2. [**Handoffs**](https://openai.github.io/openai-agents-python/handoffs/): A specialized tool call used by the Agents SDK for transferring control between agents
1414
3. [**Guardrails**](https://openai.github.io/openai-agents-python/guardrails/): Configurable safety checks for input and output validation
15-
4. [**Tracing**](https://openai.github.io/openai-agents-python/tracing/): Built-in tracking of agent runs, allowing you to view, debug and optimize your workflows
15+
4. [**Sessions**](#sessions): Automatic conversation history management across agent runs
16+
5. [**Tracing**](https://openai.github.io/openai-agents-python/tracing/): Built-in tracking of agent runs, allowing you to view, debug and optimize your workflows
1617

1718
Explore the [examples](examples) directory to see the SDK in action, and read our [documentation](https://openai.github.io/openai-agents-python/) for more details.
1819

20+
## Sessions
21+
22+
The Agents SDK provides built-in session memory to automatically maintain conversation history across multiple agent runs, eliminating the need to manually handle `.to_input_list()` between turns.
23+
24+
### Quick start
25+
26+
```python
27+
from agents import Agent, Runner, SQLiteSession
28+
29+
# Create agent
30+
agent = Agent(
31+
name="Assistant",
32+
instructions="Reply very concisely.",
33+
)
34+
35+
# Create a session instance
36+
session = SQLiteSession("conversation_123")
37+
38+
# First turn
39+
result = await Runner.run(
40+
agent,
41+
"What city is the Golden Gate Bridge in?",
42+
session=session
43+
)
44+
print(result.final_output) # "San Francisco"
45+
46+
# Second turn - agent automatically remembers previous context
47+
result = await Runner.run(
48+
agent,
49+
"What state is it in?",
50+
session=session
51+
)
52+
print(result.final_output) # "California"
53+
54+
# Also works with synchronous runner
55+
result = Runner.run_sync(
56+
agent,
57+
"What's the population?",
58+
session=session
59+
)
60+
print(result.final_output) # "Approximately 39 million"
61+
```
62+
63+
### Session options
64+
65+
- **No memory** (default): No session memory when session parameter is omitted
66+
- **`session: Session = DatabaseSession(...)`**: Use a Session instance to manage conversation history
67+
68+
```python
69+
from agents import Agent, Runner, SQLiteSession
70+
71+
# Custom SQLite database file
72+
session = SQLiteSession("user_123", "conversations.db")
73+
agent = Agent(name="Assistant")
74+
75+
# Different session IDs maintain separate conversation histories
76+
result1 = await Runner.run(
77+
agent,
78+
"Hello",
79+
session=session
80+
)
81+
result2 = await Runner.run(
82+
agent,
83+
"Hello",
84+
session=SQLiteSession("user_456", "conversations.db")
85+
)
86+
```
87+
88+
### Custom session implementations
89+
90+
You can implement your own session memory by creating a class that follows the `Session` protocol:
91+
92+
```python
93+
from agents.memory import Session
94+
from typing import List
95+
96+
class MyCustomSession:
97+
"""Custom session implementation following the Session protocol."""
98+
99+
def __init__(self, session_id: str):
100+
self.session_id = session_id
101+
# Your initialization here
102+
103+
async def get_items(self, limit: int | None = None) -> List[dict]:
104+
# Retrieve conversation history for the session
105+
pass
106+
107+
async def add_items(self, items: List[dict]) -> None:
108+
# Store new items for the session
109+
pass
110+
111+
async def pop_item(self) -> dict | None:
112+
# Remove and return the most recent item from the session
113+
pass
114+
115+
async def clear_session(self) -> None:
116+
# Clear all items for the session
117+
pass
118+
119+
# Use your custom session
120+
agent = Agent(name="Assistant")
121+
result = await Runner.run(
122+
agent,
123+
"Hello",
124+
session=MyCustomSession("my_session")
125+
)
126+
```
127+
19128
## Get started
20129

21130
1. Set up your Python environment
@@ -170,10 +279,16 @@ make sync
170279

171280
2. (After making changes) lint/test
172281

282+
```
283+
make check # run tests linter and typechecker
284+
```
285+
286+
Or to run them individually:
173287
```
174288
make tests # run tests
175289
make mypy # run typechecker
176290
make lint # run linter
291+
make format-check # run style checker
177292
```
178293

179294
## Acknowledgements

docs/agents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Agents are the core building block in your apps. An agent is a large language mo
66

77
The most common properties of an agent you'll configure are:
88

9+
- `name`: A required string that identifies your agent.
910
- `instructions`: also known as a developer message or system prompt.
1011
- `model`: which LLM to use, and optional `model_settings` to configure model tuning parameters like temperature, top_p, etc.
1112
- `tools`: Tools that the agent can use to achieve its tasks.

docs/examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ Check out a variety of sample implementations of the SDK in the examples section
4040

4141
- **[voice](https://github.com/openai/openai-agents-python/tree/main/examples/voice):**
4242
See examples of voice agents, using our TTS and STT models.
43+
44+
- **[realtime](https://github.com/openai/openai-agents-python/tree/main/examples/realtime):**
45+
Examples showing how to build realtime experiences using the SDK.

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The [OpenAI Agents SDK](https://github.com/openai/openai-agents-python) enables
55
- **Agents**, which are LLMs equipped with instructions and tools
66
- **Handoffs**, which allow agents to delegate to other agents for specific tasks
77
- **Guardrails**, which enable the inputs to agents to be validated
8+
- **Sessions**, which automatically maintains conversation history across agent runs
89

910
In combination with Python, these primitives are powerful enough to express complex relationships between tools and agents, and allow you to build real-world applications without a steep learning curve. In addition, the SDK comes with built-in **tracing** that lets you visualize and debug your agentic flows, as well as evaluate them and even fine-tune models for your application.
1011

@@ -21,6 +22,7 @@ Here are the main features of the SDK:
2122
- Python-first: Use built-in language features to orchestrate and chain agents, rather than needing to learn new abstractions.
2223
- Handoffs: A powerful feature to coordinate and delegate between multiple agents.
2324
- Guardrails: Run input validations and checks in parallel to your agents, breaking early if the checks fail.
25+
- Sessions: Automatic conversation history management across agent runs, eliminating manual state handling.
2426
- Function tools: Turn any Python function into a tool, with automatic schema generation and Pydantic-powered validation.
2527
- Tracing: Built-in tracing that lets you visualize, debug and monitor your workflows, as well as use the OpenAI suite of evaluation, fine-tuning and distillation tools.
2628

0 commit comments

Comments
 (0)