Skip to content

Commit a25ab9f

Browse files
Merge pull request #184 from scaleapi/dm/add-better-tracing
Wrap try catch block to avoid failing API
2 parents 622b0c0 + 10e1660 commit a25ab9f

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/agentex/lib/adk/providers/_modules/sync_provider.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,22 @@ async def get_response(
164164
output_items = response_output if isinstance(response_output, list) else [response_output]
165165

166166
for item in output_items:
167-
item_dict = _serialize_item(item)
168-
if item_dict:
169-
new_items.append(item_dict)
170-
171-
# Extract final_output from message type if available
172-
if item_dict.get('type') == 'message' and not final_output:
173-
content = item_dict.get('content', [])
174-
if content and isinstance(content, list):
175-
for content_part in content:
176-
if isinstance(content_part, dict) and 'text' in content_part:
177-
final_output = content_part['text']
178-
break
167+
try:
168+
item_dict = _serialize_item(item)
169+
if item_dict:
170+
new_items.append(item_dict)
171+
172+
# Extract final_output from message type if available
173+
if item_dict.get('type') == 'message' and not final_output:
174+
content = item_dict.get('content', [])
175+
if content and isinstance(content, list):
176+
for content_part in content:
177+
if isinstance(content_part, dict) and 'text' in content_part:
178+
final_output = content_part['text']
179+
break
180+
except Exception as e:
181+
logger.warning(f"Failed to serialize item in get_response: {e}")
182+
continue
179183

180184
span.output = {
181185
"new_items": new_items,
@@ -275,18 +279,22 @@ async def stream_response(
275279
if event_type == 'response.output_item.done':
276280
item = getattr(event, 'item', None)
277281
if item is not None:
278-
item_dict = _serialize_item(item)
279-
if item_dict:
280-
new_items.append(item_dict)
281-
282-
# Update final_response_text from message type if available
283-
if item_dict.get('type') == 'message':
284-
content = item_dict.get('content', [])
285-
if content and isinstance(content, list):
286-
for content_part in content:
287-
if isinstance(content_part, dict) and 'text' in content_part:
288-
final_response_text = content_part['text']
289-
break
282+
try:
283+
item_dict = _serialize_item(item)
284+
if item_dict:
285+
new_items.append(item_dict)
286+
287+
# Update final_response_text from message type if available
288+
if item_dict.get('type') == 'message':
289+
content = item_dict.get('content', [])
290+
if content and isinstance(content, list):
291+
for content_part in content:
292+
if isinstance(content_part, dict) and 'text' in content_part:
293+
final_response_text = content_part['text']
294+
break
295+
except Exception as e:
296+
logger.warning(f"Failed to serialize item in stream_response: {e}")
297+
continue
290298

291299
yield event
292300

0 commit comments

Comments
 (0)