Skip to main content

Crate a2a_llm

Crate a2a_llm 

Source
Expand description

Provider-neutral vocabulary for chat completions, plus the providers that speak it.

LlmProvider is the port: chat_completion and chat_completion_stream over LlmRequest / LlmResponse. openai covers OpenAI and every OpenAI-compatible endpoint (OpenRouter, vLLM, llama.cpp); gemini covers Google’s API. provider_from_env picks one from the environment.

The types are deliberately not tied to A2A. ToolCall, ToolDefinition and ToolResult are the tool-calling vocabulary shared with the MCP bridge, which is why they live in their own crate rather than inside an agent framework.

decision is the second port: DecisionModel asks a decision model typed questions (yes-or-no, choice, score) and gets probabilities back instead of text.

A message’s content is MessageContent: a string, or ContentParts when it carries bytes a string cannot — an image, a PDF, a recording. Each provider renders those into the shape its API takes; see content.

Re-exports§

pub use content::ContentPart;
pub use content::MessageContent;
pub use decision::DECISION_PROVIDERS;
pub use decision::Decision;
pub use decision::DecisionConfigError;
pub use decision::DecisionError;
pub use decision::DecisionModel;
pub use decision::DecisionProvider;
pub use decision::DecisionSettings;
pub use decision::Question;
pub use decision::Questions;
pub use decision::SelectedDecision;
pub use decision::answer_schema;
pub use decision::decision_from_settings;
pub use provider::LlmConfigError;
pub use provider::LlmSettings;
pub use provider::PROVIDER_ENV_VARS;
pub use provider::ReasoningPlan;
pub use provider::SUPPORTED_PROVIDERS;
pub use provider::SelectedLlm;
pub use provider::provider_from_env;
pub use provider::provider_from_settings;
pub use tool_call::PartialToolCall;
pub use tool_call::ToolCallAccumulator;

Modules§

content
What a message says, when not all of it is text.
decision
Decision models: a typed answer and its probability, instead of text.
gemini
openai
provider
Centralized LlmProvider selection.
schema
What each provider takes of a tool’s JSON Schema.
tool_call
Incremental tool-call assembly for streaming LLM responses.

Structs§

ChatMessage
A single message in a chat conversation.
LlmRequest
A request to an LLM provider for chat completion.
LlmResponse
A response from an LLM provider.
TokenUsage
Tokens a provider reported for one request.
ToolAnnotations
What a tool’s source says about its effects. Hints, not guarantees: MCP’s own wording, and a server can lie. None is “the source said nothing”, which is not the same as Some(false) — a tool with no read_only claim is a tool the consumer knows nothing about, not one that writes.
ToolCall
Represents a specific tool invocation requested by the LLM.
ToolDefinition
Defines a tool (function) available for the LLM to call.
ToolResult
What a tool answered: the text the model is shown, and the structured value beside it when the tool’s source returned one (MCP’s structuredContent).

Enums§

FinishReason
Why the model stopped generating, normalized across providers.
LlmError
Represents an error returned by an LLM provider.
LlmStreamEvent
An event emitted during a streaming LLM response.
MessageRole
The role of the message sender.
Reasoning
What to ask a reasoning-capable model to do with its thinking.
ReasoningEffort
How hard a reasoning model should think, when reasoning is requested.

Traits§

LlmProvider
Trait defining a generic LLM provider for standardizing AI integration across agents.