Skip to content

Capture context_management In Anthropic Messages Tracer - #227

Merged
Abhijeet Prasad (AbhiPrasad) merged 11 commits into
braintrustdata:mainfrom
atharvamhaske:fix/anthropic-context-management
Sep 14, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 11 commits into
braintrustdata:mainfrom
atharvamhaske:fix/anthropic-context-management

Conversation

@atharvamhaske

Copy link
Copy Markdown
Contributor

Summary

The Anthropic Messages tracer does not capture context_management. This field controls Claude's server-side context editing. It clears oldtool-use results or thinking blocks as a conversation grows.

Changes

  • trace/contrib/anthropic/messages.go: add context_management to the request metadata fields. Add the response-side applied_edits field, nested under the same context_management key.
  • trace/contrib/anthropic/traceanthropic_test.go: add a test for both the request config and the response applied_edits.
  • examples/internal/anthropic/main.go: add a context management example.

Closes #222

Screenshot

Screenshot 2026-09-10 at 11 06 40 PM

Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>
Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>
Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7186e2f5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread trace/contrib/anthropic/messages.go Outdated
@atharvamhaske

Copy link
Copy Markdown
Contributor Author

note: i haven't tried on braintrust dashboard as i dont have anthropic api key to test, you can test it !

… responses

Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>
@atharvamhaske

Atharva Mhaske (atharvamhaske) commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

fixed above suggestion by bot, ClaudeStreamAccumulator now has a contextManagement field. Its Add method saves **context_management** from the message_start event into this field. a new ContextManagement() method returns this saved value. In parseStreamingResponse, the code reads applied_edits from this value and adds it to the span metadata, under the same context_management key that holds the request-side config.

this matches the pattern already used for non-streaming responses, so both paths now report applied edits the same way.

cc: Abhijeet Prasad (@AbhiPrasad) re run ci jobs, once you get time :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's delete the mocks/fakes tests we have in favor of adding a vcr test. Once we have the vcr test, I can record the cassette with my api key

@atharvamhaske

Copy link
Copy Markdown
Contributor Author

Let's delete the mocks/fakes tests we have in favor of adding a vcr test. Once we have the vcr test, I can record the cassette with my api key

sure on it

Signed-off-by: atharvamhaske <atharvamhaske76@gmail.com>
@atharvamhaske

Copy link
Copy Markdown
Contributor Author

reverted all fake tests in latest commit, ci is green
cc: Abhijeet Prasad (@AbhiPrasad)

@atharvamhaske

Copy link
Copy Markdown
Contributor Author

Abhijeet Prasad (@AbhiPrasad) PTAL

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T16:58:23.693368Z c67cbe0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@AbhiPrasad

Copy link
Copy Markdown
Member

push up the cassette and made some fixes + cleanup

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c67cbe0459

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 5d9babc into braintrustdata:main Sep 14, 2026
8 checks passed
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.

[bot] Anthropic Messages tracer does not capture context_management (context editing / memory tool)

2 participants