Skip to main content

Crate mutil_ai

Crate mutil_ai 

Source
Expand description

A small, provider-neutral AI SDK designed for learning.

The important idea in this crate is the split between:

  1. an internal message model that can represent messy agent histories;
  2. a normalization layer that turns that model into a clean, strict provider-facing conversation;
  3. provider adapters that only serialize the normalized form.

This keeps role conversion and tool-call repair in one place.

The crate intentionally stops at the model request/response boundary. Conversation loops, tool execution, permissions, and agent scheduling belong to the downstream application. See examples/minimal_agent.rs for a small runtime built only from the public API.

Structs§

Anthropic
Entry point for Anthropic adapters.
AnthropicMessages
Adapter for POST /v1/messages.
AuditConfig
Controls which structured transport events are emitted.
AuditStats
Runtime counters for a bounded audit channel.
AuditStatsSnapshot
A point-in-time copy of AuditStats counters.
ByteCounts
Content-free request and response byte counts.
CancellationToken
A cloneable cooperative cancellation handle.
Capabilities
Capability switches used to reject requests before they reach a provider.
ChatRequest
A request sent to a model adapter.
ChatResponse
A normalized model response.
ClientInfo
Product identity attached to requests.
CompletionReport
A stable summary of transformations applied while preparing or decoding a model request.
CustomToolAccumulator
Accumulates a single custom call; deltas are fragments and done inputs are authoritative snapshots. Identical completion snapshots are idempotent.
EffortMapping
Provider-specific translation for neutral reasoning effort values.
EndpointAdapter
A protocol-dispatching adapter for explicitly configured endpoints.
EndpointSpec
Explicit description of one HTTP endpoint.
Gemini
Entry point for Gemini adapters.
GeminiGenerateContent
Adapter for POST /v1beta/models/{model}:generateContent.
HeaderPolicy
Header names that an application must explicitly opt into overriding.
ImagePart
A multimodal image input.
ImageUrl
Image input used by multimodal messages.
Message
A message in the internal conversation model.
ModelProfile
Model-level policy selected after the endpoint protocol is known.
NativeToolCall
Original call identity and input, independent of a canonical tool call.
NativeToolIdentity
Identity fields as they become available across streamed frames.
NormalizeOptions
Rules used by the normalization layer.
NormalizeProfile
Normalization behavior attached to a provider profile.
NormalizeReport
Details about normalization. Callers can log this while learning.
NormalizeStats
Context-free aggregate of normalization repairs.
NormalizedChat
A provider-facing conversation.
NormalizedMessage
A provider-facing message after role downgrade and tool-pair repair.
OpenAI
Entry point for OpenAI-compatible adapters.
OpenAIChat
Adapter for POST /v1/chat/completions.
OpenAIResponses
Adapter for POST /v1/responses.
ProfileAuditSnapshot
Non-content configuration snapshot for diagnostics.
ProfileId
Stable identifier for a provider profile.
ProfileRegistry
Explicit registry for built-in behavior profiles.
ProviderErrorInfo
Safe, provider-neutral summary of a structured error response.
ProviderProfile
Provider-level defaults and behavior switches.
ProviderRequestOptions
Typed provider request switches that are common across compatible APIs.
ProviderState
Opaque state needed to replay provider-specific content.
Reasoning
Provider-neutral reasoning content.
ReasoningAliases
Names observed in provider responses for each neutral reasoning category.
ReasoningCapabilities
Reasoning feature switches for a provider.
ReasoningConfig
Provider-neutral reasoning request configuration.
ReasoningProfile
Reasoning-related defaults for a provider.
RequestContext
Per-request context. It is intentionally not automatically mapped to provider-specific headers such as x-sessionid.
RequestOptions
Per-request transport options.
RequestProfile
Request fields that are applied before per-call extra_* values.
RequestTiming
Timing measured from the start of one logical request.
ResponseLimits
Bounds decoded provider data across all attempts of a logical request.
ResponseMetadata
HTTP metadata associated with a model response.
RetryDirective
A parsed server-directed retry instruction.
RetryPolicy
Controls how transient errors are retried.
ServerToolItem
Opaque provider-hosted tool item returned by a provider.
SseMessage
A parsed SSE message.
SseParser
Incremental, zero-I/O SSE parser.
StreamCapabilities
Streaming feature switches for a provider.
StreamError
Stable, content-free metadata for a recoverable stream error.
StreamProfile
Streaming behavior for a provider.
StreamReconnectPolicy
Opt-in transport reconnect policy for an already-started SSE stream.
ToolCall
A tool call requested by the model.
ToolCapabilities
Tool-call feature switches for a provider.
ToolProfile
Tool-call encoding behavior for a provider.
ToolResult
A tool result that will be sent back to the model.
ToolSpec
A provider-neutral tool definition.
TransportConfig
Shared transport defaults for an adapter.
Usage
Token usage reported by a provider.
UsageProfile
Usage reporting behavior for a provider.
WireReport
Provider-wire transformations that could not be represented losslessly.

Enums§

AuditEvent
A structured, context-free audit event.
AuditOutcome
The final outcome of an attempt or request.
AuthStyle
How the generic adapter authenticates a request.
CustomToolFormat
Input accepted by a client-executed custom tool.
Error
The error type returned by this crate’s public API.
ErrorKind
Stable high-level classification for SDK errors.
ExternalRole
Roles that are safe to send to a provider adapter.
FirstTokenKind
Which model output started the stream.
ImageDetail
Processing-detail hint for image inputs.
ImageSource
A provider-neutral image source.
MaxTokensSemantics
Which request field carries the maximum output token limit.
MissingToolResultPolicy
What to do when an assistant tool call has no result.
ModelMatcher
Selects which model names a ModelProfile applies to.
NativeToolCompletion
Whether the protocol has reliably finished delivering a call.
NativeToolKind
The original wire representation of a client-executed tool call.
NativeToolPayload
Raw input, kept separate from application-specific canonical arguments.
NormalizeAction
A human-readable trace of every repair made at the boundary.
OrphanToolResultPolicy
What to do with a tool result that has no matching assistant tool call.
Part
A piece of a message.
ProfileSelector
Which profile implementation should be used for an endpoint.
Protocol
The provider-facing protocol we are preparing a request for.
ProtocolSurface
Protocol surface of an endpoint, re-exported from the normalize module.
ProviderStateFormat
The wire format that owns an opaque provider state.
ReasoningEffort
A provider-neutral reasoning-effort level.
ReasoningKind
The main display category of a reasoning item.
ReasoningMode
High-level mode for providers that expose enable/disable controls.
ReasoningReplayPolicy
Whether and how reasoning state captured from a response is replayed on follow-up requests.
ReasoningSummary
How much reasoning detail the provider should expose.
ResponseFormat
Provider-neutral output format for one request.
RetryProvider
Provider family used to decide which vendor-specific reset headers to read.
RetrySource
Where a retry delay came from. This is useful for logs and debugging.
Role
The role used inside your application.
ScopedToolDeclaration
A client-executed tool within a declaration scope.
ServerTool
A provider-hosted tool declaration.
ServerToolState
Generic state of a provider-hosted tool.
SseError
Errors that can occur while parsing an SSE stream.
SseEvent
An event emitted by SseParser.
SseUtf8Policy
How invalid UTF-8 in field values is handled.
StreamEvent
A provider-neutral streaming event.
StreamTerminal
The event that marks the end of a provider’s response stream.
SystemPlacement
How System/Developer messages are placed by normalization.
TailPolicy
How an incomplete trailing event is handled by SseParser::finish.
ThinkingRequestProfile
How a neutral thinking configuration is encoded into a provider request.
ToolCallContentMode
How an assistant tool-call message should encode empty content.
ToolCallIdPolicy
How tool-call identifiers are handled when translating between protocols.
ToolChoice
Provider-neutral tool selection for one request.
ToolDeclaration
A flat client tool or a single-level namespace of client tools.
ToolResultPart
A structured tool-result payload.
UsagePlacement
Where usage (token counts) appears in a streamed response.
WireAction
WireFeature

Constants§

SDK_USER_AGENT
Default User-Agent value, e.g. mutil-ai/0.1.0.

Traits§

AuditSink
Receives context-free audit events.
HeaderInjector
Dynamic header provider for authentication refresh and request-specific routing.
ModelAdapter
A provider adapter.
RequestTransform
A synchronous, provider-neutral request transform.

Functions§

apply_headers
Merges one header layer into target, enforcing the HeaderPolicy.
bounded_audit_channel
Create a non-blocking, bounded audit channel.
collect_stream
Collect a stream into the final response while preserving all events.
next_event
Await the next stream event without requiring the caller to import futures_util::StreamExt.
normalize
Normalize a request using the default rules for a protocol.
normalize_with_options
Normalize a request with explicit rules.
parse_retry_after
Parse the HTTP Retry-After header.
parse_retry_after_at
Deterministic version of parse_retry_after for tests and custom clocks.
parse_retry_headers
Read all supported retry headers using the current time.
parse_retry_headers_at
Deterministic version of parse_retry_headers.
retry_async
Retry an async operation according to a RetryPolicy.
validate_tool_declarations
Reject duplicate names within each declaration scope, regardless of kind.

Type Aliases§

ModelStream
A boxed provider-neutral stream of model events.
OpenAICompatible
Backwards-compatible name for the OpenAI Chat-focused first iteration.
Result
Convenience alias for results returned by this crate.