Skip to content

Cohere ​

The Cohere provider uses provider key cohere and the HPD-Agent.Providers.Cohere package. ModelName is a Cohere chat model id for chat, or a Cohere embedding model id for embeddings.

The provider package is currently net10.0 only because the underlying TryAGI-generated Cohere SDK targets net10.0.

Set an API key:

bash
export COHERE_API_KEY="..."

Use fluent chat setup first:

csharp
using HPD.Agent;
using HPD.Agent.Providers.Cohere;

var agent = await new AgentBuilder()
    .WithCohere(model: "command-r-plus")
    .BuildAsync();

var result = await agent.RunAsync("Write one sentence about Cohere setup.");
Console.WriteLine(result.Text);

Provider construction stays small. Put model behavior on the agent's Clients.Chat default or a run's complete Clients.Chat replacement, and use Cohere request options only for Cohere-only request fields:

csharp
using HPD.Agent;
using HPD.Agent.Providers.Cohere;

var agent = await new AgentBuilder()
    .WithCohere(model: "command-r-plus")

    .WithCohereChatRequestOptions(cohere =>
    {
        cohere.StrictTools = true;
        cohere.CitationMode = CohereCitationMode.Accurate;
        cohere.SafetyMode = CohereSafetyMode.Strict;
        cohere.ThinkingTokenBudget = 2048;
        cohere.Documents =
        [
            new CohereChatDocument
            {
                Id = "setup",
                Data = new Dictionary<string, object>
                {
                    ["title"] = "Setup note",
                    ["body"] = "Runtime model behavior belongs on Clients.Chat."
                }
            }
        ];
    })
    .BuildAsync();

The provider helper writes the same portable fields, typed providerConfig, and typed providerOptions into Clients.Chat. Use the runtime selection guide for the canonical JSON and YAML shape.

Embeddings ​

Cohere also registers the embeddings provider family under the same cohere key:

csharp
using HPD.Agent;
using HPD.Agent.Providers.Cohere;

var agent = await new AgentBuilder()
    .WithCohereEmbeddings(model: "embed-english-v3.0")
    .BuildAsync();

The equivalent family config is:

json
{
  "Clients": {
    "Embeddings": {
      "ProviderKey": "cohere",
      "ModelName": "embed-english-v3.0"
    }
  }
}

Runtime Chat Options ​

Use ChatClientConfig for shared model-call behavior such as temperature, top-p, top-k, max output tokens, stop sequences, tools, tool mode, seed, and generic reasoning options. Put agent-level defaults in AgentConfig.Clients.Chat; use AgentRunConfig.Clients.Chat for complete per-run replacements.

The Cohere adapter maps the common MEAI chat options to Cohere Chat v2 request fields:

HPD chat optionCohere request field
ModelIdmodel
Temperaturetemperature
TopPp
TopKk
MaxOutputTokensmax_tokens
Seedseed
StopSequencesstop_sequences
ResponseFormatresponse_format
Toolstools
ToolModetool_choice
Reasoningthinking

Use CohereChatRequestOptions for Cohere-only request properties:

OptionCohere keyMeaning
StrictToolsstrict_toolsForces tool calls to follow their tool definitions strictly.
DocumentsdocumentsRelevant source documents that the model can cite while generating an answer.
CitationModecitation_modeCitation generation mode. Supported values include enabled, disabled, accurate, fast, and off.
SafetyModesafety_modeSafety instruction mode. Supported values include contextual, off, and strict.
LogprobslogprobsIncludes output token log probabilities in the raw Cohere response.
ThinkingEnabledthinking_enabledOverrides whether Cohere thinking is enabled. If unset, generic Reasoning controls this.
ThinkingTokenBudgetthinking_token_budgetMaximum number of tokens the model can use for thinking.
PrioritypriorityRequest priority. Lower numbers indicate higher priority; Cohere defaults to 0.

CohereChatDocument supports:

OptionMeaning
IdOptional identifier referenced by Cohere citations.
TextPlain document text for simple string documents.
DataStructured document data and metadata.

Construction Options ​

CohereProviderConfig exposes Cohere-specific embedding defaults for the embeddings family:

OptionPurpose
EmbeddingModelIdDefault embedding model id for the embeddings provider family.

For embeddings, WithCohereEmbeddings(...) stores the embedding model in the embeddings family config.

Caveats ​

Cohere chat and embeddings are available only when the HPD-Agent.Providers.Cohere package is referenced by a net10.0 application.

The current TryAGI Cohere MEAI streaming adapter returns a single final update rather than token-by-token streaming.

Runtime validation checks model, endpoint, and embedding model options. Runtime chat options are applied through Clients.Chat and AgentRunConfig.Clients.Chat. Generic reasoning is mapped to Cohere thinking; set ThinkingEnabled or ThinkingTokenBudget only when you need Cohere-specific control. Credentials are resolved lazily when a run first acquires this provider client; a missing credential fails that run, not BuildAsync().

Built for production .NET agent applications.