Skip to content

feat(agent-tracing): collect assistant messages into root run outputs#421

Merged
jerryliang64 merged 1 commit intomasterfrom
feat/claude-tracer-output-messages
Mar 29, 2026
Merged

feat(agent-tracing): collect assistant messages into root run outputs#421
jerryliang64 merged 1 commit intomasterfrom
feat/claude-tracer-output-messages

Conversation

@jerryliang64
Copy link
Copy Markdown
Contributor

@jerryliang64 jerryliang64 commented Mar 29, 2026

Summary

  • Automatically collect assistant text responses during message processing into outputs.messages
  • Aligns with LangGraph convention where root run outputs contains business data (messages)

Changes

  • core/agent-tracing/src/ClaudeAgentTracer.ts
    • Add outputMessages array to Trace class to accumulate assistant text
    • Collect text from assistant messages in handleAssistant
    • Include messages in root run outputs in handleResult
  • core/agent-tracing/test/ClaudeAgentTracer.test.ts
    • New test: multi-turn assistant text collected into outputs.messages
    • New test: empty messages array when no assistant text

Root Run outputs (before → after)

 outputs: {
+  messages: [{ role: 'assistant', content: '...' }, ...],
   result: '...',
   is_error: false,
   num_turns: 1,
   llmOutput: { promptTokens, completionTokens, ... },
 }

Test plan

  • All 58 tests pass (56 existing + 2 new)
  • Verified locally in chair-sandbox-ai-use project

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Assistant text content is now collected per trace and exposed in trace outputs as a messages array.
    • Mixed content blocks (text and tool-use) are preserved in the recorded messages.
  • Tests

    • Added tests verifying message collection for multi-part assistant outputs and the empty messages case when no assistant text appears.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5b68feb-8cd5-4083-bcfc-909ade4a0223

📥 Commits

Reviewing files that changed from the base of the PR and between 78685ea and b5df79a.

📒 Files selected for processing (2)
  • core/agent-tracing/src/ClaudeAgentTracer.ts
  • core/agent-tracing/test/ClaudeAgentTracer.test.ts
✅ Files skipped from review due to trivial changes (1)
  • core/agent-tracing/test/ClaudeAgentTracer.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/agent-tracing/src/ClaudeAgentTracer.ts

📝 Walkthrough

Walkthrough

Collect assistant content blocks per-trace by adding an outputMessages array to Trace. On assistant messages with content blocks, append { role: 'assistant', content }. On final result, attach messages: this.outputMessages to the root run's outputs while preserving existing fields and behavior.

Changes

Cohort / File(s) Summary
Core Implementation
core/agent-tracing/src/ClaudeAgentTracer.ts
Added outputMessages to Trace; append assistant content blocks as { role: 'assistant', content } on assistant messages; include outputs.messages with collected entries on root run result.
Test Suite
core/agent-tracing/test/ClaudeAgentTracer.test.ts
Added tests under Trace outputs.messages in root run validating collected assistant message entries (mixed content and text-only) and empty-array behavior when no assistant content exists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • akitaSummer

Poem

"I hop through traces, soft and light,
Gathering assistant words in sight,
Little blocks tucked in a row,
Saved for the root when runs must close,
A happy rabbit with logs aglow." 🐇✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: collecting assistant messages into root run outputs, which aligns with the core functionality added to ClaudeAgentTracer.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/claude-tracer-output-messages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the collection of assistant text messages into the outputs.messages field of the root run within the ClaudeAgentTracer. This is achieved by tracking text content during message processing and updating the root run's outputs upon completion. Corresponding tests were added to ensure correct message aggregation. Feedback suggests improving type safety by narrowing the role property to a literal type and using type guards instead of type assertions when filtering content.

Automatically collect complete assistant messages (text + tool_use)
during message processing and include them as outputs.messages in the
root run, aligning with LangGraph convention where outputs contain
business data (messages).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jerryliang64 jerryliang64 force-pushed the feat/claude-tracer-output-messages branch from 78685ea to b5df79a Compare March 29, 2026 04:51
@jerryliang64 jerryliang64 merged commit 8dcebaf into master Mar 29, 2026
12 checks passed
@jerryliang64 jerryliang64 deleted the feat/claude-tracer-output-messages branch March 29, 2026 05:17
This was referenced Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant