pub struct BriefBuilder { /* private fields */ }Expand description
Assembles a Brief from registered Sources.
See the module-level docs for usage. The default tokenizer is
CharApproxTokenizer (≈ 4 chars per token); the default governance is
NoOpGovernance; the default strategy is PruneStrategy::default
(== PruneStrategy::ImportanceFirst).
Implementations§
Source§impl BriefBuilder
impl BriefBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a fresh builder with no sources, the default
CharApproxTokenizer, NoOpGovernance, the default
TokenBudget (8000 total / 1024 reserved), and
PruneStrategy::ImportanceFirst.
Sourcepub fn source(self, source: Arc<dyn Source>) -> Self
pub fn source(self, source: Arc<dyn Source>) -> Self
Register a Source. Duplicate SourceIds are rejected at
BriefBuilder::build time, not here.
Sourcepub fn governance(self, governance: Arc<dyn Governance>) -> Self
pub fn governance(self, governance: Arc<dyn Governance>) -> Self
Swap the Governance hook. Defaults to NoOpGovernance.
Sourcepub fn tokenizer(self, tokenizer: Arc<dyn Tokenizer>) -> Self
pub fn tokenizer(self, tokenizer: Arc<dyn Tokenizer>) -> Self
Swap the Tokenizer. Defaults to CharApproxTokenizer.
Sourcepub fn budget(self, budget: TokenBudget) -> Self
pub fn budget(self, budget: TokenBudget) -> Self
Set the TokenBudget used for pruning.
Sourcepub fn strategy(self, strategy: PruneStrategy) -> Self
pub fn strategy(self, strategy: PruneStrategy) -> Self
Set the PruneStrategy. Defaults to
PruneStrategy::ImportanceFirst.
Sourcepub fn sources(&self) -> &[Arc<dyn Source>]
pub fn sources(&self) -> &[Arc<dyn Source>]
Borrowed view of the configured sources. Useful for tests.
Sourcepub fn current_budget(&self) -> &TokenBudget
pub fn current_budget(&self) -> &TokenBudget
The configured budget.
Sourcepub async fn build(&self, ctx: &BriefContext) -> Result<Brief>
pub async fn build(&self, ctx: &BriefContext) -> Result<Brief>
Assemble the Brief for ctx.
Steps:
- Reject duplicate
SourceIds. - Fan out to every source in parallel via
join_all. Per-source errors surface in step 4 — fan-out itself never fails. - Tokenize each surviving
Contributionusing the activeTokenizer(source-providedestimated_tokensis treated as a hint only). - Apply budget pruning via
apply_budget. - Assemble draft
Brief(system concatenation, message order preserved within priority, tools collected). - Run
Governance::review. Allow / Redacted advance; Rejected surfaces asBriefError::Rejected. - Build the
BriefReceiptwith per-source stats, drops, and timings.
On any fatal source error (anything other than
SourceError::Skipped), build returns
BriefError::Source. Skipped sources are silently treated as
zero contributions.