-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(anthropic) : implement context_management #10540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(anthropic) : implement context_management #10540
Conversation
gr2m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add an example for manual testing? e.g. examples/ai-core/src/generate-text/anthropic-context-management.ts
Also the ## Manual Verification section in your pull request templates is very important. For this particular case, I would add or alter an existing example to examples/next-openai (ignore the openai in the name, we have lots of other provider examples in there) and then test it extensively with multi-turn chats
834eb48 to
d403f29
Compare
examples/ai-core/src/generate-text/anthropic-context-management.ts
Outdated
Show resolved
Hide resolved
|
a) code style seems to be off, unclear why prettier is not running |
1d04abb to
91c8ca6
Compare
I have applied the changes to the doc and replaced the if-else logic with switch case , but i can not say about the issue regarding prettier , i ran pnpm prettier-fix on my machine , and it ran successfully. |
32753a7 to
927049f
Compare
|
@shubham-021 hey just a quick note: please don't force-push changes once we started reviewing, it will make us loose track of what we already reviewed and what changed since the last review |
|
could you help us resolving the conflict? |
Resolved conflicts in anthropic-messages-language-model.ts by: - Keeping context management variable declaration and logic - Preserving upstream URL variable and other changes - Maintaining context management parsing in doGenerate() and doStream() All tests passing.
|
@gr2m i have updated the branch , this should do now |
|
@gr2m I have resolved the conflicts again , can you please review this ? |
Background
Anthropic's now supports context management to automatically clear conversation history when approaching token limits. This prevents
model_context_window_exceedederrors and enables longer conversations by removing older tool uses or thinking blocks while preserving recent context.Summary
Added the context management feature for anthropic:
context_managementconfiguration to provider optionsclear_tool_uses_20250919andclear_thinking_20251015strategiesmodel_context_window_exceededstop reason to'length'Checklist
pnpm changesetin the project root)Related Issues
Fixes #10485