Skip to content

Commit ba031f8

Browse files
authored
Merge pull request #155 from stanislavHamara/new-provider-docs
Add docs on how to add a new provider
2 parents 20f9e88 + 13fe871 commit ba031f8

3 files changed

Lines changed: 73 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Many more examples can be found [here](/examples/README.md)!
3939

4040
### Improving an agent with MCP tools
4141

42-
`cagent` supports MCP servers, enabling agents to use a wide variety of external tools and services.
42+
`cagent` supports MCP servers, enabling agents to use a wide variety of external tools and services.
4343

4444
It supports three transport types: `stdio`, `http` and `sse`.
4545

@@ -62,9 +62,9 @@ agents:
6262
ref: docker:duckduckgo # stdio transport
6363
```
6464

65-
When using a containerized server via the Docker MCP gateway, you can configure any required settings/secrets/authentication using the [Docker MCP Toolkit](https://docs.docker.com/ai/mcp-catalog-and-toolkit/toolkit/#example-use-the-github-official-mcp-server) in Docker Desktop.
65+
When using a containerized server via the Docker MCP gateway, you can configure any required settings/secrets/authentication using the [Docker MCP Toolkit](https://docs.docker.com/ai/mcp-catalog-and-toolkit/toolkit/#example-use-the-github-official-mcp-server) in Docker Desktop.
6666

67-
Aside from the containerized MCP severs the Docker MCP Gateway provides, any standard MCP server can be used with cagent!
67+
Aside from the containerized MCP severs the Docker MCP Gateway provides, any standard MCP server can be used with cagent!
6868

6969
Here's an example similar to the above but adding `read_file` and `write_file` tools from the `rust-mcp-filesystem` MCP server:
7070

@@ -194,7 +194,7 @@ models:
194194
model: ai/qwen3
195195
max_tokens: 8192
196196
provider_opts:
197-
runtime_flags: ["--ngl=33", "--repeat-penalty=1.2", ...] # or comma/space-separated string
197+
runtime_flags: ["--ngl=33", "--repeat-penalty=1.2", ...] # or comma/space-separated string
198198
```
199199

200200
The default base_url `cagent` will use for dmr providers is `http://localhost:12434/engines/llama.cpp/v1`. DMR itself might need to be enabled via [Docker Desktop's settings](https://docs.docker.com/ai/model-runner/get-started/#enable-dmr-in-docker-desktop) on MacOS and Windows, and via command line on [Docker CE on Linux](https://docs.docker.com/ai/model-runner/get-started/#enable-dmr-in-docker-engine).

docs/CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ improvements to the code. It can also fix issues and implement new features!
8585

8686
More info about the architecture behind `cagent` can be found [here](/docs/architecture.md)
8787

88+
## Add a new model provider
89+
90+
More details on how to add a new model provider can be found in [PROVIDERS.md](/docs/PROVIDERS.md)
91+
8892
## Opening issues
8993

9094
Issues can be opened on our repo [here](https://github.com/docker/cagent/issues).

docs/PROVIDERS.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Adding a new provider to Cagent
2+
3+
## Add provider alias
4+
5+
Add a new `Alias` to `ProviderAliases` [`pkg/model/provider/provider.go`](https://github.com/docker/cagent/blob/main/pkg/model/provider/provider.go)
6+
7+
```go
8+
var ProviderAliases = map[string]Alias{
9+
"requesty": {
10+
ApiType: "openai",
11+
BaseURL: "https://router.requesty.ai/v1",
12+
TokenEnvVar: "REQUESTY_API_KEY",
13+
},
14+
"azure": {
15+
ApiType: "openai",
16+
TokenEnvVar: "AZURE_API_KEY",
17+
},
18+
"YOUR_PROVIDER": {
19+
ApiType: "openai"
20+
TokenEnvVar: "YOUR_PROVIDER_API_KEY"
21+
BaseURL: "https://your-provider.ai/v1"
22+
}
23+
}
24+
```
25+
26+
## Add custom config if needed (optional)
27+
28+
If your provider requires custom config, like Azure's `api_version`
29+
30+
```yaml
31+
models:
32+
azure_model:
33+
provider: azure
34+
model: gpt-4o
35+
base_url: https://your-llm.openai.azure.com
36+
provider_opts:
37+
api_version: 2024-12-01-preview
38+
# custom option example
39+
your_model:
40+
provider: your_provider
41+
model: gpt-4o
42+
provider_opts:
43+
your_custom_option: your_custom_value
44+
```
45+
46+
edit [`pkg/model/provider/openai/client.go`](https://github.com/docker/cagent/blob/main/pkg/model/provider/openai/client.go)
47+
48+
```go
49+
switch cfg.Provider { //nolint:gocritic
50+
case "azure":
51+
if apiVersion, exists := cfg.ProviderOpts["api_version"]; exists {
52+
slog.Debug("Setting API version", "api_version", apiVersion)
53+
if apiVersionStr, ok := apiVersion.(string); ok {
54+
openaiConfig.APIVersion = apiVersionStr
55+
}
56+
}
57+
case "your_provider":
58+
if yourCustomOption, exists := cfg.ProviderOpts["your_custom_option"]; exists {
59+
slog.Debug("Setting your custom option", "your_custom_option", yourCustomOption)
60+
if yourCustomOptionStr, ok := yourCustomOption.(string); ok {
61+
openaiConfig.yourCustomOption = yourCustomOptionStr
62+
}
63+
}
64+
}
65+
```

0 commit comments

Comments
 (0)