Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,57 @@ export async function GET(
spanIdToParentSpanId.set(spanAttr.spanId, parentSpanId);
}

// Build map from spanId to context breakdown (from agent.generate spans)
type ContextBreakdownData = {
systemPromptTemplate: number;
coreInstructions: number;
agentPrompt: number;
toolsSection: number;
artifactsSection: number;
dataComponents: number;
artifactComponents: number;
transferInstructions: number;
delegationInstructions: number;
thinkingPreparation: number;
conversationHistory: number;
total: number;
};
const spanIdToContextBreakdown = new Map<string, ContextBreakdownData>();
for (const spanAttr of allSpanAttributes) {
const data = spanAttr.data;
if (data['context.breakdown.total_tokens'] !== undefined) {
spanIdToContextBreakdown.set(spanAttr.spanId, {
systemPromptTemplate: Number(data['context.breakdown.system_template_tokens']) || 0,
coreInstructions: Number(data['context.breakdown.core_instructions_tokens']) || 0,
agentPrompt: Number(data['context.breakdown.agent_prompt_tokens']) || 0,
toolsSection: Number(data['context.breakdown.tools_tokens']) || 0,
artifactsSection: Number(data['context.breakdown.artifacts_tokens']) || 0,
dataComponents: Number(data['context.breakdown.data_components_tokens']) || 0,
artifactComponents: Number(data['context.breakdown.artifact_components_tokens']) || 0,
transferInstructions: Number(data['context.breakdown.transfer_instructions_tokens']) || 0,
delegationInstructions:
Number(data['context.breakdown.delegation_instructions_tokens']) || 0,
thinkingPreparation: Number(data['context.breakdown.thinking_preparation_tokens']) || 0,
conversationHistory: Number(data['context.breakdown.conversation_history_tokens']) || 0,
total: Number(data['context.breakdown.total_tokens']) || 0,
});
}
}

// Helper to get context breakdown for a span (check self and parent)
const getContextBreakdownForSpan = (spanId: string): ContextBreakdownData | undefined => {
// Check if this span has context breakdown
if (spanIdToContextBreakdown.has(spanId)) {
return spanIdToContextBreakdown.get(spanId);
}
// Check parent span
const parentId = spanIdToParentSpanId.get(spanId);
if (parentId && spanIdToContextBreakdown.has(parentId)) {
return spanIdToContextBreakdown.get(parentId);
}
return undefined;
};

// activities
type Activity = {
id: string;
Expand Down Expand Up @@ -1419,12 +1470,13 @@ export async function GET(
const hasError = getField(span, SPAN_KEYS.HAS_ERROR) === true;
const durMs = getNumber(span, SPAN_KEYS.DURATION_NANO) / 1e6;
const aiStreamingText = getString(span, SPAN_KEYS.SPAN_ID, '');
const parentSpanId = spanIdToParentSpanId.get(aiStreamingText) || undefined;
activities.push({
id: aiStreamingText,
type: ACTIVITY_TYPES.AI_MODEL_STREAMED_TEXT,
description: 'AI model streaming text response',
timestamp: span.timestamp,
parentSpanId: spanIdToParentSpanId.get(aiStreamingText) || undefined,
parentSpanId,
status: hasError ? ACTIVITY_STATUS.ERROR : ACTIVITY_STATUS.SUCCESS,
subAgentId: getString(
span,
Expand All @@ -1445,6 +1497,7 @@ export async function GET(
inputTokens: getNumber(span, SPAN_KEYS.GEN_AI_USAGE_INPUT_TOKENS, 0),
outputTokens: getNumber(span, SPAN_KEYS.GEN_AI_USAGE_OUTPUT_TOKENS, 0),
aiTelemetryFunctionId: getString(span, SPAN_KEYS.AI_TELEMETRY_FUNCTION_ID, '') || undefined,
contextBreakdown: parentSpanId ? getContextBreakdownForSpan(parentSpanId) : undefined,
});
}

Expand Down
2 changes: 2 additions & 0 deletions agents-manage-ui/src/components/traces/timeline/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export interface ActivityItem {
// Tool approval fields
approvalToolName?: string;
approvalToolCallId?: string;
// Context breakdown for AI generation spans
contextBreakdown?: ContextBreakdown;
}

export interface ToolCall {
Expand Down
1 change: 0 additions & 1 deletion agents-manage-ui/src/lib/actions/copilot-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export async function getCopilotTokenAction(): Promise<ActionResult<CopilotToken
// Read cookies and format as a cookie header string
const cookieStore = await cookies();
const allCookies = cookieStore.getAll();
console.log('allCookies', allCookies);
const cookieHeader = allCookies.map((c) => `${c.name}=${c.value}`).join('; ');

return {
Expand Down
Loading