Expand description
af-llm — unified async LLM access for the Agent Factory platform.
Provider-neutral model transport and request types. Provides:
LlmClient— async chat completions against any OpenAI-compatible endpoint, with a hard per-request timeout and a sharedCircuitBreaker.- Strongly-typed request/response models (
CompletionRequest,CompletionResponse,ChatMessage,Tool, …) — the Pydantic equivalent, validated at the wire boundary. parse_json— pull structured output out of fenced LLM text into anyserdetype.
§Example
use af_llm::{LlmClient, LlmConfig, CompletionRequest, ChatMessage};
let client = LlmClient::new(LlmConfig::new("http://localhost:4000/v1", ""))?;
let req = CompletionRequest::new(
"deepseek/deepseek-chat",
vec![ChatMessage::user("Say hi in one word.")],
);
let resp = client.complete_stream_single_attempt(&req, |_, _| {}).await?;
println!("{:?}", resp.first_content());Re-exports§
pub use circuit_breaker::CircuitBreaker;pub use circuit_breaker::State as CircuitState;pub use circuit_breaker::Status as CircuitStatus;pub use client::LlmClient;pub use client::LlmConfig;pub use client::DEFAULT_TIMEOUT;pub use error::LlmError;pub use error::Result;pub use json::parse_json;pub use json::strip_code_fence;pub use stream::StreamDelta;pub use types::AssistantBlock;pub use types::ChatMessage;pub use types::Choice;pub use types::CompletionRequest;pub use types::CompletionResponse;pub use types::FinishReason;pub use types::FunctionCall;pub use types::FunctionDef;pub use types::InputImage;pub use types::ReasoningEffort;pub use types::Role;pub use types::StreamOptions;pub use types::Tool;pub use types::ToolCall;pub use types::ToolChoice;pub use types::Usage;
Modules§
- circuit_
breaker - In-process circuit breaker for LLM calls.
- client
- Async LLM client — port of
agent_core/llm/client.py::llm_completion. - error
- Error type for the LLM client.
- images
- Governed binary resource resolution at the provider boundary. Image references remain durable; signed projections exist only for one request.
- json
- Helpers for coaxing structured JSON out of free-form LLM text.
- stream
- OpenAI-compatible SSE parsing for streaming chat completions.
- types
- Strongly-typed OpenAI-compatible chat-completion request/response shapes.