diff --git a/internal/agentexec/modelloop/transcript.go b/internal/agentexec/modelloop/transcript.go index ec8b09e7c..3ea93618d 100644 --- a/internal/agentexec/modelloop/transcript.go +++ b/internal/agentexec/modelloop/transcript.go @@ -61,6 +61,7 @@ func (t *transcript) ModelCallFinished(_ context.Context, req chat.Request, resp } if resp != nil { entry.Text = clip(resp.Content, &entry.TextBytes) + entry.Reasoning = clip(reasoning(resp.Parts), &entry.ReasoningBytes) entry.FinishReason = resp.FinishReason for _, call := range resp.ToolCalls { recorded := agentrun.TranscriptToolCall{ID: call.ID, Name: call.Name} @@ -130,6 +131,16 @@ func (t *transcript) AfterToolExecute(_ context.Context, call core.ToolCall, res t.add(entry) } +func reasoning(parts chat.Parts) string { + var texts []string + for _, part := range parts { + if thought, ok := part.(chat.ReasoningPart); ok && thought.Text != "" { + texts = append(texts, thought.Text) + } + } + return strings.Join(texts, "\n\n") +} + func isCompaction(req chat.Request) bool { n := len(req.Messages) return n > 0 && req.Messages[n-1].Role == chat.RoleUser && strings.HasPrefix(req.Messages[n-1].Content, compactionPrefix) diff --git a/internal/domain/agentrun/runner.go b/internal/domain/agentrun/runner.go index 3277631b9..484db1f20 100644 --- a/internal/domain/agentrun/runner.go +++ b/internal/domain/agentrun/runner.go @@ -45,7 +45,7 @@ func (r Reporter) ReportTranscript(entry TranscriptEntry) { const ( TranscriptSystem = "system" // Text: the system prompt TranscriptUser = "user" // Text: the mission, or input the loop added later - TranscriptModel = "model" // Text and ToolCalls: one model response + TranscriptModel = "model" // Reasoning, Text and ToolCalls: one model response TranscriptTool = "tool" // one tool call's arguments and result TranscriptCompaction = "compaction" // Text: the summary that replaced the history ) @@ -60,6 +60,9 @@ type TranscriptEntry struct { TextBytes int `json:"text_bytes,omitempty"` ToolCalls []TranscriptToolCall `json:"tool_calls,omitempty"` + Reasoning string `json:"reasoning,omitempty"` + ReasoningBytes int `json:"reasoning_bytes,omitempty"` + CallID string `json:"call_id,omitempty"` Tool string `json:"tool,omitempty"` Args string `json:"args,omitempty"` diff --git a/ui/src/workflows/AgentTranscript.vue b/ui/src/workflows/AgentTranscript.vue index 7f60d1926..687d0acf7 100644 --- a/ui/src/workflows/AgentTranscript.vue +++ b/ui/src/workflows/AgentTranscript.vue @@ -1,5 +1,6 @@ diff --git a/ui/src/workflows/TranscriptTool.vue b/ui/src/workflows/TranscriptTool.vue new file mode 100644 index 000000000..e0611a83d --- /dev/null +++ b/ui/src/workflows/TranscriptTool.vue @@ -0,0 +1,119 @@ + + + diff --git a/ui/src/workflows/transcript.ts b/ui/src/workflows/transcript.ts new file mode 100644 index 000000000..d49970cce --- /dev/null +++ b/ui/src/workflows/transcript.ts @@ -0,0 +1,26 @@ +/** One agent_transcript entry, as the State Store records it. */ +export interface TranscriptEntry { + seq: number; + kind: string; + text?: string; + text_bytes?: number; + reasoning?: string; + reasoning_bytes?: number; + tool_calls?: { id?: string; name: string }[]; + call_id?: string; + tool?: string; + args?: string; + args_bytes?: number; + output?: string; + output_bytes?: number; + error?: string; + finish_reason?: string; + usage?: { prompt_tokens?: number; completion_tokens?: number; cached_tokens?: number }; + latency_ms?: number; +} + +/** The text as recorded, with a note when it was clipped. */ +export function withClip(text: string | undefined, bytes: number | undefined): string { + if (!bytes) return text ?? ""; + return `${text ?? ""}\n… clipped, ${(bytes / 1024).toFixed(1)} KB in full`; +}