ExAgent.Compaction.Capability (ExAgent v2.1.0)

View Source

A capability that compacts only the projection sent by before_model_request.

It accepts the current request_messages override, or the full authoritative history when no override exists, so it can compact growth within a run without undoing an earlier capability's redaction. It never changes messages or first_new_message_index. Errors, no-change and invalid projections leave the incoming state unchanged; stream cancellation is propagated.

Custom compactors retain compact/2, but must preserve original instructions, the latest user request and complete, unmodified tool exchanges. They must not insert new System instructions. With the built-in Summary/default counter, advertised function/output tool schemas also contribute to the rough estimate. A supplied :token_counter retains its one-argument interface and owns its entire estimate; capture tool definitions in its closure when needed.

Add it to an agent's :capabilities:

%ExAgent.Compaction.Capability{
  compactor: ExAgent.Compaction.Summary,
  opts: [threshold_tokens: 6000, keep_recent: 8, summarize: &my_summarize/1]
}

Summary

Functions

after_model_request(cap, state)

Callback implementation for ExAgent.Capability.after_model_request/2.

after_tool_execute(cap, ctx, tool_call, result)

Callback implementation for ExAgent.Capability.after_tool_execute/4.

before_tool_execute(cap, ctx, tool_call)

Callback implementation for ExAgent.Capability.before_tool_execute/3.