Skip to main content

Module compact_directive

Module compact_directive 

Source
Expand description

Store for the agent-driven conversation-compaction directive (#1570 P1).

The MCP server cannot rewrite the client’s conversation — only the proxy sees the messages. ctx_session(action="compact") therefore records a directive; the proxy applies it to the requests of the app session that armed it (cache-safe, live-suffix only). Restore is lossless by construction: the client resends the full original history each turn, so clearing the directive is enough.

One proxy carries many app sessions (the launching app’s x-leanctx-session-id header, LEAN_CTX_SESSION_ID for the agent’s MCP server). Every directive belongs to exactly one of them: it is stored under that session, applied only to requests naming it, and a request that names no valid session gets none (fail closed). The proxy also notes each session it carries, so ctx_session compact can say honestly whether a proxy would apply the directive at all.

Structs§

CompactDirective

Functions§

clear
Drop the directive of session — its next request carries the full original history again, so this alone is a complete, lossless restore.
create
Create a new directive for session. Fails when the session has no valid id, or when its previous one was created less than MIN_INTERVAL_SECS ago (rate limit — nothing is ever blocked, the agent simply keeps its current, already-compacted context).
is_carried
Whether a proxy carried a request of session within the carried window.
load_active
The directive of session when it exists and is younger than TTL_SECS.
note_carried
The proxy carried a request of session now. Best effort and throttled: a failed note only makes a later compact reply say “no proxy”.
save