Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,109 @@ internal static string SerializeChatMessages(
m.Parts.Add(new OtelGenericPart { Type = "error", Content = ec.Message });
break;

// Server tool call content types as specified in the OpenTelemetry semantic conventions:
Comment thread
stephentoub marked this conversation as resolved.

case CodeInterpreterToolCallContent citcc:
m.Parts.Add(new OtelServerToolCallPart
{
Id = citcc.CallId,
Name = "code_interpreter",
ServerToolCall = new OtelGenericServerToolCall
{
Type = "code_interpreter",
Inputs = citcc.Inputs,
Comment thread
stephentoub marked this conversation as resolved.
Outdated
},
});
break;

case CodeInterpreterToolResultContent citrc:
m.Parts.Add(new OtelServerToolCallResponsePart
{
Id = citrc.CallId,
ServerToolCallResponse = new OtelGenericServerToolCallResponse
{
Type = "code_interpreter",
Output = citrc.Outputs,
},
});
break;

case ImageGenerationToolCallContent igtcc:
m.Parts.Add(new OtelServerToolCallPart
{
Id = igtcc.ImageId,
Name = "image_generation",
ServerToolCall = new OtelGenericServerToolCall
{
Type = "image_generation",
},
});
break;

case ImageGenerationToolResultContent igtrc:
m.Parts.Add(new OtelServerToolCallResponsePart
{
Id = igtrc.ImageId,
ServerToolCallResponse = new OtelGenericServerToolCallResponse
{
Type = "image_generation",
Output = igtrc.Outputs,
},
});
break;

case McpServerToolCallContent mstcc:
m.Parts.Add(new OtelServerToolCallPart
{
Id = mstcc.CallId,
Name = mstcc.ToolName,
ServerToolCall = new OtelGenericServerToolCall
{
Type = "mcp",
Arguments = mstcc.Arguments,
ServerName = mstcc.ServerName,
},
});
break;

case McpServerToolResultContent mstrc:
m.Parts.Add(new OtelServerToolCallResponsePart
{
Id = mstrc.CallId,
ServerToolCallResponse = new OtelGenericServerToolCallResponse
{
Type = "mcp",
Output = mstrc.Output,
},
});
break;

case McpServerToolApprovalRequestContent mstarc:
m.Parts.Add(new OtelServerToolCallPart
{
Id = mstarc.Id,
Name = mstarc.ToolCall.ToolName,
ServerToolCall = new OtelGenericServerToolCall
{
Type = "mcp_approval_request",
Arguments = mstarc.ToolCall.Arguments,
ServerName = mstarc.ToolCall.ServerName,
},
});
break;

case McpServerToolApprovalResponseContent mstaresp:
m.Parts.Add(new OtelServerToolCallResponsePart
{
Id = mstaresp.Id,
ServerToolCallResponse = new OtelGenericServerToolCallResponse
{
Type = "mcp_approval_response",
Approved = mstaresp.Approved,
},
});
break;

default:
JsonElement element = _emptyObject;
try
Expand Down Expand Up @@ -691,6 +794,36 @@ private sealed class OtelToolCallResponsePart
public object? Response { get; set; }
}

private sealed class OtelServerToolCallPart
{
public string Type { get; set; } = "server_tool_call";
public string? Id { get; set; }
public string? Name { get; set; }
public OtelGenericServerToolCall? ServerToolCall { get; set; }
}

private sealed class OtelServerToolCallResponsePart
{
public string Type { get; set; } = "server_tool_call_response";
public string? Id { get; set; }
public OtelGenericServerToolCallResponse? ServerToolCallResponse { get; set; }
}

private sealed class OtelGenericServerToolCall
{
public string? Type { get; set; }
public IReadOnlyDictionary<string, object?>? Arguments { get; set; }
public IList<AIContent>? Inputs { get; set; }
public string? ServerName { get; set; }
}

private sealed class OtelGenericServerToolCallResponse
{
public string? Type { get; set; }
public object? Output { get; set; }
public bool? Approved { get; set; }
Comment thread
stephentoub marked this conversation as resolved.
Outdated
}

private sealed class OtelFunction
{
public string Type { get; set; } = "function";
Expand Down Expand Up @@ -727,6 +860,10 @@ private static JsonSerializerOptions CreateDefaultOptions()
[JsonSerializable(typeof(OtelFilePart))]
[JsonSerializable(typeof(OtelToolCallRequestPart))]
[JsonSerializable(typeof(OtelToolCallResponsePart))]
[JsonSerializable(typeof(OtelServerToolCallPart))]
[JsonSerializable(typeof(OtelServerToolCallResponsePart))]
[JsonSerializable(typeof(OtelGenericServerToolCall))]
[JsonSerializable(typeof(OtelGenericServerToolCallResponse))]
[JsonSerializable(typeof(IEnumerable<OtelFunction>))]
private sealed partial class OtelContext : JsonSerializerContext;
}
Loading
Loading