Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions internal/llminternal/base_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (f *Flow) handleFunctionCalls(ctx agent.InvocationContext, toolsDict map[st
ev.Author = ctx.Agent().Name()
ev.Branch = ctx.Branch()
ev.Actions = *toolCtx.Actions()
telemetry.TraceToolCall(spans, curTool, fnCall.Args, ev)
telemetry.TraceToolCall(spans, ctx, curTool, fnCall.Args, ev)
fnResponseEvents = append(fnResponseEvents, ev)
}
mergedEvent, err := mergeParallelFunctionResponseEvents(fnResponseEvents)
Expand All @@ -415,7 +415,7 @@ func (f *Flow) handleFunctionCalls(ctx agent.InvocationContext, toolsDict map[st
}
// this is needed for debug traces of parallel calls
spans := telemetry.StartTrace(ctx, "execute_tool (merged)")
telemetry.TraceMergedToolCalls(spans, mergedEvent)
telemetry.TraceMergedToolCalls(spans, ctx, mergedEvent)
return mergedEvent, nil
}

Expand Down
8 changes: 6 additions & 2 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
genAiToolCallID = "gen_ai.tool.call.id"
genAiSystemName = "gen_ai.system"
genAiRequestModelName = "gen_ai.request.model"
genAiConversationID = "gen_ai.conversation.id"

gcpVertexAgentLLMRequestName = "gcp.vertex.agent.llm_request"
gcpVertexAgentToolCallArgsName = "gcp.vertex.agent.tool_call_args"
Expand Down Expand Up @@ -118,12 +119,13 @@ func StartTrace(ctx context.Context, traceName string) []trace.Span {
}

// TraceMergedToolCalls traces the tool execution events.
func TraceMergedToolCalls(spans []trace.Span, fnResponseEvent *session.Event) {
func TraceMergedToolCalls(spans []trace.Span, agentCtx agent.InvocationContext, fnResponseEvent *session.Event) {
if fnResponseEvent == nil {
return
}
for _, span := range spans {
attributes := []attribute.KeyValue{
attribute.String(genAiConversationID, agentCtx.Session().ID()),
attribute.String(genAiOperationName, executeToolName),
attribute.String(genAiToolName, mergeToolName),
attribute.String(genAiToolDescription, mergeToolName),
Expand All @@ -141,12 +143,13 @@ func TraceMergedToolCalls(spans []trace.Span, fnResponseEvent *session.Event) {
}

// TraceToolCall traces the tool execution events.
func TraceToolCall(spans []trace.Span, tool tool.Tool, fnArgs map[string]any, fnResponseEvent *session.Event) {
func TraceToolCall(spans []trace.Span, agentCtx agent.InvocationContext, tool tool.Tool, fnArgs map[string]any, fnResponseEvent *session.Event) {
if fnResponseEvent == nil {
return
}
for _, span := range spans {
attributes := []attribute.KeyValue{
attribute.String(genAiConversationID, agentCtx.Session().ID()),
attribute.String(genAiOperationName, executeToolName),
attribute.String(genAiToolName, tool.Name()),
attribute.String(genAiToolDescription, tool.Description()),
Expand Down Expand Up @@ -195,6 +198,7 @@ func TraceLLMCall(spans []trace.Span, agentCtx agent.InvocationContext, llmReque
attribute.String(genAiRequestModelName, llmRequest.Model),
attribute.String(gcpVertexAgentInvocationID, event.InvocationID),
attribute.String(gcpVertexAgentSessionID, agentCtx.Session().ID()),
attribute.String(genAiConversationID, agentCtx.Session().ID()),
attribute.String(gcpVertexAgentEventID, event.ID),
attribute.String(gcpVertexAgentLLMRequestName, safeSerialize(llmRequestToTrace(llmRequest))),
attribute.String(gcpVertexAgentLLMResponseName, safeSerialize(event.LLMResponse)),
Expand Down