Skip to content

Commit 795caa3

Browse files
committed
Merge branch 'main' of https://github.com/openai/openai-agents-python into fix/parallel_tool_calls
2 parents 1f0915a + cfe9099 commit 795caa3

File tree

16 files changed

+176
-30
lines changed

16 files changed

+176
-30
lines changed

docs/ja/tracing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ async def main():
119119
- [Comet Opik](https://www.comet.com/docs/opik/tracing/integrations/openai_agents)
120120
- [Langfuse](https://langfuse.com/docs/integrations/openaiagentssdk/openai-agents)
121121
- [Langtrace](https://docs.langtrace.ai/supported-integrations/llm-frameworks/openai-agents-sdk)
122-
- [Okahu‑Monocle](https://github.com/monocle2ai/monocle)
122+
- [Okahu‑Monocle](https://github.com/monocle2ai/monocle)
123+
- [Portkey AI](https://portkey.ai/docs/integrations/agents/openai-agents)

docs/mcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Agents SDK has support for MCP. This enables you to use a wide range of MCP
88

99
## MCP servers
1010

11-
Currently, the MCP spec defines two kinds of servers, based on the transport mechanism they use:
11+
Currently, the MCP spec defines three kinds of servers, based on the transport mechanism they use:
1212

1313
1. **stdio** servers run as a subprocess of your application. You can think of them as running "locally".
1414
2. **HTTP over SSE** servers run remotely. You connect to them via a URL.

docs/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ The `agent.as_tool` function is a convenience method to make it easy to turn an
270270
```python
271271
@function_tool
272272
async def run_my_agent() -> str:
273-
"""A tool that runs the agent with custom configs".
273+
"""A tool that runs the agent with custom configs"""
274274

275275
agent = Agent(name="My agent", instructions="...")
276276

docs/tracing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ To customize this default setup, to send traces to alternative or additional bac
116116
- [Langtrace](https://docs.langtrace.ai/supported-integrations/llm-frameworks/openai-agents-sdk)
117117
- [Okahu-Monocle](https://github.com/monocle2ai/monocle)
118118
- [Galileo](https://v2docs.galileo.ai/integrations/openai-agent-integration#openai-agent-integration)
119+
- [Portkey AI](https://portkey.ai/docs/integrations/agents/openai-agents)

examples/agent_patterns/input_guardrails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Guardrails are checks that run in parallel to the agent's execution.
2121
They can be used to do things like:
2222
- Check if input messages are off-topic
23-
- Check that output messages don't violate any policies
23+
- Check that input messages don't violate any policies
2424
- Take over control of the agent's execution if an unexpected input is detected
2525
2626
In this example, we'll setup an input guardrail that trips if the user is asking to do math homework.

src/agents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
MaxTurnsExceeded,
1515
ModelBehaviorError,
1616
OutputGuardrailTripwireTriggered,
17+
RunErrorDetails,
1718
UserError,
1819
)
1920
from .guardrail import (
@@ -204,6 +205,7 @@ def enable_verbose_stdout_logging():
204205
"AgentHooks",
205206
"RunContextWrapper",
206207
"TContext",
208+
"RunErrorDetails",
207209
"RunResult",
208210
"RunResultStreaming",
209211
"RunConfig",

src/agents/agent_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def json_schema(self) -> dict[str, Any]:
3838
@abc.abstractmethod
3939
def is_strict_json_schema(self) -> bool:
4040
"""Whether the JSON schema is in strict mode. Strict mode constrains the JSON schema
41-
features, but guarantees valis JSON. See here for details:
41+
features, but guarantees valid JSON. See here for details:
4242
https://platform.openai.com/docs/guides/structured-outputs#supported-schemas
4343
"""
4444
pass

src/agents/exceptions.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1-
from typing import TYPE_CHECKING
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
from typing import TYPE_CHECKING, Any
25

36
if TYPE_CHECKING:
7+
from .agent import Agent
48
from .guardrail import InputGuardrailResult, OutputGuardrailResult
9+
from .items import ModelResponse, RunItem, TResponseInputItem
10+
from .run_context import RunContextWrapper
11+
12+
from .util._pretty_print import pretty_print_run_error_details
13+
14+
15+
@dataclass
16+
class RunErrorDetails:
17+
"""Data collected from an agent run when an exception occurs."""
18+
input: str | list[TResponseInputItem]
19+
new_items: list[RunItem]
20+
raw_responses: list[ModelResponse]
21+
last_agent: Agent[Any]
22+
context_wrapper: RunContextWrapper[Any]
23+
input_guardrail_results: list[InputGuardrailResult]
24+
output_guardrail_results: list[OutputGuardrailResult]
25+
26+
def __str__(self) -> str:
27+
return pretty_print_run_error_details(self)
528

629

730
class AgentsException(Exception):
831
"""Base class for all exceptions in the Agents SDK."""
32+
run_data: RunErrorDetails | None
33+
34+
def __init__(self, *args: object) -> None:
35+
super().__init__(*args)
36+
self.run_data = None
937

1038

1139
class MaxTurnsExceeded(AgentsException):
@@ -15,6 +43,7 @@ class MaxTurnsExceeded(AgentsException):
1543

1644
def __init__(self, message: str):
1745
self.message = message
46+
super().__init__(message)
1847

1948

2049
class ModelBehaviorError(AgentsException):
@@ -26,6 +55,7 @@ class ModelBehaviorError(AgentsException):
2655

2756
def __init__(self, message: str):
2857
self.message = message
58+
super().__init__(message)
2959

3060

3161
class UserError(AgentsException):
@@ -35,15 +65,16 @@ class UserError(AgentsException):
3565

3666
def __init__(self, message: str):
3767
self.message = message
68+
super().__init__(message)
3869

3970

4071
class InputGuardrailTripwireTriggered(AgentsException):
4172
"""Exception raised when a guardrail tripwire is triggered."""
4273

43-
guardrail_result: "InputGuardrailResult"
74+
guardrail_result: InputGuardrailResult
4475
"""The result data of the guardrail that was triggered."""
4576

46-
def __init__(self, guardrail_result: "InputGuardrailResult"):
77+
def __init__(self, guardrail_result: InputGuardrailResult):
4778
self.guardrail_result = guardrail_result
4879
super().__init__(
4980
f"Guardrail {guardrail_result.guardrail.__class__.__name__} triggered tripwire"
@@ -53,10 +84,10 @@ def __init__(self, guardrail_result: "InputGuardrailResult"):
5384
class OutputGuardrailTripwireTriggered(AgentsException):
5485
"""Exception raised when a guardrail tripwire is triggered."""
5586

56-
guardrail_result: "OutputGuardrailResult"
87+
guardrail_result: OutputGuardrailResult
5788
"""The result data of the guardrail that was triggered."""
5889

59-
def __init__(self, guardrail_result: "OutputGuardrailResult"):
90+
def __init__(self, guardrail_result: OutputGuardrailResult):
6091
self.guardrail_result = guardrail_result
6192
super().__init__(
6293
f"Guardrail {guardrail_result.guardrail.__class__.__name__} triggered tripwire"

src/agents/extensions/models/litellm_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections.abc import AsyncIterator
66
from typing import Any, Literal, cast, overload
77

8-
import litellm.types
98
from openai.types.responses.response_usage import InputTokensDetails, OutputTokensDetails
109

1110
from agents.exceptions import ModelBehaviorError

src/agents/handoffs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def handoff(
168168
input_filter: a function that filters the inputs that are passed to the next agent.
169169
"""
170170
assert (on_handoff and input_type) or not (on_handoff and input_type), (
171-
"You must provide either both on_input and input_type, or neither"
171+
"You must provide either both on_handoff and input_type, or neither"
172172
)
173173
type_adapter: TypeAdapter[Any] | None
174174
if input_type is not None:

0 commit comments

Comments
 (0)