Architecture Pattern

Infinite Runtime for Autonomous Agents

Context overflow is the #1 cause of agent failure. Integrate Ctxfy as a 'Memory Garbage Collector' to keep your agents running forever without losing IQ.

Compatible with LangChain, LangGraph, AutoGPT

The 'Context Crash' Reality

Step 10Agent works fine. Context at 10%.
Step 50Latency increases. Cost spikes. Context at 80%.
Step 80Crash. 'Model context length exceeded'. Task failed.
The Ctxfy Loop
Action (Step 1)
Observation
Compress State
Action (Step 2)

The Recursive Summary Pattern

Turn linear history into a sustainable loop. When context fills, compress the tail into a dense 'State Object' and continue.

Active Memory Management

Think of Ctxfy as a Garbage Collector (GC) for your context window. It cleans up noise while keeping references to important variables.

Stable Latency

Raw history makes every subsequent request slower. Compressed state keeps your Time-To-First-Byte (TTFB) flat and fast.

Recursive Intelligence

The model summarizes its own progress. State v2 includes State v1, creating a chain of memory that can span millions of tokens.

agent-loop.ts
async function runAgentLoop() {
  let history = [];
  
  while (true) {
    const action = await agent.act(history);
    history.push(action);

    if (countTokens(history) > 10000) {
      // POST /v1/spaces/:spaceId/sources with type CONTENT
      const res = await fetch(`/v1/spaces/${spaceId}/sources`, {
        method: "POST",
        body: JSON.stringify({ type: "CONTENT", initial_data: { data: formatHistory(history) }, instructions: {} })
      });
      const { data } = await res.json();
      // Receive postback with processed source content
      const state = await waitForPostback(data.id);
      history = [{ role: 'system', content: state.content }];
    }
  }
}

Copy this pattern into your agent's main loop.

Frequently asked questions

Minimal information loss occurs. Our algorithm is tuned to preserve 'Hard State' (decisions, file paths, variable values) and discard 'Soft State' (chit-chat, reasoning steps).

Processing runs asynchronously. Create a source and receive a postback with the processed content when ready. See the documentation for details.

Yes. The API is REST-based. Use POST /v1/spaces/:spaceId/sources with type CONTENT. See the API Reference for integration patterns.

Build agents that never sleep.

Stop restarting your runs. Start managing your state.