Skip to content

History Processor

chimera.context.history provides composable processors for transforming conversation history before sending it to the LLM.

ClassDescription
HistoryProcessorAbstract base class — implement process(messages)
TruncateProcessorKeep only the last N messages
PruneProcessorReplace old tool result content with [pruned]
CompressProcessorCompress old messages into a summary, keep recent ones intact
CompositeProcessorChain multiple processors in sequence
from chimera.context.history import TruncateProcessor, PruneProcessor, CompositeProcessor
# Keep last 20 messages, prune old tool results beyond the 3 most recent
processor = CompositeProcessor([
PruneProcessor(keep_last_n_results=3),
TruncateProcessor(max_messages=20),
])
cleaned = processor.process(messages)

Keeps only the last N messages, discarding everything older.

proc = TruncateProcessor(max_messages=15)

Replaces old tool result content with [pruned], preserving structure.

proc = PruneProcessor(keep_last_n_results=5)

Compresses old messages into a summary, keeping recent ones intact. Uses simple concatenation and truncation (no LLM call).

proc = CompressProcessor(keep_recent=5, max_summary_tokens=500)

Chains multiple processors — each processor’s output becomes the next input.

proc = CompositeProcessor([PruneProcessor(), TruncateProcessor()])

Subclass HistoryProcessor and implement process():

from chimera.context.history import HistoryProcessor
class DropSystemProcessor(HistoryProcessor):
def process(self, messages):
return [m for m in messages if m.role != "system"]