Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(anthropic): add prompt-caching support to the Python provider (#4722)
`AnthropicProvider` had no `cache_control` option at all, unlike the TypeScript `AnthropicProvider`'s `cacheTools` option — the docs describe tool caching as TS-specific, even though the Python `anthropic` SDK's own `ToolParam` already has a native `cache_control` field. Fixes #4720 ## Changes - Adds a `cache_tools` constructor option (default `False`) that attaches Anthropic's ephemeral `cache_control` to the tool definitions. `wrap_tools` marks only the last tool, because Anthropic allows at most 4 breakpoints per request (shared across the system prompt, tools, and messages) and a breakpoint caches everything up to and including it. `wrap_tool` on its own marks the tool it returns. The key is omitted entirely when disabled, not set to `None`. This matches the TS `cacheTools` behaviour after #4724. - The limit is per request, not per call: if you concatenate lists from several `wrap_tools` calls, each list's last tool keeps its breakpoint. The `wrap_tool` and `wrap_tools` docstrings say so. - Scoped to the tool definitions (`wrap_tool` and `wrap_tools`): `handle_tool_calls` returning raw `ToolExecutionResponse` objects rather than building `tool_result` blocks (where TS's caching also applies) is an existing, already-documented Python/TS asymmetry this change doesn't touch — there's no `tool_result` block construction anywhere in the Python provider to attach a cache breakpoint to. - New `providers/anthropic/tests/test_provider.py` — this provider had no behavioral test file before (only a type-inference test). Covers: default omits `cache_control`, enabling it attaches `{"type": "ephemeral"}`, only the last tool of a batch carries it via `wrap_tools`, and schema/name/ description are unaffected. - Wired the new test directory into `noxfile.py`'s `tst` session (installs and runs each provider's own `test_provider.py` as a separate pytest invocation, same pattern already used for `openai_agents`/`claude_agent_sdk`). ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? `uv run pytest providers/anthropic/tests/test_provider.py tests/test_type_inference_anthropic.py` — 11 passed (6 new in `providers/anthropic/tests`), no regressions. `ruff check`/`ruff format --check`: clean. `mypy --config-file config/mypy.ini providers/anthropic/`: same 2 pre-existing, unrelated errors as unmodified `next` (confirmed via `git stash`), none on the changed files. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I have read and understand every line of this diff, including any LLM-generated code - [x] Any third-party docs links or promotional content follow the third-party links policy — n/a - [x] I ran linters/tests locally and they passed - [ ] I updated documentation as needed — n/a, same reasoning as Part 1 - [x] I added tests or explain why not applicable - [ ] I added a changeset if this change affects published packages — **not applicable**, same reasoning as Part 1 (Python-only change, changesets are TS-only in this repo) --------- Co-authored-by: jkomyno <alberto@composio.dev>