Expand description
§cognis
v2-beta umbrella crate. Re-exports cognis-core, cognis-graph,
cognis-llm, cognis-rag and adds:
agent— the standard ReAct agent loop.backend— agent workspace (in-memory or sandboxed real FS).middleware— composable LLM-call hooks (retry, fallback, caching, redaction, summarization, …).retrievers— LLM-driven retrievers (multi-query, contextual compression).
Re-exports§
pub use agent::default_react_graph;pub use agent::default_react_graph_with_limits;pub use agent::Agent;pub use agent::AgentBuilder;pub use agent::AgentHealth;pub use agent::AgentLifecycle;pub use agent::AgentPlugin;pub use agent::AgentResponse;pub use agent::AgentState;pub use agent::AgentStateUpdate;pub use agent::Buffer;pub use agent::ClosurePlugin;pub use agent::ConversationMode;pub use agent::EntityExtractor;pub use agent::EntityFact;pub use agent::EntityMemory;pub use agent::Fact;pub use agent::FactExtractionInput;pub use agent::FactExtractor;pub use agent::FactExtractorBuilder;pub use agent::FactKind;pub use agent::FnPlugin;pub use agent::HybridMemory;pub use agent::KnowledgeGraphMemory;pub use agent::LifecyclePlugin;pub use agent::LlmExtractor;pub use agent::LlmExtractorBuilder;pub use agent::Memory;pub use agent::OnStart;pub use agent::PluginRegistry;pub use agent::SummaryBufferMemory;pub use agent::SummaryMemory;pub use agent::ThinkNode;pub use agent::TokenBufferMemory;pub use agent::ToolDispatchNode;pub use agent::Triple;pub use agent::TripleExtractor;pub use agent::VectorMemory;pub use agent::Window;pub use agent::Workflow;pub use agent::WorkflowState;pub use agent::WorkflowStateUpdate;pub use agent_bus::AgentBus;pub use agent_bus::SubscribeError;pub use agent_bus::Subscription;pub use agent_events::AgentEvent;pub use agent_events::AgentEventBus;pub use agent_events::EventSubscription;pub use agent_events::DEFAULT_EVENTS_TOPIC;pub use backend::Backend;pub use backend::Blob;pub use backend::GrepHit;pub use backend::InMemoryStateBackend;pub use backend::InMemoryStorageBackend;pub use backend::LocalFsStorageBackend;pub use backend::MemoryBackend;pub use backend::SandboxedFsBackend;pub use backend::StateBackend;pub use backend::StorageBackend;pub use conversation::summarize;pub use conversation::turns_from_messages;pub use conversation::ConversationSummary;pub use conversation::ConversationTurn;pub use eval::Contains;pub use eval::EvalCase;pub use eval::EvalReport;pub use eval::EvalRow;pub use eval::EvalRunner;pub use eval::Evaluator;pub use eval::ExactMatch;pub use eval::LlmJudge;pub use history::HistoryStore;pub use history::HistoryTrimmer;pub use history::InMemoryHistory;pub use history::RunnableWithMessageHistory;pub use history::SessionKey;pub use history::SessionResolver;pub use middleware::AlwaysSkip;pub use middleware::ApprovalGate;pub use middleware::AutoApproveAll;pub use middleware::AutoRejectAll;pub use middleware::CapMessageLength;pub use middleware::ChatApproval;pub use middleware::ChatApprover;pub use middleware::ContextEditing;pub use middleware::ContextInjection;pub use middleware::ContextProvider;pub use middleware::DropMatching;pub use middleware::EditPolicy;pub use middleware::EmulatorSource;pub use middleware::FilesystemMiddleware;pub use middleware::FixedRecovery;pub use middleware::FnContextProvider;pub use middleware::FnRecovery;pub use middleware::FnToolCallPatcher;pub use middleware::HumanDecision;pub use middleware::HumanInTheLoop;pub use middleware::HumanResponder;pub use middleware::LimitTools;pub use middleware::MapEmulator;pub use middleware::Middleware;pub use middleware::MiddlewareCtx;pub use middleware::MiddlewarePipeline;pub use middleware::ModelCallLimit;pub use middleware::ModelFallback;pub use middleware::ModelRetry;pub use middleware::Next;pub use middleware::PatchToolCalls;pub use middleware::PiiRedactor;pub use middleware::PipelinedClient;pub use middleware::Planning;pub use middleware::PromptCaching;pub use middleware::RateLimit;pub use middleware::RateLimiter;pub use middleware::Recovery;pub use middleware::RecoveryStrategy;pub use middleware::RegexRedactor;pub use middleware::SubagentMiddleware;pub use middleware::SubagentRouter;pub use middleware::Summarization;pub use middleware::TodoMiddleware;pub use middleware::TokenBucket;pub use middleware::TokenCounter;pub use middleware::ToolAllowList;pub use middleware::ToolCallLimit;pub use middleware::ToolCallPatcher;pub use middleware::ToolDenyList;pub use middleware::ToolEmulator;pub use middleware::ToolFilter;pub use middleware::ToolRetry;pub use middleware::ToolRetryClassifier;pub use middleware::ToolSelection;pub use middleware::WorkspaceLister;pub use multi_agent::sort_by_priority;pub use multi_agent::AgentMessage;pub use multi_agent::Consensus;pub use multi_agent::HandoffStrategy;pub use multi_agent::Hierarchical;pub use multi_agent::InMemoryMessageBus;pub use multi_agent::MessageBus;pub use multi_agent::MultiAgentOrchestrator;pub use multi_agent::ParallelVote;pub use multi_agent::Priority;pub use multi_agent::RoundRobin;pub use multi_agent::Sequential;pub use multi_agent::Supervisor;pub use observers::TracingObserver;pub use retrievers::ContextualCompressionRetriever;pub use retrievers::MultiQueryRetriever;pub use retrievers::RerankingRetriever;pub use retrievers::SearchSpec;pub use retrievers::SelfQueryRetriever;pub use retrievers::TimeWeightedRetriever;pub use session::InMemorySessionStore;pub use session::Session;pub use session::SessionStore;pub use session::SessionStoreHandle;pub use skills::AllSkills;pub use skills::BuiltSkill;pub use skills::KeywordSelector;pub use skills::Skill;pub use skills::SkillBuilder;pub use skills::SkillRegistry;pub use skills::SkillSelector;pub use telemetry::InMemoryTelemetry;pub use telemetry::TelemetryEvent;pub use telemetry::TelemetryHandle;pub use telemetry::TelemetrySink;pub use telemetry::TelemetrySnapshot;pub use tools::register_filesystem_tools;pub use tools::AllowList;pub use tools::ApprovalGatedTool;pub use tools::Approver;pub use tools::AutoApprove;pub use tools::CachedTool;pub use tools::Calculator;pub use tools::CodeSanitizer;pub use tools::Decision;pub use tools::DotPathEngine;pub use tools::ExecutionPlan;pub use tools::FileEditTool;pub use tools::FileExistsTool;pub use tools::FileGlobTool;pub use tools::FileGrepTool;pub use tools::FileListTool;pub use tools::FileReadTool;pub use tools::FileWriteTool;pub use tools::HumanTool;pub use tools::JsonQueryTool;pub use tools::OrchestratorResult;pub use tools::PythonReplConfig;pub use tools::PythonReplTool;pub use tools::QueryEngine;pub use tools::RejectAll;pub use tools::RetrieverTool;pub use tools::SanitizationError;pub use tools::ShellTool;pub use tools::StaticResponder;pub use tools::SubAgentTool;pub use tools::ToolHumanResponder;pub use tools::ToolOrchestrator;pub use tools::ToolStep;pub use cognis_core;pub use cognis_graph;pub use cognis_llm;pub use cognis_rag;
Modules§
- agent
- Thin agent layer: AgentState + Memory + AgentBuilder + Agent.
- agent_
bus - Topic-based pub/sub for inter-agent broadcast.
- agent_
events - Typed lifecycle events layered over
AgentBus. - backend
- Agent workspace backend: file ops + sandboxing.
- conversation
- Typed value types over
Vec<Message>history. - eval
- Lightweight evaluation harness for any
Runnable<I, O>. - history
RunnableWithMessageHistory— wrap aRunnable<Vec<Message>, Message>so it carries conversation history per session ID.- middleware
- Agent middleware — hooks that wrap an LLM call.
- multi_
agent - Multi-agent orchestration — dispatch a single user request across a fleet of agents and merge their outputs via a pluggable handoff strategy.
- observers
Observerimplementations that bridge cognis’s [Event] stream to the surrounding ecosystem.- prelude
- Common imports for v2 user code building agents.
- presets
- Named
AgentBuilderpresets for common agent shapes. - retrievers
- LLM-driven retrievers — live in
cognis(notcognis-rag) because they depend oncognis-llm’sClient. - session
- Session — a long-lived conversation with metadata, optional expiry, and a pluggable backing store.
- skills
- Skills — coherent bundles of (system-prompt fragment, tools, activation predicate) that the agent installs at build time.
- telemetry
- Telemetry — typed counters / events emitted alongside agent runs.
- tools
- Built-in tools shipped with
cognis.
Structs§
- Active
Snapshot - Snapshot of one active task at an interrupt boundary. Used for point-of-interrupt resume.
- Aggregated
- Output of
StreamAggregator::finalize. - Audit
Entry - One audit row.
- Audit
LogObserver - Bridges cognis
Events into anAuditLog. - Caching
Retriever - Wraps any
Runnable<String, Vec<Document>>so identical query strings return cached document lists. - Char
Tokenizer - Trivial char-as-token implementation. Conservative upper bound on real tokenizer counts; useful as a default for budgeting.
- Chat
Options - Per-call options that override
ClientConfigdefaults. - Chat
Response - Response payload from
chat_completion. - Client
- Top-level LLM client. Cheap to clone.
- Client
Builder - Fluent builder for
Client. - Compiled
Graph - A validated, ready-to-run graph. Cheap to clone (the underlying nodes
are
Arc<dyn Node<S>>). - Compressor
Pipeline - Chain N doc-list transformers back-to-back. Each stage’s output feeds the next.
- Cross
Encoder Reranker - Wraps an inner retriever, then reranks its hits via a
CrossEncoder. - Dedup
Vector Store - A
VectorStoredecorator that silently skips documents whose normalised content fingerprint is already in the seen-set. - Document
- A piece of text that flows through loaders → splitters → embeddings → vector store → retrievers.
- Event
Stream - A stream of structured events. Same shape as
RunnableStream<Event>, but named separately to make stream-of-events vs stream-of-output distinguishable at the type level. - Extensions
- A typed map indexed by
TypeId. EachT: Any + Send + Sync + 'staticcan have at most one value stored. - Fake
Embeddings - Produces deterministic
dim-length f32 vectors via repeated hashing of the input text. Same input always yields the same vector. - Filter
- Metadata filter applied to similarity search.
- FnCross
Encoder - Closure-backed cross-encoder. Useful for tests; in production use a real impl that calls a hosted scorer.
- FnTokenizer
- Closure-backed tokenizer.
- Graph
- A graph under construction. Generic over the state type
S. Convert to an executable [CompiledGraph] via.compile(). - Graph
Metrics - Per-node execution counts and error counts.
- Graph
Snapshot - Serializable shape of a
CompiledGraph<S>. - InMemory
Audit Log - In-process audit log.
- InMemory
Checkpointer - Stores
(run_id, namespace, step) -> Sin a Mutex-protected HashMap. State must beClonebecause saving stores a clone and loading returns one. - InMemory
Docstore - In-process
Docstorebacked by aMutex<HashMap>. - InMemory
Record Manager - In-process record manager. Suitable for tests and single-process apps.
- InMemory
Vector Store - Linear-scan in-memory vector store.
- Incremental
Report - Result of an
IndexingPipeline::run_incrementalcall. - Loader
- Reconstructs runnables from definitions. Caller registers factories
by name for each
Lambda/Opaquekind they expect to load. - Long
Context Reorder - Reorder retrieved documents so the most-relevant ones sit at the head and tail of the list. LLMs attend better to ends than to the middle of long contexts; this is the classic “lost in the middle” fix.
- Metrics
Observer - Observer that maintains a
GraphMetricsunder aMutex. - Multi
Vector Indexer - Indexes a parent doc under N text representations.
- Multi
Vector Retriever - One type that handles both indexing (multi-rep per parent) and retrieval (parent-doc).
- NodeCtx
- Per-superstep context handed to every
Node::executecall. Carries run-correlation metadata and the activeRunnableConfig. The lifetime is the superstep — don’t hold across awaits beyondexecutereturning. - NodeOut
- Output of a node’s
execute: a typed state delta + where to go next. - Node
Retry Policy - Per-task retry policy. The engine wraps
Node::executecalls in a retry loop when the node returns aSomepolicy and the call fails with acognis_core::CognisErrorwhoseis_retryable()is true. - Node
Timing - One node’s timing aggregate.
- Ollama
Embeddings - Ollama embeddings client.
- OpenAI
Embeddings - OpenAI Embeddings API client.
- Parent
Document Retriever - Wraps a vector index of small chunks + a doc-id keyed parent docstore.
- Profiling
Observer - Per-node timing aggregator. Pairs
OnNodeStart/OnNodeEndevents keyed by(run_id, step, node)to compute durations. - Query
Translator Retriever query → translator → retriever.- Runnable
Config - Per-invocation configuration. Defaults are sensible; override only what you need.
- Runnable
Stream - A stream of
Result<O>items — the canonical output stream type forRunnable::stream. WrapsPin<Box<dyn Stream>>for trait-object flexibility, with helper combinators on the wrapper. - Search
Result - One document returned by a similarity search.
- Stream
Aggregator - Accumulates a streaming response into a final
Messageplus aggregated metadata. Chunk ordering matters for text content and for tool-call argument deltas — feed chunks in the order they arrive. - Stream
Chunk - One chunk of a streaming response.
- Subgraph
- Adapter
Nodethat runs a child graph and projects its state into a parent update. - Tool
Call - One tool invocation requested by the LLM in an
AiMessage. - Tool
Definition - Serializable form of a tool — what gets sent to the LLM API.
- Tool
Registry - HashMap-backed tool registry. The agent layer uses this to dispatch tool calls returned by the LLM.
- Usage
- Token usage report.
- Usage
Tracker - Aggregates
Usageacross manyChatResponses. Cheap to share viaArc.
Enums§
- Audit
Kind - What an audit entry records.
- Cognis
Error - All errors produced by cognis-core and downstream v2 crates.
- Distance
- How to score similarity between two vectors. Each variant carries
its mathematical meaning into
Distance::computeandDistance::similarity. - Event
- A structured event emitted by
stream_events()— exposes per-step graph activity, tool calls, token deltas, and errors. - Goto
- Routing instruction returned by a node, telling the engine which node(s) to schedule next. Branching/looping is data: a node decides at runtime where to send execution.
- Message
- A single message in an LLM conversation.
- Provider
- Closed set of supported providers.
- Runnable
Definition - Serializable description of a runnable’s shape.
- Tool
Input - Input to a tool’s
_runmethod. - Tool
Output - Output from a tool’s
_runmethod.
Traits§
- Audit
Log - Pluggable audit log.
- Base
Tool - Tier-1 tool trait. The most general contract — manual JSON schema,
serde_json::Valuearg deserialization is the tool’s responsibility. - Checkpointer
- Trait for storing & retrieving graph state at superstep boundaries.
- Cross
Encoder - Scores
(query, doc)pairs. - Docstore
- Pluggable id-keyed document store.
- Embeddings
- A model that converts text into vector embeddings. Implementations
MUST return vectors of consistent dimensionality across calls — the
dimensions()accessor (when known) reports it. - Graph
State - Trait implemented by structs that hold graph state. The
Updatetype is generated by#[derive(GraphState)]and represents a partial delta;applymerges a delta into self via per-field reducers. - Json
Schema - A type which can be described as a JSON Schema document.
- LLMProvider
- Trait every concrete provider implementation satisfies. The
Clientholds anArc<dyn LLMProvider>and dispatches through it. - Node
- The unit of computation in a graph. Async, takes a
&Ssnapshot of state - Observer
- Pluggable event sink. Multiple observers can subscribe to a single run.
- Record
Manager - Per-key indexing state. Each
keyis a stable identifier for a document (path, URL, primary key); thefingerprintis whatever the caller computes from the doc — usually a content hash. - Runnable
- The unified contract every cognis primitive implements.
- Schema
Based Tool - Tier-2 tool: typed args + auto-derived JSON Schema. Implementers only
write
execute_typed; deserialization, schema, and the Tool surface come for free via the blanket impl below. - Serializable
- Trait runnables implement to participate in dump/load. Default is
Opaque { name = type name }— override to capture useful structure. - Tokenizer
- Counts tokens in a piece of text.
- Tool
- Tier-1 tool trait. The most general contract — manual JSON schema,
serde_json::Valuearg deserialization is the tool’s responsibility. - Vector
Store - A vector store: holds documents + their embeddings, supports add + similarity search + delete.
Functions§
- node_fn
- Build a
NodeFnfrom a closure. The closure receives(&S, &NodeCtx)and returnsFuture<Output = Result<NodeOut<S>>>. - normalized_
fingerprint - Normalise
text(lowercase + collapse whitespace) then fingerprint with FNV-1a 128-bit. Two pieces of text that differ only in case or spacing produce the same fingerprint and are treated as duplicates.
Type Aliases§
- Result
- Result alias used throughout cognis.
Derive Macros§
- Graph
State #[derive(GraphStateV2)]— v2-shape state derive that emits a typed sibling<Name>Updatestruct and animpl GraphState for <Name>. Use in v2 code via the re-exportcognis_core::GraphState(the rename happens in cognis-core’s lib.rs in Plan #2).- Json
Schema