Memory Under Pressure

PentAGI's recovery loop can keep a Subtask running, but a long-running agent eventually faces another failure surface: the conversation becomes too large, too provider-specific, or too full of raw tool output to fit safely into the next request. This chapter follows how PentAGI separates live context, structured message history, summarized history, reusable knowledge, and episodic memory. The practical judgment is not whether the system “remembers everything,” but whether it preserves the right information for the next action without disguising loss as recall.

A message chain is a protocol structure, not a transcript

Each agent interaction is persisted as a typed message chain. In a simple chat, a reader can imagine the history as alternating user and assistant paragraphs. PentAGI's chains are more structured because an AI message may contain tool calls and each call must have a corresponding tool response. The ChainAST representation groups messages into sections with a system/human header and body pairs representing completion, request/response, or summarization activity.

That structure gives the system something a flat transcript cannot. It can validate that the chain begins with an allowed header, that tool calls have responses, that responses refer to real calls, and that a new AI turn does not arrive while an earlier tool call is still pending. When a chain is restored after an interruption, force mode can add fallback responses for missing tool results or skip malformed pieces so the conversation remains structurally usable. The fallback preserves the shape of the conversation; it does not recreate the command output that was lost.

The AST also tracks byte size at the message, body-pair, section, and whole-chain levels. That lets the summarizer make decisions based on the actual material it must carry forward rather than on a vague sense that the conversation is “getting long.” It can identify older sections, oversized body pairs, and the active part of the conversation. The important distinction is between preserving a chain's syntax and preserving its meaning. ChainAST can keep the call/response relationship coherent even when the content has been summarized or replaced with a placeholder.

That distinction becomes visible after an interruption. A missing tool response can be filled with a fallback so the provider receives a valid sequence, but the fallback says only that the call was not handled. It does not say whether the command ran outside the application's view, whether the target changed, or whether the missing result would have altered the plan. Structural repair lets the system continue or ask for help; it should also tell the reviewer that the original evidence is incomplete.

The chain is not only a record of text. It carries the identifiers that bind an AI request to a tool response, the role of the current agent, and the provider-specific reasoning fields that may be checked by an API.