Skip to content

Commit 0fbf8a7

Browse files
Merge pull request #209 from scaleapi/dm/add-tool-outputs
Add tool outputs
2 parents 8b1735d + e37cb92 commit 0fbf8a7

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/agentex/lib/core/temporal/plugins/openai_agents/models/temporal_streaming_model.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ async def get_response(
826826
# Serialize response output items for span tracing
827827
new_items = []
828828
final_output = None
829+
tool_calls = []
830+
tool_outputs = []
829831

830832
for item in response_output:
831833
try:
@@ -845,12 +847,38 @@ async def get_response(
845847
logger.warning(f"Failed to serialize item in temporal_streaming_model: {e}")
846848
continue
847849

850+
# Extract tool calls and outputs from input
851+
try:
852+
if isinstance(input, list):
853+
for item in input:
854+
try:
855+
item_dict = _serialize_item(item) if not isinstance(item, dict) else item
856+
if item_dict:
857+
# Capture function calls
858+
if item_dict.get('type') == 'function_call':
859+
tool_calls.append(item_dict)
860+
# Capture function outputs
861+
elif item_dict.get('type') == 'function_call_output':
862+
tool_outputs.append(item_dict)
863+
except Exception:
864+
pass
865+
except Exception as e:
866+
logger.warning(f"Failed to extract tool calls and outputs: {e}")
867+
848868
# Set span output with structured data
849869
if span:
850-
span.output = {
870+
output_data = {
851871
"new_items": new_items,
852872
"final_output": final_output,
853873
}
874+
# Include tool calls if any were in the input
875+
if tool_calls:
876+
output_data["tool_calls"] = tool_calls
877+
# Include tool outputs if any were processed
878+
if tool_outputs:
879+
output_data["tool_outputs"] = tool_outputs
880+
881+
span.output = output_data
854882

855883
# Return the response
856884
return ModelResponse(

0 commit comments

Comments
 (0)