|
| 1 | +# Anthropic |
| 2 | + |
| 3 | +[Anthropic](https://docs.anthropic.com/en/home) is an AI safety and research company focused on building reliable, interpretable, and steerable AI systems. Included in their offerings is the Claude AI family of models, which are known for their conversational abilities, careful reasoning, and capacity to follow complex instructions. The Strands Agents SDK implements an Anthropic provider, allowing users to run agents against Claude models directly. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Anthropic is configured as an optional dependency in Strands. To install, run: |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install strands-agents[anthropic] |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +After installing `anthropic`, you can import and initialize Strands' Anthropic provider as follows: |
| 16 | + |
| 17 | +```python |
| 18 | +from strands import Agent |
| 19 | +from strands.models.anthropic import AnthropicModel |
| 20 | +from strands_tools import calculator |
| 21 | + |
| 22 | +model = AnthropicModel( |
| 23 | + client_args={ |
| 24 | + "api_key": "<KEY>", |
| 25 | + }, |
| 26 | + # **model_config |
| 27 | + max_tokens=1028, |
| 28 | + model_id="claude-3-7-sonnet-20250219", |
| 29 | + params={ |
| 30 | + "temperature": 0.7, |
| 31 | + } |
| 32 | +) |
| 33 | + |
| 34 | +agent = Agent(model=model, tools=[calculator]) |
| 35 | +response = agent("What is 2+2") |
| 36 | +print(response) |
| 37 | +``` |
| 38 | + |
| 39 | +## Configuration |
| 40 | + |
| 41 | +### Client Configuration |
| 42 | + |
| 43 | +The `client_args` configure the underlying Anthropic client. For a complete list of available arguments, please refer to the Anthropic [docs](https://docs.anthropic.com/en/api/client-sdks). |
| 44 | + |
| 45 | +### Model Configuration |
| 46 | + |
| 47 | +The `model_config` configures the underlying model selected for inference. The supported configurations are: |
| 48 | + |
| 49 | +| Parameter | Description | Example | Options | |
| 50 | +|------------|-------------|---------|---------| |
| 51 | +| `max_tokens` | Maximum number of tokens to generate before stopping | `1028` | [reference](https://docs.anthropic.com/en/api/messages#body-max-tokens) |
| 52 | +| `model_id` | ID of a model to use | `claude-3-7-sonnet-20250219` | [reference](https://docs.anthropic.com/en/api/messages#body-model) |
| 53 | +| `params` | Model specific parameters | `{"max_tokens": 1000, "temperature": 0.7}` | [reference](https://docs.anthropic.com/en/api/messages) |
| 54 | + |
| 55 | +## Troubleshooting |
| 56 | + |
| 57 | +### Module Not Found |
| 58 | + |
| 59 | +If you encounter the error `ModuleNotFoundError: No module named 'anthropic'`, this means you haven't installed the `anthropic` dependency in your environment. To fix, run `pip install strands-agents[anthropic]`. |
| 60 | + |
| 61 | +## References |
| 62 | + |
| 63 | +- [API](../../../api-reference/models.md) |
| 64 | +- [Anthropic](https://docs.anthropic.com/en/home) |
| 65 | + |
0 commit comments