Skip to content

Commit 1bc92ae

Browse files
authored
Record exception with traceback for non-fatal function tool errors in OpenAI agents SDK (#924)
1 parent d5243c3 commit 1bc92ae

File tree

3 files changed

+686
-2
lines changed

3 files changed

+686
-2
lines changed

logfire/_internal/integrations/openai_agents.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ def parent_id(self) -> str | None:
278278
return self.wrapped.parent_id
279279

280280
def set_error(self, error: SpanError) -> None:
281+
_typ, exc, _tb = sys.exc_info()
282+
if (
283+
exc
284+
and error['message'] == 'Error running tool (non-fatal)'
285+
and (error['data'] or {}).get('error') == str(exc)
286+
):
287+
self.span_helper.span.record_exception(exc)
281288
return self.wrapped.set_error(error)
282289

283290
@property
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
interactions:
2+
- request:
3+
body: '{"input":[{"content":"Call the tool.","role":"user"}],"model":"gpt-4o","include":[],"stream":false,"tools":[{"name":"tool","parameters":{"properties":{},"title":"tool_args","type":"object","additionalProperties":false,"required":[]},"strict":true,"type":"function","description":""}]}'
4+
headers:
5+
accept:
6+
- application/json
7+
accept-encoding:
8+
- gzip, deflate
9+
connection:
10+
- keep-alive
11+
content-length:
12+
- '284'
13+
content-type:
14+
- application/json
15+
host:
16+
- api.openai.com
17+
user-agent:
18+
- Agents/Python 0.0.0
19+
x-stainless-arch:
20+
- arm64
21+
x-stainless-async:
22+
- async:asyncio
23+
x-stainless-lang:
24+
- python
25+
x-stainless-os:
26+
- MacOS
27+
x-stainless-package-version:
28+
- 1.66.2
29+
x-stainless-read-timeout:
30+
- '600'
31+
x-stainless-retry-count:
32+
- '0'
33+
x-stainless-runtime:
34+
- CPython
35+
x-stainless-runtime-version:
36+
- 3.12.6
37+
method: POST
38+
uri: https://api.openai.com/v1/responses
39+
response:
40+
body:
41+
string: !!binary |
42+
H4sIAAAAAAAAA4RUTW/bMAy951cIOjeD/FHHyXXAhg0buutQFIYs0ak22fIkamgX5L8Pkp1YyVLs
43+
Yth85CP5SPqwIoQqSXeEWnBjU21ktimLe2iFqLNt1lZ1wZjMK5HnLeu2LN8UXc2rohJ13t7X9C4Q
44+
mPYHCDyRmMHBZBcWOIJseMCyTZltasbyLGIOOXoXYoTpRw0IcgoCa42lOzJ4raNBDSePRgJypd0l
45+
6tB6gcoMF/aevzTG4+ixQfMTrkAjQYfc+xHXpVnnLC/XrF6zam4oBtIdeVwRQsghPgmh+DpCCOv8
46+
EDM2gmsdQyI8CdmJk4xVXbRlkHGbi7xjZb3pirrjeX1TxkgRCJuJJ74+jJ+L/D3bfvzUf/jz8v0L
47+
sOyreniQS8TA+1gTGpOUwu3e9zBgVPhwXIBbukfsuCLkKXY/csu1Bt0Eythi8EfrYYIt/FbGu+Y0
48+
7Knes7gWuDODGvZ0NytHoeuMxcSJELqHASxHaJzve25fZ3RFyHFeEGMhzYvQjyHCR3P2js3WF1wS
49+
dcb2fPlORhb9zo1OKab+no0S0YV7NPQMuP+Pf1FVghNWjdGYdvnmfILGPSBYlxQbxTUjWFQQ7ce7
50+
BUGF+kzUcLt3NEXn0uZTTBAupQp1cf0t5e64dpC4WfjllYUwycen2XxMtsaqeOFhGlfrgmZsxnQi
51+
1g+Cz1JQqRxv9em4veN7WMalhov7zMvy7l8gufrDcibiGeQSyVZJvfT67jN2C7jFe97dt6jRINdJ
52+
xffleZu8g4v/Vg/IJUceB7k6/gUAAP//AwBekvd4awUAAA==
53+
headers:
54+
CF-RAY:
55+
- 91f30df01de206f7-CPT
56+
Connection:
57+
- keep-alive
58+
Content-Encoding:
59+
- gzip
60+
Content-Type:
61+
- application/json
62+
Date:
63+
- Wed, 12 Mar 2025 11:47:02 GMT
64+
Server:
65+
- cloudflare
66+
Set-Cookie:
67+
- __cf_bm=Jn3kp4EX3JBP5nvxhCTprAM0RupZabPoS_sh_Sq9WRQ-1741780022-1.0.1.1-tfg_nyk8ABfo3N_FBTuFrN09KQzkVJZJv3efNnpk0D41ksWpxSe8vt2VRIu0jmk6NetZFUb49VsIw0cvyeZ5vt3ma3ua7S2O8SsCh5Sq4Hg;
68+
path=/; expires=Wed, 12-Mar-25 12:17:02 GMT; domain=.api.openai.com; HttpOnly;
69+
Secure; SameSite=None
70+
- _cfuvid=nulMZnkzn2UrOit.K3dVhNxR4TdJU9Qibj7o6_6aBQE-1741780022694-0.0.1.1-604800000;
71+
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
72+
Transfer-Encoding:
73+
- chunked
74+
X-Content-Type-Options:
75+
- nosniff
76+
alt-svc:
77+
- h3=":443"; ma=86400
78+
cf-cache-status:
79+
- DYNAMIC
80+
openai-organization:
81+
- pydantic-28gund
82+
openai-processing-ms:
83+
- '692'
84+
openai-version:
85+
- '2020-10-01'
86+
strict-transport-security:
87+
- max-age=31536000; includeSubDomains; preload
88+
x-request-id:
89+
- req_b17475e90634232c7842507048efe083
90+
status:
91+
code: 200
92+
message: OK
93+
- request:
94+
body: '{"input":[{"content":"Call the tool.","role":"user"},{"id":"fc_67d1743683b4819192c2f0487f38fa280273f8a636c82b58","arguments":"{}","call_id":"call_OpJ32C09GImFzxYLe01MiOOd","name":"tool","type":"function_call","status":"completed"},{"call_id":"call_OpJ32C09GImFzxYLe01MiOOd","output":"An
95+
error occurred while running the tool. Please try again. Error: Ouch, don''t
96+
do that again!","type":"function_call_output"}],"model":"gpt-4o","include":[],"stream":false,"tools":[{"name":"tool","parameters":{"properties":{},"title":"tool_args","type":"object","additionalProperties":false,"required":[]},"strict":true,"type":"function","description":""}]}'
97+
headers:
98+
accept:
99+
- application/json
100+
accept-encoding:
101+
- gzip, deflate
102+
connection:
103+
- keep-alive
104+
content-length:
105+
- '641'
106+
content-type:
107+
- application/json
108+
host:
109+
- api.openai.com
110+
user-agent:
111+
- Agents/Python 0.0.0
112+
x-stainless-arch:
113+
- arm64
114+
x-stainless-async:
115+
- async:asyncio
116+
x-stainless-lang:
117+
- python
118+
x-stainless-os:
119+
- MacOS
120+
x-stainless-package-version:
121+
- 1.66.2
122+
x-stainless-read-timeout:
123+
- '600'
124+
x-stainless-retry-count:
125+
- '0'
126+
x-stainless-runtime:
127+
- CPython
128+
x-stainless-runtime-version:
129+
- 3.12.6
130+
method: POST
131+
uri: https://api.openai.com/v1/responses
132+
response:
133+
body:
134+
string: !!binary |
135+
H4sIAAAAAAAAA3RUy3LbMAy8+ytQnpOOHo4t+w9y6z2T0cAUZLOhSJWE6ngy/vcOqYfpNLl4LCwA
136+
grtLfKwAhGrEHoQj39ebbZNv1+WGit26ynf5DotDU2x2T3mFFZaUFduyrXBTbmRVHJ4q8RAa2MNv
137+
kjw3scbTGJeOkKmpMWD5dp1vqywrioh5Rh58qJG26zUxNWMROWed2IMZtI4BZeaMuiFGpf096tkN
138+
kpU1d/EO32s7cD9wzfaNPoG2IR3OPvb8uLaPRVasH7PqMdtMF4qFYg8vKwCAj/gLIPjSUyjryHs8
139+
jreMwEhh548zg9uSChkYrGR12BW0xnJXVrncfslg7PEdIxF0VseT0XvlGQ3fIGkNk7lNm058N/VM
140+
B73fqseEENmDeGbwRJ0HPpEjOKMHNBAFgfOJDLC7KHMEtiBR65AGbK3+Cc8tXOwAhqiBE+kezopP
141+
4G1HfAoVviepWiUfoCXS0DoKlaCJoSN4M/b8434kNMYyzqq+vC7Ydfo3RsLXa5SsR4dak67DQHUY
142+
LxSyG2iEHf1VdvD17NA6SrY4whF6a5Q5iv1EnqC2tY6TJABxJEMOmWo/dB26y4SuAK6Tq62j9Fym
143+
rg8VQwznP7MpGgmfDmqt6/D2nSgW85aLjkeM9ztZJUdDDGzFAvjvPdsOJr6Sm3Ea8tKpPgbTWwII
144+
g904gLX6VhA47ojJ+WTYSK7tybGiGL/ehBSsWC+NanRHL1J0Nua4PxIEm0aFuVD/Snu3qD0laY7+
145+
DMpRk1rkmjwop+JaCmp8sgvbvu5TRdxgJE5UiEZ5POh5Iw3xrS9yKXO3VIqqfPgfSFbVooREeaLm
146+
VpmtknnF52VVZl8BX/VdvPtda7aMOumcl4ubBk93y7YjxgYZo5Cr6z8AAAD//wMAAmVw3iAGAAA=
147+
headers:
148+
CF-RAY:
149+
- 91f30df61c5d06f7-CPT
150+
Connection:
151+
- keep-alive
152+
Content-Encoding:
153+
- gzip
154+
Content-Type:
155+
- application/json
156+
Date:
157+
- Wed, 12 Mar 2025 11:47:03 GMT
158+
Server:
159+
- cloudflare
160+
Transfer-Encoding:
161+
- chunked
162+
X-Content-Type-Options:
163+
- nosniff
164+
alt-svc:
165+
- h3=":443"; ma=86400
166+
cf-cache-status:
167+
- DYNAMIC
168+
openai-organization:
169+
- pydantic-28gund
170+
openai-processing-ms:
171+
- '912'
172+
openai-version:
173+
- '2020-10-01'
174+
strict-transport-security:
175+
- max-age=31536000; includeSubDomains; preload
176+
x-request-id:
177+
- req_2868c5642b6b6c2148eba3ac2a8f349c
178+
status:
179+
code: 200
180+
message: OK
181+
version: 1

0 commit comments

Comments
 (0)