cel_brief/lib.rs
1//! cel-brief — Per-turn LLM briefing layer.
2//!
3//! See [`cellar-cel-brief.md`] for the full implementation plan. This crate is
4//! the per-turn briefing layer that sits between an agent's state and the LLM:
5//! every turn, sources contribute [`source::Contribution`]s to a budgeted,
6//! governed [`types::Brief`].
7//!
8//! **Status (Phases 1 + 2 + 3 + 4):** all core types, traits, sources,
9//! governance, and builder are shipped.
10//!
11//! **Phase 1** — core types ([`types::Brief`], [`types::BriefMessage`],
12//! [`types::Role`], [`types::BriefContext`], [`types::TokenBudget`],
13//! [`types::Priority`], [`types::ToolSchema`], [`types::ImageData`],
14//! [`types::SourceId`]) and the [`source::Source`] trait + supporting
15//! types ([`source::Contribution`], [`source::ContributionContent`],
16//! [`source::SourceError`]).
17//!
18//! **Phase 2** — [`builder::BriefBuilder`], [`tokenizer::Tokenizer`]
19//! (default [`tokenizer::CharApproxTokenizer`]; opt-in
20//! [`tokenizer::TiktokenCl100k`] behind the `tiktoken` feature),
21//! [`budget::PruneStrategy`] + budget enforcement, full
22//! [`receipt::BriefReceipt`].
23//!
24//! **Phase 3** — built-in [`sources::SystemPromptSource`],
25//! [`sources::UserMessageSource`], [`sources::ToolCatalogSource`],
26//! [`sources::HistorySource`] + [`sources::HistoryStore`] under default
27//! features; [`sources::MemorySource`] behind the `memory` feature;
28//! [`sources::PerceptionSource`] + [`sources::PerceptionSnapshot`] behind
29//! the `perception` feature.
30//!
31//! **Phase 4** — [`governance::Governance`] trait with
32//! [`governance::NoOpGovernance`] default, [`governance::GovernanceVerdict`]
33//! enum, and the [`receipt::RedactionRecord`] surface that
34//! [`governance::GovernanceVerdict::Redacted`] returns.
35//!
36//! ## Quick start
37//!
38//! ```no_run
39//! # use std::sync::Arc;
40//! # use cel_brief::{BriefBuilder, BriefContext, TokenBudget};
41//! # async fn example() -> Result<(), cel_brief::BriefError> {
42//! let builder = BriefBuilder::new()
43//! .budget(TokenBudget::new(8000, 1024));
44//! // .source(Arc::new(MySource)) ...
45//!
46//! let ctx = BriefContext::new(TokenBudget::default())
47//! .with_user_message("hi");
48//! let brief = builder.build(&ctx).await?;
49//! println!("brief: {} messages, {} tokens",
50//! brief.messages.len(), brief.receipt.total_tokens);
51//! # Ok(())
52//! # }
53//! ```
54//!
55//! [`cellar-cel-brief.md`]: file:///Users/dimitriospagkratis/.claude/plans/cellar-cel-brief.md
56
57#![deny(missing_docs)]
58#![warn(rust_2018_idioms)]
59
60pub mod budget;
61pub mod builder;
62pub mod error;
63pub mod governance;
64pub mod receipt;
65pub mod source;
66pub mod sources;
67pub mod tokenizer;
68pub mod types;
69
70pub use budget::{PruneStrategy, WeightedContribution};
71pub use builder::BriefBuilder;
72pub use error::{BriefError, Result};
73pub use governance::{Governance, GovernanceError, GovernanceVerdict, NoOpGovernance};
74pub use receipt::{
75 BriefReceipt, DropReason, DroppedContribution, RedactionRecord, SourceStats, Timings,
76};
77pub use source::{Contribution, ContributionContent, Source, SourceError};
78pub use sources::{
79 HistoryEntry, HistorySource, HistoryStore, SystemPromptSource, ToolCatalogSource,
80 UserMessageSource,
81};
82#[cfg(feature = "memory")]
83pub use sources::{MemoryQueryStrategy, MemorySource};
84#[cfg(feature = "perception")]
85pub use sources::{PerceptionError, PerceptionMode, PerceptionSnapshot, PerceptionSource};
86pub use tokenizer::{CharApproxTokenizer, Tokenizer};
87pub use types::{
88 Brief, BriefContext, BriefMessage, ImageData, Priority, Role, SourceId, TokenBudget, ToolSchema,
89};
90
91#[cfg(feature = "tiktoken")]
92pub use tokenizer::TiktokenCl100k;