Skip to content

Commit 9d2b318

Browse files
fix(deps-dev): bump ruff from 0.9.2 to 0.16.8 (#5249)
* fix(deps-dev): bump ruff from 0.9.2 to 0.16.8 Bumps [ruff](https://github.com/astral-sh/ruff) from 0.9.2 to 0.16.8. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.9.2...0.16.8) --- updated-dependencies: - dependency-name: ruff dependency-version: 0.16.8 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * fix: apply Ruff 0.16.8 formatting and lint updates * fix: exclude generated translations from Ruff formatting --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Justin Beckwith <[email protected]>
1 parent 00d4470 commit 9d2b318

44 files changed

Lines changed: 371 additions & 382 deletions

Some content is hidden

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

‎README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ from agents.sandbox.sandboxes import UnixLocalSandboxClient
8686
agent = SandboxAgent(
8787
name="Workspace Assistant",
8888
instructions="Inspect the sandbox workspace before answering.",
89-
default_manifest=Manifest(entries={"repo": GitRepo(repo="openai/openai-agents-python", ref="main")}),
89+
default_manifest=Manifest(
90+
entries={"repo": GitRepo(repo="openai/openai-agents-python", ref="main")}
91+
),
9092
)
9193

9294
result = Runner.run_sync(
@@ -105,8 +107,11 @@ Use a [`RealtimeAgent`](https://openai.github.io/openai-agents-python/realtime/q
105107
import asyncio
106108
from agents.realtime import RealtimeAgent, RealtimeRunner
107109

110+
108111
async def main() -> None:
109-
agent = RealtimeAgent(name="Assistant", instructions="You are a helpful voice assistant. Keep responses short.")
112+
agent = RealtimeAgent(
113+
name="Assistant", instructions="You are a helpful voice assistant. Keep responses short."
114+
)
110115
runner = RealtimeRunner(starting_agent=agent)
111116
session = await runner.run()
112117

@@ -121,6 +126,7 @@ async def main() -> None:
121126
elif event.type == "agent_end":
122127
break
123128

129+
124130
if __name__ == "__main__":
125131
asyncio.run(main())
126132
```

‎docs/agents.md‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ The most common properties of an agent are:
4848
from agents import Agent
4949
from agents.decorators import tool
5050

51+
5152
@tool
5253
def get_weather(city: str) -> str:
5354
"""returns weather info for the specified city."""
5455
return f"The weather in {city} is sunny"
5556

57+
5658
agent = Agent(
5759
name="Haiku agent",
5860
instructions="Always respond in haiku form",
@@ -99,6 +101,7 @@ from dataclasses import dataclass
99101

100102
from agents import Agent, GenerateDynamicPromptData, Runner
101103

104+
102105
@dataclass
103106
class PromptContext:
104107
prompt_id: str
@@ -131,10 +134,12 @@ Read the [context guide](context.md) for the full `RunContextWrapper` surface, s
131134
```python
132135
from dataclasses import dataclass
133136

137+
134138
@dataclass
135139
class Purchase:
136140
id: str
137141

142+
138143
@dataclass
139144
class UserContext:
140145
name: str
@@ -145,6 +150,7 @@ class UserContext:
145150
# implement your logic here
146151
return []
147152

153+
148154
agent = Agent[UserContext](
149155
...,
150156
)
@@ -164,6 +170,7 @@ class CalendarEvent(BaseModel):
164170
date: str
165171
participants: list[str]
166172

173+
167174
agent = Agent(
168175
name="Calendar extractor",
169176
instructions="Extract calendar events from text",
@@ -208,7 +215,7 @@ customer_facing_agent = Agent(
208215
refund_agent.as_tool(
209216
tool_name="refund_expert",
210217
tool_description="Handles refund questions and requests.",
211-
)
218+
),
212219
],
213220
)
214221
```
@@ -241,9 +248,8 @@ In most cases, you can provide instructions when you create the agent. However,
241248
```python
242249
from agents import Agent, RunContextWrapper
243250

244-
def dynamic_instructions(
245-
context: RunContextWrapper[UserContext], agent: Agent[UserContext]
246-
) -> str:
251+
252+
def dynamic_instructions(context: RunContextWrapper[UserContext], agent: Agent[UserContext]) -> str:
247253
return f"The user's name is {context.context.name}. Help them with their questions."
248254

249255

@@ -336,16 +342,18 @@ When you are using OpenAI Responses tool search, named tool choices are more lim
336342
from agents import Agent, ModelSettings
337343
from agents.decorators import tool
338344

345+
339346
@tool
340347
def get_weather(city: str) -> str:
341348
"""Returns weather info for the specified city."""
342349
return f"The weather in {city} is sunny"
343350

351+
344352
agent = Agent(
345353
name="Weather Agent",
346354
instructions="Retrieve weather details.",
347355
tools=[get_weather],
348-
model_settings=ModelSettings(tool_choice="get_weather")
356+
model_settings=ModelSettings(tool_choice="get_weather"),
349357
)
350358
```
351359

@@ -360,16 +368,18 @@ The `tool_use_behavior` parameter in the `Agent` configuration controls how tool
360368
from agents import Agent
361369
from agents.decorators import tool
362370

371+
363372
@tool
364373
def get_weather(city: str) -> str:
365374
"""Returns weather info for the specified city."""
366375
return f"The weather in {city} is sunny"
367376

377+
368378
agent = Agent(
369379
name="Weather Agent",
370380
instructions="Retrieve weather details.",
371381
tools=[get_weather],
372-
tool_use_behavior="stop_on_first_tool"
382+
tool_use_behavior="stop_on_first_tool",
373383
)
374384
```
375385

@@ -380,21 +390,24 @@ from agents import Agent
380390
from agents.agent import StopAtTools
381391
from agents.decorators import tool
382392

393+
383394
@tool
384395
def get_weather(city: str) -> str:
385396
"""Returns weather info for the specified city."""
386397
return f"The weather in {city} is sunny"
387398

399+
388400
@tool
389401
def sum_numbers(a: int, b: int) -> int:
390402
"""Adds two numbers."""
391403
return a + b
392404

405+
393406
agent = Agent(
394407
name="Stop At Stock Agent",
395408
instructions="Get weather or sum numbers.",
396409
tools=[get_weather, sum_numbers],
397-
tool_use_behavior=StopAtTools(stop_at_tool_names=["get_weather"])
410+
tool_use_behavior=StopAtTools(stop_at_tool_names=["get_weather"]),
398411
)
399412
```
400413

@@ -406,32 +419,30 @@ from agents.agent import ToolsToFinalOutputResult
406419
from agents.decorators import tool
407420
from typing import List, Any
408421

422+
409423
@tool
410424
def get_weather(city: str) -> str:
411425
"""Returns weather info for the specified city."""
412426
return f"The weather in {city} is sunny"
413427

428+
414429
def custom_tool_handler(
415-
context: RunContextWrapper[Any],
416-
tool_results: List[FunctionToolResult]
430+
context: RunContextWrapper[Any], tool_results: List[FunctionToolResult]
417431
) -> ToolsToFinalOutputResult:
418432
"""Processes tool results to decide final output."""
419433
for result in tool_results:
420434
if result.output and "sunny" in result.output:
421435
return ToolsToFinalOutputResult(
422-
is_final_output=True,
423-
final_output=f"Final weather: {result.output}"
436+
is_final_output=True, final_output=f"Final weather: {result.output}"
424437
)
425-
return ToolsToFinalOutputResult(
426-
is_final_output=False,
427-
final_output=None
428-
)
438+
return ToolsToFinalOutputResult(is_final_output=False, final_output=None)
439+
429440

430441
agent = Agent(
431442
name="Weather Agent",
432443
instructions="Retrieve weather details.",
433444
tools=[get_weather],
434-
tool_use_behavior=custom_tool_handler
445+
tool_use_behavior=custom_tool_handler,
435446
)
436447
```
437448

‎docs/config.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ You can also pass the full registration object:
121121
```python
122122
from agents import OpenAIAgentRegistrationConfig, set_default_openai_agent_registration
123123

124-
set_default_openai_agent_registration(
125-
OpenAIAgentRegistrationConfig(harness_id="your-harness-id")
126-
)
124+
set_default_openai_agent_registration(OpenAIAgentRegistrationConfig(harness_id="your-harness-id"))
127125
```
128126

129127
If no SDK default is set, providers that use the SDK's OpenAI backend fall back to the `OPENAI_AGENT_HARNESS_ID` environment variable. When a harness ID is configured, the SDK adds it to trace metadata as `agent_harness_id` unless that key is already present in `RunConfig.trace_metadata`.
@@ -147,7 +145,9 @@ from agents import (
147145
set_tracing_export_api_key,
148146
)
149147

150-
custom_client = AsyncOpenAI(base_url="https://your-openai-compatible-endpoint.example/v1", api_key="provider-key")
148+
custom_client = AsyncOpenAI(
149+
base_url="https://your-openai-compatible-endpoint.example/v1", api_key="provider-key"
150+
)
151151
set_default_openai_client(custom_client, use_for_tracing=False)
152152

153153
set_tracing_export_api_key("sk-tracing")
@@ -217,7 +217,7 @@ Alternatively, you can customize the logs by adding handlers, filters, formatter
217217
```python
218218
import logging
219219

220-
logger = logging.getLogger("openai.agents") # or openai.agents.tracing for the Tracing logger
220+
logger = logging.getLogger("openai.agents") # or openai.agents.tracing for the Tracing logger
221221

222222
# To make all logs show up
223223
logger.setLevel(logging.DEBUG)

‎docs/context.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ from dataclasses import dataclass
6161
from agents import Agent, RunContextWrapper, Runner
6262
from agents.decorators import tool
6363

64+
6465
@dataclass
6566
class UserInfo: # (1)!
6667
name: str
6768
uid: int
6869

70+
6971
@tool
7072
async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
7173
"""Fetch the age of the user. Call this function to get user's age information."""
7274
return f"The user {wrapper.context.name} is 47 years old"
7375

76+
7477
async def main():
7578
user_info = UserInfo(name="John", uid=123)
7679

@@ -88,6 +91,7 @@ async def main():
8891
print(result.final_output) # (5)!
8992
# The user John is 47 years old.
9093

94+
9195
if __name__ == "__main__":
9296
asyncio.run(main())
9397
```
@@ -112,19 +116,27 @@ from agents import Agent
112116
from agents.decorators import tool
113117
from agents.tool_context import ToolContext
114118

119+
115120
class WeatherContext(BaseModel):
116121
user_id: str
117122

123+
118124
class Weather(BaseModel):
119125
city: str = Field(description="The city name")
120126
temperature_range: str = Field(description="The temperature range in Celsius")
121127
conditions: str = Field(description="The weather conditions")
122128

129+
123130
@tool
124-
def get_weather(ctx: ToolContext[WeatherContext], city: Annotated[str, "The city to get the weather for"]) -> Weather:
125-
print(f"[debug] Tool context: (name: {ctx.tool_name}, call_id: {ctx.tool_call_id}, args: {ctx.tool_arguments})")
131+
def get_weather(
132+
ctx: ToolContext[WeatherContext], city: Annotated[str, "The city to get the weather for"]
133+
) -> Weather:
134+
print(
135+
f"[debug] Tool context: (name: {ctx.tool_name}, call_id: {ctx.tool_call_id}, args: {ctx.tool_arguments})"
136+
)
126137
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
127138

139+
128140
agent = Agent(
129141
name="Weather Agent",
130142
instructions="You are a helpful agent that can tell the weather of a given city.",

‎docs/guardrails.md‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,27 @@ from agents import (
103103
)
104104
from agents.decorators import input_guardrail
105105

106+
106107
class MathHomeworkOutput(BaseModel):
107108
is_math_homework: bool
108109
reasoning: str
109110

110-
guardrail_agent = Agent( # (1)!
111+
112+
guardrail_agent = Agent( # (1)!
111113
name="Guardrail check",
112114
instructions="Check if the user is asking you to do their math homework.",
113115
output_type=MathHomeworkOutput,
114116
)
115117

116118

117119
@input_guardrail
118-
async def math_guardrail( # (2)!
120+
async def math_guardrail( # (2)!
119121
ctx: RunContextWrapper[None], agent: Agent, input: str | list[TResponseInputItem]
120122
) -> GuardrailFunctionOutput:
121123
result = await Runner.run(guardrail_agent, input, context=ctx.context)
122124

123125
return GuardrailFunctionOutput(
124-
output_info=result.final_output, # (3)!
126+
output_info=result.final_output, # (3)!
125127
tripwire_triggered=result.final_output.is_math_homework,
126128
)
127129

@@ -132,6 +134,7 @@ agent = Agent( # (4)!
132134
input_guardrails=[math_guardrail],
133135
)
134136

137+
135138
async def main():
136139
# This should trip the guardrail
137140
try:
@@ -159,19 +162,24 @@ from agents import (
159162
Runner,
160163
)
161164
from agents.decorators import output_guardrail
162-
class MessageOutput(BaseModel): # (1)!
165+
166+
167+
class MessageOutput(BaseModel): # (1)!
163168
response: str
164169

165-
class MathOutput(BaseModel): # (2)!
170+
171+
class MathOutput(BaseModel): # (2)!
166172
reasoning: str
167173
is_math: bool
168174

175+
169176
guardrail_agent = Agent(
170177
name="Guardrail check",
171178
instructions="Check if the output includes any math.",
172179
output_type=MathOutput,
173180
)
174181

182+
175183
@output_guardrail
176184
async def math_guardrail( # (3)!
177185
ctx: RunContextWrapper, agent: Agent, output: MessageOutput
@@ -183,13 +191,15 @@ async def math_guardrail( # (3)!
183191
tripwire_triggered=result.final_output.is_math,
184192
)
185193

186-
agent = Agent( # (4)!
194+
195+
agent = Agent( # (4)!
187196
name="Customer support agent",
188197
instructions="You are a customer support agent. You help customers with their questions.",
189198
output_guardrails=[math_guardrail],
190199
output_type=MessageOutput,
191200
)
192201

202+
193203
async def main():
194204
# This should trip the guardrail
195205
try:
@@ -216,6 +226,7 @@ from agents import (
216226
)
217227
from agents.decorators import tool, tool_input_guardrail, tool_output_guardrail
218228

229+
219230
@tool_input_guardrail
220231
def block_secrets(data):
221232
args = json.loads(data.context.tool_arguments or "{}")

0 commit comments

Comments
 (0)