agora.fleet.distiller

Hierarchical map-reduce distillation for large files.

When an agent does read_file on a 67 KB knowledge-base page, the result overflows the model’s context and the task fails. This module shrinks such content before it reaches the agent’s message history:

  1. Split the source into buckets that fit comfortably in one LLM call.

  2. For each bucket, run a focused extraction prompt that keeps only the facts relevant to the current task.

  3. Concatenate the per-bucket extracts.

  4. If the concatenated result still exceeds the target size, recurse — treating the merged extracts as the new input.

  5. Cap recursion depth so a pathologically large source can’t run forever.

The LLM used for distillation is the same model the agents use, so no extra dependencies and the token budget is per-call, not per-source.

Module Attributes

DEFAULT_TARGET_CHARS

Roughly the size that leaves room for the task prompt + tool schemas.

DEFAULT_BUCKET_CHARS

Per-bucket input size.

DEFAULT_MAX_ROUNDS

Safety cap.

Functions

distill(text, *, focus, llm, model[, ...])

Recursively shrink text while preserving information relevant to focus.

make_distill_fn(llm, *, model[, ...])

Return an async (text, focus) -> str closure bound to an LLM + model.

agora.fleet.distiller.DEFAULT_BUCKET_CHARS = 4000

Per-bucket input size. Below num_ctx by a wide margin so one call is reliable.

agora.fleet.distiller.DEFAULT_MAX_ROUNDS = 4

Safety cap. Recursion that hasn’t converged by round 4 fallback-truncates.

agora.fleet.distiller.DEFAULT_TARGET_CHARS = 6000

Roughly the size that leaves room for the task prompt + tool schemas.

async agora.fleet.distiller.distill(text, *, focus, llm, model, target_chars=6000, bucket_chars=4000, max_rounds=4)[source]

Recursively shrink text while preserving information relevant to focus.

Returns a string of length <= target_chars (approximately — the last LLM call may overshoot). On internal failure (LLM errors, empty output) falls back to head-truncation with a [...truncated...] marker so the caller always receives something usable.

agora.fleet.distiller.make_distill_fn(llm, *, model, target_chars=6000, bucket_chars=4000, max_rounds=4)[source]

Return an async (text, focus) -> str closure bound to an LLM + model.