发布

  • fix(llm/anthropic): inject max_tokens into Anthropic adapter (1.0.6) (#2783)

    frostbyte_neo 发布于 2026-05-05 18:02:40 +00:00

    Summary

    • Anthropic adapter
      (cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py)
      wraps anthropic.AsyncAnthropic().messages.create via
      instructor.patch, bypassing litellm. Neither layer auto-injects
      max_tokens, which the Anthropic SDK requires — every
      cognify/search call with LLM_PROVIDER=anthropic failed with a
      misleading InstructorRetryException: Missing required arguments....
    • Fix: self.llm_args.setdefault("max_tokens", max_completion_tokens)
      in AnthropicAdapter.__init__, so the value flows through
      merged_kwargs at 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 targets main per the
    request to ship a hotfix release. A follow-up cherry-pick / merge into
    dev is 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 from max_completion_tokens when
      not provided
    • User-supplied llm_args={"max_tokens": 4096} is honored
      (setdefault, not overwrite)
    • ruff check + ruff format --check pass on the changed file
    • CI on PR: full unit + integration suite
    • End-to-end smoke: cognee.addcognee.cognify
      cognee.search with LLM_PROVIDER=anthropic,
      LLM_MODEL=claude-haiku-4-5

    🤖 Generated with Claude Code

    下载附件