Expand description
§LiteForge
A Rust SDK for the LiteForge with an OpenAI-compatible API.
§Quick Start
use liteforge::{ForgeClient, Message};
// Create client (reads LITEFORGE_API_KEY from environment)
let client = ForgeClient::new();
// Make a completion request
let response = client.complete(vec![
Message::user("What is the capital of France?")
]).unwrap();
println!("{}", response.content().unwrap_or("No response"));§Async Usage
use liteforge::{AsyncForgeClient, Message};
#[tokio::main]
async fn main() {
let client = AsyncForgeClient::new();
let response = client.complete(vec![
Message::user("Hello!")
]).await.unwrap();
println!("{}", response.content().unwrap_or("No response"));
}§Streaming
use liteforge::{AsyncForgeClient, Message};
use futures::StreamExt;
#[tokio::main]
async fn main() {
let client = AsyncForgeClient::new();
let mut stream = client.complete_stream(vec![
Message::user("Tell me a story")
]).await.unwrap();
while let Some(chunk) = stream.next().await {
if let Ok(chunk) = chunk {
if let Some(content) = chunk.content() {
print!("{}", content);
}
}
}
}§Configuration
The SDK reads configuration from environment variables:
LITEFORGE_API_KEYorOPENAI_API_KEY: API key for authenticationLITEFORGE_BASE_URL: Custom API endpointLITEFORGE_DEFAULT_MODEL: Default model to useLITEFORGE_TIMEOUT: Request timeout in seconds
You can also configure programmatically:
use liteforge::ForgeClient;
let client = ForgeClient::builder()
.api_key("your-api-key")
.default_model("gpt-4")
.base_url("https://api.example.com")
.timeout_secs(30)
.build();Re-exports§
pub use client::AsyncForgeClient;pub use client::ForgeClient;pub use client::ForgeClientBuilder;pub use config::OtelConfig;pub use config::ForgeConfig;pub use config::ForgeConfigBuilder;pub use error::Result;pub use error::ForgeError;pub use otel_init::init_otel;pub use otel_init::otel_feature_enabled;pub use types::ChatCompletion;pub use types::ChatCompletionChunk;pub use types::ChatCompletionRequest;pub use types::Choice;pub use types::ChoiceDelta;pub use types::EmbeddingData;pub use types::EmbeddingInput;pub use types::EmbeddingRequest;pub use types::EmbeddingResponse;pub use types::EmbeddingUsage;pub use types::FunctionCall;pub use types::Message;pub use types::Model;pub use types::ModelList;pub use types::StreamChoice;pub use types::ToolCall;pub use types::ToolDefinition;pub use types::ToolParameters;pub use types::Usage;pub use chunking::chunk;pub use chunking::Chunk;pub use chunking::ChunkingStrategy;pub use guardrails::check_all;pub use guardrails::detect_injection;pub use guardrails::detect_pii;pub use guardrails::find_pii;pub use guardrails::redact_pii;pub use guardrails::GuardrailResult;pub use guardrails::PiiType;pub use guardrails::INJECTION_PATTERNS;pub use guardrails::PII_PATTERNS;pub use retry::is_retryable;pub use retry::with_retry;pub use retry::with_retry_async;pub use retry::RetryConfig;pub use tools::validate_json_schema;pub use tools::FnTool;pub use tools::FunctionDefinition;pub use tools::SchemaValidationError;pub use tools::Tool;pub use tools::ToolExecutor;pub use tools::ToolRegistry;pub use tools::ToolResult;pub use knowledge::Document;pub use knowledge::KnowledgeClient;pub use knowledge::KnowledgeStats;pub use knowledge::ListOptions;pub use knowledge::LocalKnowledgeBackend;pub use knowledge::SearchOptions;pub use knowledge::SearchResult;pub use knowledge::SyncKnowledgeClient;pub use rag::cosine_similarity;pub use rag::dot_product;pub use rag::euclidean_distance;pub use rag::normalize;pub use rag::EmbeddedDocument;pub use rag::RagConfig;pub use rag::RagPipeline;pub use rag::RagPipelineBuilder;pub use rag::RetrievalResult;pub use rag::VectorIndex;pub use rag::VectorSearchResult;pub use events::Event;pub use events::EventBus;pub use events::EventData;pub use events::EventType;pub use events::Subscription;pub use hooks::Hook;pub use hooks::HookContext;pub use hooks::HookManager;pub use hooks::HookResult;pub use agents::Agent;pub use agents::AgentConfig;pub use agents::AgentContext;pub use agents::AgentError;pub use agents::AgentMemory;pub use agents::AgentState;pub use agents::AgentStep;pub use agents::StepResult;pub use agents::StepType;pub use agents::ToolCallingAgent;pub use orchestration::AgentOrchestrator;pub use orchestration::CommonIntents;pub use orchestration::EchoExecutor;pub use orchestration::ExecutionContext;pub use orchestration::Intent;pub use orchestration::IntentRoute;pub use orchestration::IntentRouter;pub use orchestration::OrchestratedAgent;pub use orchestration::OrchestrationResult;pub use orchestration::OrchestrationStrategy;pub use orchestration::OrchestratorConfig;pub use orchestration::OrchestratorError;pub use orchestration::RoutingDecision;pub use orchestration::Session;pub use orchestration::SessionMessage;pub use orchestration::SessionStore;pub use orchestration::StepExecutionResult;pub use orchestration::StepExecutor;pub use orchestration::StepStatus;pub use orchestration::ToolCallingAgentWrapper;pub use orchestration::Workflow;pub use orchestration::WorkflowError;pub use orchestration::WorkflowExecutor;pub use orchestration::WorkflowResult;pub use orchestration::WorkflowStep;pub use observability::MetricValue;pub use observability::MetricsCollector;pub use observability::MetricsSnapshot;pub use observability::Span;pub use observability::SpanBuilder;pub use observability::SpanContext;pub use observability::SpanEvent;pub use observability::SpanKind;pub use observability::SpanStatus;pub use observability::Tracer;pub use conversation::CompactingConversation;pub use conversation::ConversationConfig;pub use conversation::ManagedConversation;pub use conversation::SummarizationStrategy;pub use hitl::ApprovalHandler;pub use hitl::ApprovalRequest;pub use hitl::ApprovalResult;pub use hitl::ApprovalStatus;pub use hitl::AutoApprovalHandler;pub use hitl::DenyAllHandler;pub use hitl::QueueApprovalHandler;pub use hitl::RiskBasedHandler;pub use hitl::RiskLevel;pub use hitl::TimeoutApprovalHandler;pub use evals::ContainsEvaluator;pub use evals::EvalResult;pub use evals::EvalSuite;pub use evals::Evaluator;pub use evals::ExactMatchEvaluator;pub use evals::JsonMatchEvaluator;pub use evals::RegexEvaluator;pub use evals::SimilarityEvaluator;pub use evals::SuiteResult;pub use evals::SuiteStats;pub use evals::TestCase;pub use evals::TestCaseBuilder;pub use scheduler::CronSchedule;pub use scheduler::IntervalSchedule;pub use scheduler::Job;pub use scheduler::JobBuilder;pub use scheduler::JobStatus;pub use scheduler::OnceSchedule;pub use scheduler::Schedule;pub use scheduler::ScheduleType;pub use pipelines::BranchStep;pub use pipelines::LlmStep;pub use pipelines::ModelTransform;pub use pipelines::Pipeline;pub use pipelines::PipelineBuilder;pub use pipelines::PipelineContext;pub use pipelines::PipelineError;pub use pipelines::PipelineOutput;pub use pipelines::PipelineResult;pub use pipelines::PipelineStep;pub use pipelines::StepOutput;pub use pipelines::TransformChain;pub use pipelines::TransformStep;pub use images::create_variations;pub use images::edit_image;pub use images::generate_image;pub use images::ImageData;pub use images::ImageEditRequest;pub use images::ImageQuality;pub use images::ImageRequest;pub use images::ImageResponse;pub use images::ImageSize;pub use images::ImageStyle;pub use images::ImageVariationRequest;pub use images::ResponseFormat;pub use prompts::CommonPrompts;pub use prompts::PromptBuilder;pub use prompts::PromptConfig;pub use prompts::PromptLibrary;pub use prompts::PromptTemplate;pub use prompts::TemplateError;pub use prompts::TemplateResult;pub use automation::AutomationBuilder;pub use automation::AutomationConfig;pub use automation::AutomationError;pub use automation::AutomationResult;pub use automation::AutomationRunner;pub use automation::AutomationTask;pub use automation::ExecutionRecord;pub use automation::PromptTask;pub use automation::ScheduleConfig;pub use automation::TaskContext;pub use automation::TaskOutput;pub use automation::TaskStatus;pub use futures;pub use tokio_stream;
Modules§
- agents
- Agent framework for building LLM-powered agents.
- automation
- Automation for running workflows on schedules.
- chunking
- Text chunking utilities for RAG pipelines.
- client
- LiteForge Client implementation.
- config
- Configuration for LiteForge.
- conversation
- Conversation management for context window handling.
- error
- Error types for LiteForge.
- evals
- Evaluation framework for testing agent outputs.
- events
- Event system for reactive programming patterns.
- guardrails
- Guardrails for input validation and output filtering.
- hitl
- Human-in-the-Loop (HITL) support for agent approval workflows.
- hooks
- Hook system for intercepting and modifying behavior.
- images
- Image generation functionality.
- knowledge
- Knowledge base for document storage and retrieval.
- mcp
- MCP (Model Context Protocol) support.
- model_
enrichment - Model enrichment: provider detection, capability inference, and source mapping.
- observability
- Observability support for tracing and metrics.
- orchestration
- Multi-agent orchestration support.
- otel_
init - Optional OTel initialisation helpers.
- pipelines
- Pipelines for composable model transformations.
- prompts
- Prompt templates and management.
- rag
- RAG (Retrieval-Augmented Generation) pipeline for LiteForge.
- retry
- Retry utilities for transient API failures.
- scheduler
- Scheduler and triggers for periodic agent execution.
- skills
- Skills for composable AI capabilities.
- streaming
- SSE streaming support for chat completions.
- tools
- Tool framework for function calling with LLMs.
- triggers
- Triggers for event-driven agent execution.
- types
- Type definitions for LiteForge.