Expand description
Provider-agnostic LLM trait and wire types for polychrome.
This crate defines the LlmProvider trait that every concrete provider
backend implements, and the language-shaped Rust types that flow through it.
LlmProvider is the seam that lets the planner swap LLM backends
without touching its own code: one impl crate per provider, dispatched
behind a dyn LlmProvider trait object.
§Modules
request—CompletionRequestand everything reachable from it (Message,Content,ToolSpec,ToolChoice).chunk—Chunk(streaming response events) and friends (Usage,StopReason).error— theLlmErrortrait bound thatLlmProvider::Errormust satisfy.
The trait itself lives in this crate root; the wire types live in the modules above and are re-exported here for convenience.
Re-exports§
pub use chunk::Chunk;pub use chunk::StopReason;pub use chunk::Usage;pub use erased::BoxError;pub use erased::DynProvider;pub use erased::ErasedProvider;pub use erased::into_dyn;pub use error::LlmError;pub use error::LlmErrorKind;pub use error::kind_from_http_status;pub use error::parse_retry_after;pub use model_info::FALLBACK_CONTEXT_WINDOW;pub use model_info::ModelInfo;pub use model_info::lookup_model;pub use model_info::lookup_model_or_fallback;pub use preflight::PreflightReport;pub use preflight::ProbeOutcome;pub use preflight::preflight;pub use request::APPROVAL_STATUS_GROUND_RULE;pub use request::CacheHint;pub use request::CompletionRequest;pub use request::Content;pub use request::GATED_TOOL_APPROVAL_NOTE;pub use request::ImageRef;pub use request::JsonSchema;pub use request::Message;pub use request::Role;pub use request::ToolCall;pub use request::ToolChoice;pub use request::ToolResult;pub use request::ToolSpec;
Modules§
- chunk
- Streaming response types:
Chunk,Usage, andStopReason. - erased
- Type erasure for
LlmProviderso the control plane can hold a singleArc<dyn LlmProvider>regardless of which backend is configured. - error
LlmErrormarker trait and referenceDummyErrorimplementation.- model_
info - Bundled model catalog: per-model context-window facts and the longest-prefix lookup that drives compaction.
- preflight
- Startup preflight: verify a backend actually delivers native tool calling and schema-constrained structured output, against the live endpoint.
- request
- Request-side LLM types:
CompletionRequest,Message,Content,ToolSpec,ToolChoice, andJsonSchema. - sse
- Shared Server-Sent Events framing helpers for streaming providers.
- turn
- Turn helpers: a
StubProviderfor wiring/tests andcollect_turn, which folds a provider’sChunkstream into a singleTurnOutput.
Traits§
- LlmProvider
- The seam between the planner and any concrete LLM backend.
Functions§
- init_
metrics - Force-register this crate’s Prometheus call-latency histogram.