Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Single Agent Loop

One agent, persistent wisdom across sessions.

The Simplest Pattern

The single agent loop is the foundation of every LocusGraph workflow: one agent, one graph. The agent stores what it learns and retrieves what it needs. Each session builds on the last.

Session Start: Retrieve Context

Begin every session by pulling recent context from the graph. A broad query surfaces the most relevant prior knowledge.

During Session: Store Events

As the agent observes, decides, and acts, store each meaningful event. Tag events with descriptive contexts so they can be retrieved later.

Session End: Summarize

Close the session by storing a summary event. This captures the session's key outcomes in a single retrievable node.

Full Example

const client = new LocusGraphClient({ graphId: 'my-project' });
 
// Session start — retrieve recent context
const context = await client.retrieveMemories({
  query: 'recent work and decisions',
  limit: 10,
});
 
// During work — store what you learn
await client.storeEvent({
  graph_id: 'my-project',
  event_kind: 'fact',
  source: 'agent',
  context_id: 'skill:error_handling',
  payload: { topic: 'retry_pattern', value: 'Use exponential backoff for network errors' },
});
 
// Session end — summarize
await client.storeEvent({
  graph_id: 'my-project',
  event_kind: 'observation',
  source: 'agent',
  context_id: 'session:2025_03_19',
  payload: { topic: 'session_summary', value: 'Refactored error handling to use exponential backoff' },
});

The context_id field is how you organize knowledge. Use prefixes like skill:, session:, or project: to create a natural taxonomy.

What Gets Stored

Focus on events that compound over time:

  • Facts — durable knowledge the agent discovers (e.g., "this API requires auth headers").
  • Observations — patterns noticed during work (e.g., "tests fail when DB migrations are pending").
  • Decisions — choices made and why (e.g., "chose REST over gRPC for simplicity").
  • Summaries — session-level recaps that anchor future retrieval.

Next

Multi-Agent Collaboration
Share wisdom across multiple agents with scoped contexts.
Session & Long-Term Memory
Manage ephemeral session data and persistent knowledge.