From e7b599eb66697f1afeb4691c531bbd9a6c0aa3ce Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Fri, 27 Jun 2025 06:40:07 -0500 Subject: [PATCH 1/8] Create cohere.md --- .../concepts/model-providers/cohere.md | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/user-guide/concepts/model-providers/cohere.md diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md new file mode 100644 index 00000000..78eed4fe --- /dev/null +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -0,0 +1,74 @@ +# Cohere + +[Cohere](https://cohere.com) provides cutting-edge language models. These are accessible accessible through OpenAI's SDK via the Compatibility API. This allows easy and portable integration with the Strands Agents SDK using the familiar OpenAI interface. + +## Installation + +Cohere is configured as an optional dependency in Strands Agents via the openai sdk. To install, run: + +```bash +pip install 'strands-agents[openai]' +```` + +## Usage + +After installing the `openai` package, you can import and initialize the Strands Agents' OpenAI-compatible provider for Cohere models as follows: + +```python +from strands import Agent +from strands.models.openai import OpenAIModel +from strands_tools import calculator + +model = OpenAIModel( + client_args={ + "api_key": "", + "base_url": "https://api.cohere.ai/compatibility/v1", # Cohere compatibility endpoint + }, + model_id="command-a-03-2025" # or see https://docs.cohere.com/docs/models +) + +agent = Agent(model=model, tools=[calculator]) +response = agent("What is 2+2?") +print(response) +``` + +## Configuration + +### Client Configuration + +The `client_args` configure the underlying OpenAI-compatible client. When using Cohere, you must set: + +* `api_key`: Your Cohere API key. Get one from the [Cohere Dashboard](https://dashboard.cohere.com). +* `base_url`: `https://api.cohere.ai/compatibility/v1` + +Refer to [OpenAI Python SDK GitHub](https://github.com/openai/openai-python) for full client options. + +### Model Configuration + +The `model_config` specifies which Cohere model to use and any additional parameters. + +| Parameter | Description | Example | Options | +| ---------- | ------------------------- | ------------------------------------------ | ------------------------------------------------------------------ | +| `model_id` | Model name | `command-r-plus` | See [Cohere docs](https://docs.cohere.com/docs/models) | +| `params` | Model-specific parameters | `{"max_tokens": 1000, "temperature": 0.7}` | [API reference](https://docs.cohere.com/docs/compatibility-api) | + +## Troubleshooting + +### `ModuleNotFoundError: No module named 'openai'` + +You must install the `openai` dependency to use this provider: + +```bash +pip install 'strands-agents[openai]' +``` + +### Unexpected model behavior? + +Ensure you're using a model ID compatible with Cohere’s Compatibility API (e.g., `command-r-plus`, `command-a-03-2025`, `embed-v4.0`), and your `base_url` is set to `https://api.cohere.ai/compatibility/v1`. + +## References + +* [Cohere Docs: Using the OpenAI SDK](https://docs.cohere.com/docs/compatibility-api) +* [Cohere API Reference](https://docs.cohere.com/reference) +* [OpenAI Python SDK](https://github.com/openai/openai-python) +* [Strands Agents API](../../../api-reference/models.md) From 76f55a7de5ddee02d0d48ce2739ed1ea6f41b57e Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Fri, 27 Jun 2025 06:41:42 -0500 Subject: [PATCH 2/8] Update mkdocs.yml --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 358501c5..4c7fa681 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -88,6 +88,7 @@ nav: - LlamaAPI: user-guide/concepts/model-providers/llamaapi.md - Ollama: user-guide/concepts/model-providers/ollama.md - OpenAI: user-guide/concepts/model-providers/openai.md + - Cohere: user-guide/concepts/model-providers/cohere.md - Custom Providers: user-guide/concepts/model-providers/custom_model_provider.md - Streaming: - Async Iterators: user-guide/concepts/streaming/async-iterators.md From 85f85791ad0e9cb92d02929a50d467a68ece8ba2 Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:42:23 -0500 Subject: [PATCH 3/8] Update docs/user-guide/concepts/model-providers/cohere.md Co-authored-by: Nick Clegg --- docs/user-guide/concepts/model-providers/cohere.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 78eed4fe..5306bb1f 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -4,7 +4,7 @@ ## Installation -Cohere is configured as an optional dependency in Strands Agents via the openai sdk. To install, run: +The Strands Agents SDK provides access to Cohere models through the OpenAI compatiblity layer, configured as an optional dependency. To install, run: ```bash pip install 'strands-agents[openai]' From 3e8e122ed0feb8e1e5be5765e3b9fef4d62d8325 Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:43:14 -0500 Subject: [PATCH 4/8] Update cohere.md --- docs/user-guide/concepts/model-providers/cohere.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 5306bb1f..644de599 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -8,7 +8,7 @@ The Strands Agents SDK provides access to Cohere models through the OpenAI compa ```bash pip install 'strands-agents[openai]' -```` +``` ## Usage From 5a14947f075b719d523b4ecdcea412f3089bbdf5 Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:43:33 -0500 Subject: [PATCH 5/8] Apply suggestion from @Unshure Co-authored-by: Nick Clegg --- docs/user-guide/concepts/model-providers/cohere.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 644de599..7979af95 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -24,7 +24,10 @@ model = OpenAIModel( "api_key": "", "base_url": "https://api.cohere.ai/compatibility/v1", # Cohere compatibility endpoint }, - model_id="command-a-03-2025" # or see https://docs.cohere.com/docs/models + model_id="command-a-03-2025" # or see https://docs.cohere.com/docs/models, + params={ + "stream_options": None + } ) agent = Agent(model=model, tools=[calculator]) From ea10f945efc7d618720bbf2ca7596a8e6d0d9b0a Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:43:44 -0500 Subject: [PATCH 6/8] Apply suggestion from @Unshure Co-authored-by: Nick Clegg --- docs/user-guide/concepts/model-providers/cohere.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 7979af95..6617e9d1 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -31,8 +31,7 @@ model = OpenAIModel( ) agent = Agent(model=model, tools=[calculator]) -response = agent("What is 2+2?") -print(response) +agent("What is 2+2?") ``` ## Configuration From c201429eb13edc44e4fac2804c6106b7d33d3415 Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 14:45:01 -0500 Subject: [PATCH 7/8] Apply suggestion from @billytrend-cohere --- docs/user-guide/concepts/model-providers/cohere.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 6617e9d1..1e8092d4 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -41,7 +41,8 @@ agent("What is 2+2?") The `client_args` configure the underlying OpenAI-compatible client. When using Cohere, you must set: * `api_key`: Your Cohere API key. Get one from the [Cohere Dashboard](https://dashboard.cohere.com). -* `base_url`: `https://api.cohere.ai/compatibility/v1` +* `base_url`: + * `https://api.cohere.ai/compatibility/v1` Refer to [OpenAI Python SDK GitHub](https://github.com/openai/openai-python) for full client options. From eb0e834298b281e24f64bf124ae86f3ca4e4c242 Mon Sep 17 00:00:00 2001 From: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:38:48 -0500 Subject: [PATCH 8/8] Update docs/user-guide/concepts/model-providers/cohere.md --- docs/user-guide/concepts/model-providers/cohere.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user-guide/concepts/model-providers/cohere.md b/docs/user-guide/concepts/model-providers/cohere.md index 1e8092d4..3417b082 100644 --- a/docs/user-guide/concepts/model-providers/cohere.md +++ b/docs/user-guide/concepts/model-providers/cohere.md @@ -24,7 +24,7 @@ model = OpenAIModel( "api_key": "", "base_url": "https://api.cohere.ai/compatibility/v1", # Cohere compatibility endpoint }, - model_id="command-a-03-2025" # or see https://docs.cohere.com/docs/models, + model_id="command-a-03-2025", # or see https://docs.cohere.com/docs/models params={ "stream_options": None }