Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cognis.vasanth.xyz/llms.txt

Use this file to discover all available pages before exploring further.

cognis-core is the smallest, most stable crate. Everything else depends on it; it depends on nothing internally. If you’re building a primitive that the rest of the workspace should be able to compose, this is where the trait goes.

Crate metadata

FieldValue
Latest version0.3
docs.rsdocs.rs/cognis-core
Repo pathcrates/cognis-core
Default featuresnone

Modules at a glance

ModuleWhat
runnableRunnable<I, O> trait, RunnableConfig.
runnable_extRunnableExtpipe, with_max_retries, with_timeout, with_fallback, with_memory_cache, each.
composeBranch, Parallel, Each, Lambda, Passthrough, Pipe. Plus the lambda and pipe helpers.
wrappersRetry, RetryPolicy, Timeout, Fallback, Cache, MemoryCache, CacheBackend, Bind, Configurable, Assign.
messageMessage, HumanMessage, AiMessage, SystemMessage, ToolMessage, ToolCall.
contentContentPart, ImageSource, AudioSource.
promptsChatPromptTemplate, PromptTemplate, FewShotTemplate, Role.
output_parsersOutputParser, StructuredOutputParser, OutputFixingParser, RetryParser, JsonParser, JsonExtractor, XmlParser, BooleanParser, NumberedListParser, CommaListParser, StringParser.
callbacksCallbackHandler, CallbackManager, HandlerObserver, BuiltHandler, HandlerBuilder.
streamEvent, EventStream, Observer, RunnableStream.
toolsBaseTool (re-export of Tool). The trait shape lives in cognis-llm.
tokenizerTokenizer, CharTokenizer, FnTokenizer.
loadersLoader trait — used by cognis-rag.
errorCognisError, Result.

Key types

Runnable

#[async_trait]
pub trait Runnable<I, O>: Send + Sync
where I: Send + 'static, O: Send + 'static
{
    async fn invoke(&self, input: I, config: RunnableConfig) -> Result<O>;
    async fn batch(&self, inputs: Vec<I>, config: RunnableConfig) -> Result<Vec<O>> { /* default */ }
    async fn stream(&self, input: I, config: RunnableConfig) -> Result<RunnableStream<O>> { /* default */ }
    async fn stream_events(&self, input: I, config: RunnableConfig) -> Result<EventStream> { /* default */ }
    fn name(&self) -> &str { /* type_name */ }
    fn input_schema(&self) -> Option<serde_json::Value> { None }
    fn output_schema(&self) -> Option<serde_json::Value> { None }
}

RunnableConfig

pub struct RunnableConfig {
    pub recursion_limit: u32,
    pub max_concurrency: usize,
    pub tags: Vec<String>,
    pub metadata: serde_json::Value,
    pub observers: Vec<Arc<dyn Observer>>,
    pub run_id: Uuid,
    pub cancel_token: Option<tokio_util::sync::CancellationToken>,
    pub deadline: Option<Instant>,
    pub extras: Extensions,
    pub parent_run_id: Option<Uuid>,
}
Builder methods: new, with_recursion_limit, with_max_concurrency, with_observer, with_tag, with_cancel_token, with_parent_run_id. Plus is_cancelled and emit.

Event

pub enum Event {
    OnStart { runnable, run_id, input },
    OnNodeStart { node, step, run_id },
    OnNodeEnd { node, step, output, run_id },
    OnLlmToken { token, run_id },
    OnToolStart { tool, args, run_id },
    OnToolEnd { tool, result, run_id },
    OnError { error, run_id },
    OnEnd { runnable, run_id, output },
    OnCheckpoint { step, run_id },
    Custom { kind, payload, run_id },
}

Message

pub enum Message {
    Human(HumanMessage),
    Ai(AiMessage),
    System(SystemMessage),
    Tool(ToolMessage),
}
Constructors: Message::human, Message::ai, Message::system, Message::tool, plus *_with_parts variants.

CognisError

pub enum CognisError {
    ProviderError { provider, message, status },
    RateLimited { retry_after_ms },
    Tool { name, reason },
    ToolValidationError(String),
    OutputParse { raw, error },
    GraphInterrupted { kind, step, .. },
    RecursionLimit,
    Cancelled,
    DeadlineExceeded,
    Other(String),
    // …
}
Result<T> = std::result::Result<T, CognisError>. Cross-crate errors wrap via From.

docs.rs

Browse the full API at docs.rs/cognis-core. Every public type, trait, and function has rustdoc.

See also

Runnables

The conceptual page on the trait.

Messages

What flows through chat-shaped Runnables.

Structured output

StructuredOutputParser, OutputFixingParser, RetryParser.