Skip to main content

Crate ai_lib_rust

Crate ai_lib_rust 

Source
Expand description

§ai-lib-rust

这是 AI-Protocol 规范的高性能 Rust 参考实现(工作区聚合 crate:ai-lib-core 执行层 + ai-lib-contact 策略层)。

Protocol Runtime for AI-Protocol — workspace facade over ai-lib-core and ai-lib-contact.

Modules§

cache
响应缓存模块:提供可插拔的缓存后端以减少重复 API 调用。
client
统一客户端接口:提供协议驱动的 AI 模型交互入口。
drivers
Provider 驱动抽象层 — 通过 trait 实现多厂商 API 适配的动态分发
error
错误处理模块:提供统一的错误类型和结构化错误上下文。
error_code
V2 标准错误码:定义 13 个规范错误码及其重试/回退语义。
feedback
核心反馈类型:提供 FeedbackSink trait 和多种反馈事件(始终编译)。
pipeline
流水线处理模块:实现流式响应处理的核心算子执行引擎。
plugins
Plugin and middleware system.
protocol
协议规范层:负责加载、验证和管理 AI-Protocol 规范文件。
registry
能力注册表 — 根据 Manifest 声明动态加载和管理运行时模块
resilience
弹性模式模块:提供熔断器和限流器等可靠性保障机制。
structured
Structured output module for ai-lib-rust.
transport
types
类型系统模块:定义基于 AI-Protocol 规范的核心数据类型。
utils
Utility modules

Structs§

AiClient
Unified AI client that works with any provider through protocol configuration.
AiClientBuilder
Builder for creating clients with custom configuration.
CallStats
Per-call statistics for observability and model selection.
CancelHandle
Handle to cancel an in-flight streaming request.
ChatBatchRequest
Batch chat request parameters (developer-friendly, small surface).
ClientMetrics
Snapshot of cumulative client metrics for monitoring and routing.
ErrorContext
Structured error context for better error handling and debugging.
ExecutionMetadata
Metadata returned with every E-layer call for P-layer policy decisions.
ExecutionResult
Successful execution envelope from E: payload plus metadata for P.
ExecutionUsage
Token usage attached to an execution (aligned with driver UsageInfo).
Message
Unified message structure
ToolCall
Tool call (invocation from model)

Enums§

Error
Unified error type for the AI-Protocol Runtime This aggregates all low-level errors into actionable, high-level categories
FeedbackEvent
Typed feedback events (extensible).
MessageRole
Message role
StandardErrorCode
Standard AI-Protocol V2 error code.
StreamingEvent
Unified streaming event enum

Traits§

EndpointExt
FeedbackSink
Feedback sink trait.

Type Aliases§

BoxStream
A unified pinned, boxed stream that emits PipeResult<T>
PipeResult
A specialized Result for pipeline operations
Result
Result type alias for the library