openai-agents 0.2.1__py3-none-any.whl → 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openai-agents might be problematic. Click here for more details.
- agents/guardrail.py +5 -1
- agents/items.py +2 -1
- agents/model_settings.py +2 -1
- agents/models/chatcmpl_stream_handler.py +3 -3
- agents/realtime/openai_realtime.py +6 -1
- agents/realtime/runner.py +1 -43
- agents/realtime/session.py +34 -8
- agents/tool.py +5 -0
- agents/usage.py +2 -1
- {openai_agents-0.2.1.dist-info → openai_agents-0.2.3.dist-info}/METADATA +114 -111
- {openai_agents-0.2.1.dist-info → openai_agents-0.2.3.dist-info}/RECORD +13 -13
- {openai_agents-0.2.1.dist-info → openai_agents-0.2.3.dist-info}/WHEEL +0 -0
- {openai_agents-0.2.1.dist-info → openai_agents-0.2.3.dist-info}/licenses/LICENSE +0 -0
agents/guardrail.py
CHANGED
|
@@ -314,7 +314,11 @@ def output_guardrail(
|
|
|
314
314
|
def decorator(
|
|
315
315
|
f: _OutputGuardrailFuncSync[TContext_co] | _OutputGuardrailFuncAsync[TContext_co],
|
|
316
316
|
) -> OutputGuardrail[TContext_co]:
|
|
317
|
-
return OutputGuardrail(
|
|
317
|
+
return OutputGuardrail(
|
|
318
|
+
guardrail_function=f,
|
|
319
|
+
# Guardrail name defaults to function name when not specified (None).
|
|
320
|
+
name=name if name else f.__name__,
|
|
321
|
+
)
|
|
318
322
|
|
|
319
323
|
if func is not None:
|
|
320
324
|
# Decorator was used without parentheses
|
agents/items.py
CHANGED
|
@@ -5,6 +5,7 @@ import copy
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, Union
|
|
7
7
|
|
|
8
|
+
import pydantic
|
|
8
9
|
from openai.types.responses import (
|
|
9
10
|
Response,
|
|
10
11
|
ResponseComputerToolCall,
|
|
@@ -212,7 +213,7 @@ RunItem: TypeAlias = Union[
|
|
|
212
213
|
"""An item generated by an agent."""
|
|
213
214
|
|
|
214
215
|
|
|
215
|
-
@dataclass
|
|
216
|
+
@pydantic.dataclasses.dataclass
|
|
216
217
|
class ModelResponse:
|
|
217
218
|
output: list[TResponseOutputItem]
|
|
218
219
|
"""A list of outputs (messages, tool calls, etc) generated by the model"""
|
agents/model_settings.py
CHANGED
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import dataclasses
|
|
4
4
|
from collections.abc import Mapping
|
|
5
|
-
from dataclasses import
|
|
5
|
+
from dataclasses import fields, replace
|
|
6
6
|
from typing import Annotated, Any, Literal, Union
|
|
7
7
|
|
|
8
8
|
from openai import Omit as _Omit
|
|
@@ -10,6 +10,7 @@ from openai._types import Body, Query
|
|
|
10
10
|
from openai.types.responses import ResponseIncludable
|
|
11
11
|
from openai.types.shared import Reasoning
|
|
12
12
|
from pydantic import BaseModel, GetCoreSchemaHandler
|
|
13
|
+
from pydantic.dataclasses import dataclass
|
|
13
14
|
from pydantic_core import core_schema
|
|
14
15
|
from typing_extensions import TypeAlias
|
|
15
16
|
|
|
@@ -493,9 +493,9 @@ class ChatCmplStreamHandler:
|
|
|
493
493
|
final_response.output = outputs
|
|
494
494
|
final_response.usage = (
|
|
495
495
|
ResponseUsage(
|
|
496
|
-
input_tokens=usage.prompt_tokens,
|
|
497
|
-
output_tokens=usage.completion_tokens,
|
|
498
|
-
total_tokens=usage.total_tokens,
|
|
496
|
+
input_tokens=usage.prompt_tokens or 0,
|
|
497
|
+
output_tokens=usage.completion_tokens or 0,
|
|
498
|
+
total_tokens=usage.total_tokens or 0,
|
|
499
499
|
output_tokens_details=OutputTokensDetails(
|
|
500
500
|
reasoning_tokens=usage.completion_tokens_details.reasoning_tokens
|
|
501
501
|
if usage.completion_tokens_details
|
|
@@ -62,6 +62,7 @@ from agents.util._types import MaybeAwaitable
|
|
|
62
62
|
|
|
63
63
|
from ..exceptions import UserError
|
|
64
64
|
from ..logger import logger
|
|
65
|
+
from ..version import __version__
|
|
65
66
|
from .config import (
|
|
66
67
|
RealtimeModelTracingConfig,
|
|
67
68
|
RealtimeSessionModelSettings,
|
|
@@ -97,6 +98,8 @@ from .model_inputs import (
|
|
|
97
98
|
RealtimeModelSendUserInput,
|
|
98
99
|
)
|
|
99
100
|
|
|
101
|
+
_USER_AGENT = f"Agents/Python {__version__}"
|
|
102
|
+
|
|
100
103
|
DEFAULT_MODEL_SETTINGS: RealtimeSessionModelSettings = {
|
|
101
104
|
"voice": "ash",
|
|
102
105
|
"modalities": ["text", "audio"],
|
|
@@ -160,7 +163,9 @@ class OpenAIRealtimeWebSocketModel(RealtimeModel):
|
|
|
160
163
|
"Authorization": f"Bearer {api_key}",
|
|
161
164
|
"OpenAI-Beta": "realtime=v1",
|
|
162
165
|
}
|
|
163
|
-
self._websocket = await websockets.connect(
|
|
166
|
+
self._websocket = await websockets.connect(
|
|
167
|
+
url, user_agent_header=_USER_AGENT, additional_headers=headers
|
|
168
|
+
)
|
|
164
169
|
self._websocket_task = asyncio.create_task(self._listen_for_messages())
|
|
165
170
|
await self._update_session_config(model_settings)
|
|
166
171
|
|
agents/realtime/runner.py
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
from ..run_context import RunContextWrapper, TContext
|
|
5
|
+
from ..run_context import TContext
|
|
8
6
|
from .agent import RealtimeAgent
|
|
9
7
|
from .config import (
|
|
10
8
|
RealtimeRunConfig,
|
|
11
|
-
RealtimeSessionModelSettings,
|
|
12
9
|
)
|
|
13
10
|
from .model import (
|
|
14
11
|
RealtimeModel,
|
|
@@ -67,16 +64,6 @@ class RealtimeRunner:
|
|
|
67
64
|
print(event)
|
|
68
65
|
```
|
|
69
66
|
"""
|
|
70
|
-
model_settings = await self._get_model_settings(
|
|
71
|
-
agent=self._starting_agent,
|
|
72
|
-
disable_tracing=self._config.get("tracing_disabled", False) if self._config else False,
|
|
73
|
-
initial_settings=model_config.get("initial_model_settings") if model_config else None,
|
|
74
|
-
overrides=self._config.get("model_settings") if self._config else None,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
model_config = model_config.copy() if model_config else {}
|
|
78
|
-
model_config["initial_model_settings"] = model_settings
|
|
79
|
-
|
|
80
67
|
# Create and return the connection
|
|
81
68
|
session = RealtimeSession(
|
|
82
69
|
model=self._model,
|
|
@@ -87,32 +74,3 @@ class RealtimeRunner:
|
|
|
87
74
|
)
|
|
88
75
|
|
|
89
76
|
return session
|
|
90
|
-
|
|
91
|
-
async def _get_model_settings(
|
|
92
|
-
self,
|
|
93
|
-
agent: RealtimeAgent,
|
|
94
|
-
disable_tracing: bool,
|
|
95
|
-
context: TContext | None = None,
|
|
96
|
-
initial_settings: RealtimeSessionModelSettings | None = None,
|
|
97
|
-
overrides: RealtimeSessionModelSettings | None = None,
|
|
98
|
-
) -> RealtimeSessionModelSettings:
|
|
99
|
-
context_wrapper = RunContextWrapper(context)
|
|
100
|
-
model_settings = initial_settings.copy() if initial_settings else {}
|
|
101
|
-
|
|
102
|
-
instructions, tools = await asyncio.gather(
|
|
103
|
-
agent.get_system_prompt(context_wrapper),
|
|
104
|
-
agent.get_all_tools(context_wrapper),
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
if instructions is not None:
|
|
108
|
-
model_settings["instructions"] = instructions
|
|
109
|
-
if tools is not None:
|
|
110
|
-
model_settings["tools"] = tools
|
|
111
|
-
|
|
112
|
-
if overrides:
|
|
113
|
-
model_settings.update(overrides)
|
|
114
|
-
|
|
115
|
-
if disable_tracing:
|
|
116
|
-
model_settings["tracing"] = None
|
|
117
|
-
|
|
118
|
-
return model_settings
|
agents/realtime/session.py
CHANGED
|
@@ -107,6 +107,11 @@ class RealtimeSession(RealtimeModelListener):
|
|
|
107
107
|
|
|
108
108
|
self._guardrail_tasks: set[asyncio.Task[Any]] = set()
|
|
109
109
|
|
|
110
|
+
@property
|
|
111
|
+
def model(self) -> RealtimeModel:
|
|
112
|
+
"""Access the underlying model for adding listeners or other direct interaction."""
|
|
113
|
+
return self._model
|
|
114
|
+
|
|
110
115
|
async def __aenter__(self) -> RealtimeSession:
|
|
111
116
|
"""Start the session by connecting to the model. After this, you will be able to stream
|
|
112
117
|
events from the model and send messages and audio to the model.
|
|
@@ -114,8 +119,14 @@ class RealtimeSession(RealtimeModelListener):
|
|
|
114
119
|
# Add ourselves as a listener
|
|
115
120
|
self._model.add_listener(self)
|
|
116
121
|
|
|
122
|
+
model_config = self._model_config.copy()
|
|
123
|
+
model_config["initial_model_settings"] = await self._get_updated_model_settings_from_agent(
|
|
124
|
+
starting_settings=self._model_config.get("initial_model_settings", None),
|
|
125
|
+
agent=self._current_agent,
|
|
126
|
+
)
|
|
127
|
+
|
|
117
128
|
# Connect to the model
|
|
118
|
-
await self._model.connect(
|
|
129
|
+
await self._model.connect(model_config)
|
|
119
130
|
|
|
120
131
|
# Emit initial history update
|
|
121
132
|
await self._put_event(
|
|
@@ -319,7 +330,10 @@ class RealtimeSession(RealtimeModelListener):
|
|
|
319
330
|
self._current_agent = result
|
|
320
331
|
|
|
321
332
|
# Get updated model settings from new agent
|
|
322
|
-
updated_settings = await self.
|
|
333
|
+
updated_settings = await self._get_updated_model_settings_from_agent(
|
|
334
|
+
starting_settings=None,
|
|
335
|
+
agent=self._current_agent,
|
|
336
|
+
)
|
|
323
337
|
|
|
324
338
|
# Send handoff event
|
|
325
339
|
await self._put_event(
|
|
@@ -495,19 +509,31 @@ class RealtimeSession(RealtimeModelListener):
|
|
|
495
509
|
# Mark as closed
|
|
496
510
|
self._closed = True
|
|
497
511
|
|
|
498
|
-
async def
|
|
499
|
-
self,
|
|
512
|
+
async def _get_updated_model_settings_from_agent(
|
|
513
|
+
self,
|
|
514
|
+
starting_settings: RealtimeSessionModelSettings | None,
|
|
515
|
+
agent: RealtimeAgent,
|
|
500
516
|
) -> RealtimeSessionModelSettings:
|
|
501
|
-
|
|
517
|
+
# Start with run config model settings as base
|
|
518
|
+
run_config_settings = self._run_config.get("model_settings", {})
|
|
519
|
+
updated_settings: RealtimeSessionModelSettings = run_config_settings.copy()
|
|
520
|
+
# Apply starting settings (from model config) next
|
|
521
|
+
if starting_settings:
|
|
522
|
+
updated_settings.update(starting_settings)
|
|
523
|
+
|
|
502
524
|
instructions, tools, handoffs = await asyncio.gather(
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
self._get_handoffs(
|
|
525
|
+
agent.get_system_prompt(self._context_wrapper),
|
|
526
|
+
agent.get_all_tools(self._context_wrapper),
|
|
527
|
+
self._get_handoffs(agent, self._context_wrapper),
|
|
506
528
|
)
|
|
507
529
|
updated_settings["instructions"] = instructions or ""
|
|
508
530
|
updated_settings["tools"] = tools or []
|
|
509
531
|
updated_settings["handoffs"] = handoffs or []
|
|
510
532
|
|
|
533
|
+
disable_tracing = self._run_config.get("tracing_disabled", False)
|
|
534
|
+
if disable_tracing:
|
|
535
|
+
updated_settings["tracing"] = None
|
|
536
|
+
|
|
511
537
|
return updated_settings
|
|
512
538
|
|
|
513
539
|
@classmethod
|
agents/tool.py
CHANGED
|
@@ -24,6 +24,7 @@ from .function_schema import DocstringStyle, function_schema
|
|
|
24
24
|
from .items import RunItem
|
|
25
25
|
from .logger import logger
|
|
26
26
|
from .run_context import RunContextWrapper
|
|
27
|
+
from .strict_schema import ensure_strict_json_schema
|
|
27
28
|
from .tool_context import ToolContext
|
|
28
29
|
from .tracing import SpanError
|
|
29
30
|
from .util import _error_tracing
|
|
@@ -92,6 +93,10 @@ class FunctionTool:
|
|
|
92
93
|
and returns whether the tool is enabled. You can use this to dynamically enable/disable a tool
|
|
93
94
|
based on your context/state."""
|
|
94
95
|
|
|
96
|
+
def __post_init__(self):
|
|
97
|
+
if self.strict_json_schema:
|
|
98
|
+
self.params_json_schema = ensure_strict_json_schema(self.params_json_schema)
|
|
99
|
+
|
|
95
100
|
|
|
96
101
|
@dataclass
|
|
97
102
|
class FileSearchTool:
|
agents/usage.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openai-agents
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: OpenAI Agents SDK
|
|
5
5
|
Project-URL: Homepage, https://openai.github.io/openai-agents-python/
|
|
6
6
|
Project-URL: Repository, https://github.com/openai/openai-agents-python
|
|
@@ -56,125 +56,19 @@ The OpenAI Agents SDK is a lightweight yet powerful framework for building multi
|
|
|
56
56
|
|
|
57
57
|
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.
|
|
58
58
|
|
|
59
|
-
## Sessions
|
|
60
|
-
|
|
61
|
-
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.
|
|
62
|
-
|
|
63
|
-
### Quick start
|
|
64
|
-
|
|
65
|
-
```python
|
|
66
|
-
from agents import Agent, Runner, SQLiteSession
|
|
67
|
-
|
|
68
|
-
# Create agent
|
|
69
|
-
agent = Agent(
|
|
70
|
-
name="Assistant",
|
|
71
|
-
instructions="Reply very concisely.",
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
# Create a session instance
|
|
75
|
-
session = SQLiteSession("conversation_123")
|
|
76
|
-
|
|
77
|
-
# First turn
|
|
78
|
-
result = await Runner.run(
|
|
79
|
-
agent,
|
|
80
|
-
"What city is the Golden Gate Bridge in?",
|
|
81
|
-
session=session
|
|
82
|
-
)
|
|
83
|
-
print(result.final_output) # "San Francisco"
|
|
84
|
-
|
|
85
|
-
# Second turn - agent automatically remembers previous context
|
|
86
|
-
result = await Runner.run(
|
|
87
|
-
agent,
|
|
88
|
-
"What state is it in?",
|
|
89
|
-
session=session
|
|
90
|
-
)
|
|
91
|
-
print(result.final_output) # "California"
|
|
92
|
-
|
|
93
|
-
# Also works with synchronous runner
|
|
94
|
-
result = Runner.run_sync(
|
|
95
|
-
agent,
|
|
96
|
-
"What's the population?",
|
|
97
|
-
session=session
|
|
98
|
-
)
|
|
99
|
-
print(result.final_output) # "Approximately 39 million"
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Session options
|
|
103
|
-
|
|
104
|
-
- **No memory** (default): No session memory when session parameter is omitted
|
|
105
|
-
- **`session: Session = DatabaseSession(...)`**: Use a Session instance to manage conversation history
|
|
106
|
-
|
|
107
|
-
```python
|
|
108
|
-
from agents import Agent, Runner, SQLiteSession
|
|
109
|
-
|
|
110
|
-
# Custom SQLite database file
|
|
111
|
-
session = SQLiteSession("user_123", "conversations.db")
|
|
112
|
-
agent = Agent(name="Assistant")
|
|
113
|
-
|
|
114
|
-
# Different session IDs maintain separate conversation histories
|
|
115
|
-
result1 = await Runner.run(
|
|
116
|
-
agent,
|
|
117
|
-
"Hello",
|
|
118
|
-
session=session
|
|
119
|
-
)
|
|
120
|
-
result2 = await Runner.run(
|
|
121
|
-
agent,
|
|
122
|
-
"Hello",
|
|
123
|
-
session=SQLiteSession("user_456", "conversations.db")
|
|
124
|
-
)
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Custom session implementations
|
|
128
|
-
|
|
129
|
-
You can implement your own session memory by creating a class that follows the `Session` protocol:
|
|
130
|
-
|
|
131
|
-
```python
|
|
132
|
-
from agents.memory import Session
|
|
133
|
-
from typing import List
|
|
134
|
-
|
|
135
|
-
class MyCustomSession:
|
|
136
|
-
"""Custom session implementation following the Session protocol."""
|
|
137
|
-
|
|
138
|
-
def __init__(self, session_id: str):
|
|
139
|
-
self.session_id = session_id
|
|
140
|
-
# Your initialization here
|
|
141
|
-
|
|
142
|
-
async def get_items(self, limit: int | None = None) -> List[dict]:
|
|
143
|
-
# Retrieve conversation history for the session
|
|
144
|
-
pass
|
|
145
|
-
|
|
146
|
-
async def add_items(self, items: List[dict]) -> None:
|
|
147
|
-
# Store new items for the session
|
|
148
|
-
pass
|
|
149
|
-
|
|
150
|
-
async def pop_item(self) -> dict | None:
|
|
151
|
-
# Remove and return the most recent item from the session
|
|
152
|
-
pass
|
|
153
|
-
|
|
154
|
-
async def clear_session(self) -> None:
|
|
155
|
-
# Clear all items for the session
|
|
156
|
-
pass
|
|
157
|
-
|
|
158
|
-
# Use your custom session
|
|
159
|
-
agent = Agent(name="Assistant")
|
|
160
|
-
result = await Runner.run(
|
|
161
|
-
agent,
|
|
162
|
-
"Hello",
|
|
163
|
-
session=MyCustomSession("my_session")
|
|
164
|
-
)
|
|
165
|
-
```
|
|
166
|
-
|
|
167
59
|
## Get started
|
|
168
60
|
|
|
169
61
|
1. Set up your Python environment
|
|
170
62
|
|
|
171
|
-
-
|
|
63
|
+
- Option A: Using venv (traditional method)
|
|
64
|
+
|
|
172
65
|
```bash
|
|
173
66
|
python -m venv env
|
|
174
67
|
source env/bin/activate # On Windows: env\Scripts\activate
|
|
175
68
|
```
|
|
176
69
|
|
|
177
|
-
-
|
|
70
|
+
- Option B: Using uv (recommended)
|
|
71
|
+
|
|
178
72
|
```bash
|
|
179
73
|
uv venv
|
|
180
74
|
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
@@ -302,6 +196,114 @@ The Agents SDK is designed to be highly flexible, allowing you to model a wide r
|
|
|
302
196
|
|
|
303
197
|
The Agents SDK automatically traces your agent runs, making it easy to track and debug the behavior of your agents. Tracing is extensible by design, supporting custom spans and a wide variety of external destinations, including [Logfire](https://logfire.pydantic.dev/docs/integrations/llms/openai/#openai-agents), [AgentOps](https://docs.agentops.ai/v1/integrations/agentssdk), [Braintrust](https://braintrust.dev/docs/guides/traces/integrations#openai-agents-sdk), [Scorecard](https://docs.scorecard.io/docs/documentation/features/tracing#openai-agents-sdk-integration), and [Keywords AI](https://docs.keywordsai.co/integration/development-frameworks/openai-agent). For more details about how to customize or disable tracing, see [Tracing](http://openai.github.io/openai-agents-python/tracing), which also includes a larger list of [external tracing processors](http://openai.github.io/openai-agents-python/tracing/#external-tracing-processors-list).
|
|
304
198
|
|
|
199
|
+
## Sessions
|
|
200
|
+
|
|
201
|
+
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.
|
|
202
|
+
|
|
203
|
+
### Quick start
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from agents import Agent, Runner, SQLiteSession
|
|
207
|
+
|
|
208
|
+
# Create agent
|
|
209
|
+
agent = Agent(
|
|
210
|
+
name="Assistant",
|
|
211
|
+
instructions="Reply very concisely.",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Create a session instance
|
|
215
|
+
session = SQLiteSession("conversation_123")
|
|
216
|
+
|
|
217
|
+
# First turn
|
|
218
|
+
result = await Runner.run(
|
|
219
|
+
agent,
|
|
220
|
+
"What city is the Golden Gate Bridge in?",
|
|
221
|
+
session=session
|
|
222
|
+
)
|
|
223
|
+
print(result.final_output) # "San Francisco"
|
|
224
|
+
|
|
225
|
+
# Second turn - agent automatically remembers previous context
|
|
226
|
+
result = await Runner.run(
|
|
227
|
+
agent,
|
|
228
|
+
"What state is it in?",
|
|
229
|
+
session=session
|
|
230
|
+
)
|
|
231
|
+
print(result.final_output) # "California"
|
|
232
|
+
|
|
233
|
+
# Also works with synchronous runner
|
|
234
|
+
result = Runner.run_sync(
|
|
235
|
+
agent,
|
|
236
|
+
"What's the population?",
|
|
237
|
+
session=session
|
|
238
|
+
)
|
|
239
|
+
print(result.final_output) # "Approximately 39 million"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Session options
|
|
243
|
+
|
|
244
|
+
- **No memory** (default): No session memory when session parameter is omitted
|
|
245
|
+
- **`session: Session = DatabaseSession(...)`**: Use a Session instance to manage conversation history
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from agents import Agent, Runner, SQLiteSession
|
|
249
|
+
|
|
250
|
+
# Custom SQLite database file
|
|
251
|
+
session = SQLiteSession("user_123", "conversations.db")
|
|
252
|
+
agent = Agent(name="Assistant")
|
|
253
|
+
|
|
254
|
+
# Different session IDs maintain separate conversation histories
|
|
255
|
+
result1 = await Runner.run(
|
|
256
|
+
agent,
|
|
257
|
+
"Hello",
|
|
258
|
+
session=session
|
|
259
|
+
)
|
|
260
|
+
result2 = await Runner.run(
|
|
261
|
+
agent,
|
|
262
|
+
"Hello",
|
|
263
|
+
session=SQLiteSession("user_456", "conversations.db")
|
|
264
|
+
)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Custom session implementations
|
|
268
|
+
|
|
269
|
+
You can implement your own session memory by creating a class that follows the `Session` protocol:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from agents.memory import Session
|
|
273
|
+
from typing import List
|
|
274
|
+
|
|
275
|
+
class MyCustomSession:
|
|
276
|
+
"""Custom session implementation following the Session protocol."""
|
|
277
|
+
|
|
278
|
+
def __init__(self, session_id: str):
|
|
279
|
+
self.session_id = session_id
|
|
280
|
+
# Your initialization here
|
|
281
|
+
|
|
282
|
+
async def get_items(self, limit: int | None = None) -> List[dict]:
|
|
283
|
+
# Retrieve conversation history for the session
|
|
284
|
+
pass
|
|
285
|
+
|
|
286
|
+
async def add_items(self, items: List[dict]) -> None:
|
|
287
|
+
# Store new items for the session
|
|
288
|
+
pass
|
|
289
|
+
|
|
290
|
+
async def pop_item(self) -> dict | None:
|
|
291
|
+
# Remove and return the most recent item from the session
|
|
292
|
+
pass
|
|
293
|
+
|
|
294
|
+
async def clear_session(self) -> None:
|
|
295
|
+
# Clear all items for the session
|
|
296
|
+
pass
|
|
297
|
+
|
|
298
|
+
# Use your custom session
|
|
299
|
+
agent = Agent(name="Assistant")
|
|
300
|
+
result = await Runner.run(
|
|
301
|
+
agent,
|
|
302
|
+
"Hello",
|
|
303
|
+
session=MyCustomSession("my_session")
|
|
304
|
+
)
|
|
305
|
+
```
|
|
306
|
+
|
|
305
307
|
## Development (only needed if you need to edit the SDK/examples)
|
|
306
308
|
|
|
307
309
|
0. Ensure you have [`uv`](https://docs.astral.sh/uv/) installed.
|
|
@@ -323,6 +325,7 @@ make check # run tests linter and typechecker
|
|
|
323
325
|
```
|
|
324
326
|
|
|
325
327
|
Or to run them individually:
|
|
328
|
+
|
|
326
329
|
```
|
|
327
330
|
make tests # run tests
|
|
328
331
|
make mypy # run typechecker
|
|
@@ -7,12 +7,12 @@ agents/agent_output.py,sha256=bHItis02dw-issbxjB4VnjUFdSByM9OR26rzxsFOSnQ,7154
|
|
|
7
7
|
agents/computer.py,sha256=XD44UgiUWSfniv-xKwwDP6wFKVwBiZkpaL1hO-0-7ZA,2516
|
|
8
8
|
agents/exceptions.py,sha256=NHMdHE0cZ6AdA6UgUylTzVHAX05Ol1CkO814a0FdZcs,2862
|
|
9
9
|
agents/function_schema.py,sha256=JvMh356N60_c3hj7BXySuM7eqVwP00jealR7rdPnl60,13590
|
|
10
|
-
agents/guardrail.py,sha256=
|
|
10
|
+
agents/guardrail.py,sha256=kanNTh1OqSpzFH6QyNfucLDYHbBnvq3u-kWnFJw4lD8,9571
|
|
11
11
|
agents/handoffs.py,sha256=L-b2eMNKyi-uF5Isz7UfpKc2Amvqies3i5tVjDnM3M4,10793
|
|
12
|
-
agents/items.py,sha256=
|
|
12
|
+
agents/items.py,sha256=ZKc4aOBearYF4ItT9qtmehUUt9aS-3D0kVA3reoV1mU,9732
|
|
13
13
|
agents/lifecycle.py,sha256=C1LSoCa_0zf0nt7yI3SKL5bAAG4Cso6--Gmk8S8zpJg,3111
|
|
14
14
|
agents/logger.py,sha256=p_ef7vWKpBev5FFybPJjhrCCQizK08Yy1A2EDO1SNNg,60
|
|
15
|
-
agents/model_settings.py,sha256=
|
|
15
|
+
agents/model_settings.py,sha256=uWYuQJDzQmXTBxt79fsIhgfxvf2rEiY09m9dDgk-yBk,6075
|
|
16
16
|
agents/prompts.py,sha256=Ss5y_7s2HFcRAOAKu4WTxQszs5ybI8TfbxgEYdnj9sg,2231
|
|
17
17
|
agents/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
18
18
|
agents/repl.py,sha256=FKZlkGfw6QxItTkjFkCAQwXuV_pn69DIamGd3PiKQFk,2361
|
|
@@ -21,9 +21,9 @@ agents/run.py,sha256=GNVMvEs0cw5oU6OISrN5YYEVYVF-KduMt3nfpgBynLs,50792
|
|
|
21
21
|
agents/run_context.py,sha256=vuSUQM8O4CLensQY27-22fOqECnw7yvwL9U3WO8b_bk,851
|
|
22
22
|
agents/stream_events.py,sha256=VFyTu-DT3ZMnHLtMbg-X_lxec0doQxNfx-hVxLB0BpI,1700
|
|
23
23
|
agents/strict_schema.py,sha256=_KuEJkglmq-Fj3HSeYP4WqTvqrxbSKu6gezfz5Brhh0,5775
|
|
24
|
-
agents/tool.py,sha256=
|
|
24
|
+
agents/tool.py,sha256=CWjwssw4TSnvvQaxo42mUkA2Y5sZzM_h3QTq8zJwIRs,16750
|
|
25
25
|
agents/tool_context.py,sha256=lbnctijZeanXAThddkklF7vDrXK1Ie2_wx6JZPCOihI,1434
|
|
26
|
-
agents/usage.py,sha256=
|
|
26
|
+
agents/usage.py,sha256=Tb5udGd3DPgD0JBdRD8fDctTE4M-zKML5uRn8ZG1yBc,1675
|
|
27
27
|
agents/version.py,sha256=_1knUwzSK-HUeZTpRUkk6Z-CIcurqXuEplbV5TLJ08E,230
|
|
28
28
|
agents/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
29
|
agents/extensions/handoff_filters.py,sha256=2cXxu1JROez96CpTiGuT9PIuaIrIE8ksP01fX83krKM,1977
|
|
@@ -41,7 +41,7 @@ agents/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
41
41
|
agents/models/_openai_shared.py,sha256=4Ngwo2Fv2RXY61Pqck1cYPkSln2tDnb8Ai-ao4QG-iE,836
|
|
42
42
|
agents/models/chatcmpl_converter.py,sha256=lHVmWOxULJd_Q9WnWdh_ZYYRq07-4UNfpl7KDZEGZdg,19420
|
|
43
43
|
agents/models/chatcmpl_helpers.py,sha256=eIWySobaH7I0AQijAz5i-_rtsXrSvmEHD567s_8Zw1o,1318
|
|
44
|
-
agents/models/chatcmpl_stream_handler.py,sha256=
|
|
44
|
+
agents/models/chatcmpl_stream_handler.py,sha256=3tbGS-mCOVUz9lLbm35rFxC8piYDsWqIJ8DCPE1DjuQ,23999
|
|
45
45
|
agents/models/fake_id.py,sha256=lbXjUUSMeAQ8eFx4V5QLUnBClHE6adJlYYav55RlG5w,268
|
|
46
46
|
agents/models/interface.py,sha256=TpY_GEk3LLMozCcYAEcC-Y_VRpI3pwE7A7ZM317mk7M,3839
|
|
47
47
|
agents/models/multi_provider.py,sha256=aiDbls5G4YomPfN6qH1pGlj41WS5jlDp2T82zm6qcnM,5578
|
|
@@ -58,9 +58,9 @@ agents/realtime/items.py,sha256=psT6AH65qmngmPsgwk6CXacVo5tEDYq0Za3EitHFpTA,5052
|
|
|
58
58
|
agents/realtime/model.py,sha256=YwMBwtj33Z6uADnz1AoYg4wSfmpfYdZNq7ZaK8hlekw,2188
|
|
59
59
|
agents/realtime/model_events.py,sha256=JDh70uDctVuwex5EiYUdWhqQvBarN3ge7eREd1aUznU,3386
|
|
60
60
|
agents/realtime/model_inputs.py,sha256=OW2bn3wD5_pXLunDUf35jhG2q_bTKbC_D7Qu-83aOEA,2243
|
|
61
|
-
agents/realtime/openai_realtime.py,sha256=
|
|
62
|
-
agents/realtime/runner.py,sha256=
|
|
63
|
-
agents/realtime/session.py,sha256=
|
|
61
|
+
agents/realtime/openai_realtime.py,sha256=dvy07idciGl8E0swuvmgtHYf7DUSitHrwImAiG_VFq0,27323
|
|
62
|
+
agents/realtime/runner.py,sha256=KfU7utmc9QFH2htIKN2IN9H-5EnB0qN9ezmvlRTnOm4,2511
|
|
63
|
+
agents/realtime/session.py,sha256=jMOYmv3KcszBLLPcYkW_ChNiOblyoiGiYZ9jE6WUNEU,21908
|
|
64
64
|
agents/tracing/__init__.py,sha256=5HO_6na5S6EwICgwl50OMtxiIIosUrqalhvldlYvSVc,2991
|
|
65
65
|
agents/tracing/create.py,sha256=Gm9N5O2DeBy6UU86tRN0wnmzWyXb-qAUBbTj9oxIHao,18106
|
|
66
66
|
agents/tracing/logger.py,sha256=J4KUDRSGa7x5UVfUwWe-gbKwoaq8AeETRqkPt3QvtGg,68
|
|
@@ -95,7 +95,7 @@ agents/voice/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
|
|
|
95
95
|
agents/voice/models/openai_model_provider.py,sha256=Khn0uT-VhsEbe7_OhBMGFQzXNwL80gcWZyTHl3CaBII,3587
|
|
96
96
|
agents/voice/models/openai_stt.py,sha256=LcVDS7f1pmbm--PWX-IaV9uLg9uv5_L3vSCbVnTJeGs,16864
|
|
97
97
|
agents/voice/models/openai_tts.py,sha256=4KoLQuFDHKu5a1VTJlu9Nj3MHwMlrn9wfT_liJDJ2dw,1477
|
|
98
|
-
openai_agents-0.2.
|
|
99
|
-
openai_agents-0.2.
|
|
100
|
-
openai_agents-0.2.
|
|
101
|
-
openai_agents-0.2.
|
|
98
|
+
openai_agents-0.2.3.dist-info/METADATA,sha256=XtY_daBoaLEGJdzn0ZX53F2vL78SYYTQTsTfZLgzOIM,11567
|
|
99
|
+
openai_agents-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
100
|
+
openai_agents-0.2.3.dist-info/licenses/LICENSE,sha256=E994EspT7Krhy0qGiES7WYNzBHrh1YDk3r--8d1baRU,1063
|
|
101
|
+
openai_agents-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|