cf-chat-engine-sdk
SDK crate for the chat-engine gear: plugin traits, shared models, and error types used by backend plugin implementations.
The Chat Engine gear is a multi-tenant conversational infrastructure with a plugin-driven backend. Chat Engine owns session state, message trees, streaming, and routing — but zero business logic. All message processing is delegated to backend plugins that implement the ChatEngineBackendPlugin trait defined in this crate.
Purpose
This crate is the contract between Chat Engine and plugin authors. It is intentionally minimal:
- No HTTP, database, or framework dependencies
- Only
async-trait,thiserror,uuid,time,serde,serde_json - Stable API that plugin implementations compile against
Installation
[]
= { = "cf-chat-engine-sdk", = "0.1.0" }
= "0.1"
Core trait: ChatEngineBackendPlugin
Plugins implement this trait to hook into the Chat Engine lifecycle:
use async_trait;
use ;
use Uuid;
All trait methods have default no-op implementations — override only the hooks you need.
Lifecycle hooks
| Method | When Chat Engine calls it |
|---|---|
on_session_type_configured |
A developer registers a new session type bound to this plugin |
on_session_created |
A client creates a new session of this plugin's session type |
on_session_updated |
Session metadata or session-type changes mid-session |
on_message |
A user sends a new message to a session |
on_message_recreate |
A user requests regeneration of an existing assistant message (new variant) |
on_session_summary |
Session summary is requested or context overflow triggers summarization |
health_check |
Chat Engine polls plugin readiness |
Domain types
Re-exported at crate root:
Entities
Session— session record (tenant, user, lifecycle state, metadata)SessionType— registered session type referencing a pluginMessage— message node in the immutable conversation treeMessageRole—User|Assistant|SystemCapability,CapabilityValue— capability model for sessionsVariantInfo— variant metadata (index, total, is_active)
Configuration enums
MemoryStrategy—Full|SlidingWindow { window_size }|Summarized { recent_messages_to_keep }RetentionPolicy—None|AgeBased { max_age_days }|CountBased { max_message_count }
Streaming
StreamingEvent— tagged union:Start|Chunk|Complete|ErrorStreamingStartEvent,StreamingChunkEvent,StreamingCompleteEvent,StreamingErrorEvent
Plugin call contexts
PluginCallContext— tenant, user, plugin instance id, session type, plugin config, enabled capabilitiesSessionPluginCtx— session-scoped call wrappingPluginCallContextMessagePluginCtx— message-scoped call including message history
Health
HealthStatus—Healthy|Degraded|Unhealthy
Error model
Chat Engine inspects the variant to decide whether to retry, surface the error to the client, or circuit-break.
Design principles
- Backend authority — Chat Engine stays out of business logic; plugins own response generation
- Immutable tree — messages are never mutated; variants are new siblings
- Zero business logic in the SDK — the SDK contains only data types and the plugin trait
- Stateless-friendly — all state passed through context structs; plugins should not hold per-session state unless they own it
Examples in the tree
Two first-party plugin implementations live in the main chat-engine crate and serve as reference implementations:
chat_engine::infra::webhook_compat::WebhookCompatPlugin— forwards events to legacy HTTP webhook backendschat_engine::infra::llm_gateway::LlmGatewayPlugin— integrates with the internal LLM Gateway service
License
Same as the parent workspace.