Skip to documentation
Docs navigation
Docs/Long-running agents
Advanced

Long-running agents

Keep an agent useful through extended work, restarts, and large histories without replaying every turn.

Design the memory boundary

Use an application-owned stable job or conversation identifier with the lower-level MemoGrafter API when work must be reopened across process lifetimes. MemoGrafterAgent owns a generated session and is best reused while that active agent instance lives.

Checkpoint durable knowledge

Ingest completed decisions, results, and meaningful checkpoints rather than transient progress noise.
Attach source and project tags so later recall can recover the right scope.
Keep raw operational state in the application’s job store; MemoGrafter is memory infrastructure, not a scheduler.

Recall before planning

planning-cycle.ts
const memory = await memo.graftByRelevance(sessionId, nextTask, {
  topK: 5,
  minSimilarity: 0.55,
  hopDepth: 1,
});
const plan = await llm.complete(
  [{ role: "user", content: nextTask }],
  memory.systemPrompt,
);

Control growth

Bound retrieved facts and prompt context with limits and token budgets.
Use recent raw history for immediate continuity and graph memory for older relevant context.
Review extraction quality before increasing retrieval breadth.
Run crawler maintenance and reviewed lifecycle actions outside the response-critical path.

Queue and cache

Queue mode can move extraction off the foreground path. Recall caching helps repeated queries over stable memory, but neither feature replaces job state, retries, monitoring, or authorization in the host application.

Operational checklist

Use globally unique session identifiers.
Make worker shutdown call close().
Measure invoke latency, ingestion lag, queue failures, prompt size, and empty recall rate.
Do not create a new MemoGrafterAgent on every planning cycle.
Keep tenant authorization outside MemoGrafter.