-
fix(llm/anthropic): inject max_tokens into Anthropic adapter (1.0.6) (#2783)
发布于
2026-05-05 18:02:40 +00:00 Summary
- Anthropic adapter
(cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py)
wrapsanthropic.AsyncAnthropic().messages.createvia
instructor.patch, bypassing litellm. Neither layer auto-injects
max_tokens, which the Anthropic SDK requires — every
cognify/searchcall withLLM_PROVIDER=anthropicfailed with a
misleadingInstructorRetryException: Missing required arguments.... - Fix:
self.llm_args.setdefault("max_tokens", max_completion_tokens)
inAnthropicAdapter.__init__, so the value flows through
merged_kwargsat the call site and explicit user overrides are
preserved. - Version bump 1.0.5 → 1.0.6 (
pyproject.toml+uv.lock).
Note on branching
Repo convention is to branch from
dev. This PR targetsmainper the
request to ship a hotfix release. A follow-up cherry-pick / merge into
devis needed so the fix is not lost on the next dev → main merge.Test plan
- Local repro via direct adapter instantiation:
llm_args["max_tokens"]is populated frommax_completion_tokenswhen
not provided - User-supplied
llm_args={"max_tokens": 4096}is honored
(setdefault, not overwrite) ruff check+ruff format --checkpass on the changed file- CI on PR: full unit + integration suite
- End-to-end smoke:
cognee.add→cognee.cognify→
cognee.searchwithLLM_PROVIDER=anthropic,
LLM_MODEL=claude-haiku-4-5
🤖 Generated with Claude Code
下载附件
- Anthropic adapter