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

Common Patterns

Proven patterns for turning agent experience into structured agent knowledge with LocusGraph.

The Graduation Chain

The defining pattern in LocusGraph is the graduation chain: events become patterns, and patterns become skills. Confidence scoring decides what graduates and what fades.

Step 1: Store the event. When the agent makes an error, record it as an observation under an error: context.

await client.storeEvent({
  graph_id: 'default',
  event_kind: 'observation',
  source: 'agent',
  context_id: 'error:off_by_one',
  payload: { topic: 'off_by_one', value: 'Array index out of bounds in pagination logic' },
});

Step 2: Recognize the pattern. When the same error appears 3+ times, store a pattern that links back to the error context with reinforces.

await client.storeEvent({
  graph_id: 'default',
  event_kind: 'fact',
  source: 'agent',
  context_id: 'pattern:pagination_bounds',
  reinforces: ['error:off_by_one'],
  payload: { topic: 'pagination_bounds', value: 'Always use length - 1 for zero-indexed arrays' },
});

Step 3: Graduate to skill. After the pattern proves useful 5+ times, promote it to a skill with extends.

await client.storeEvent({
  graph_id: 'default',
  event_kind: 'fact',
  source: 'agent',
  context_id: 'skill:safe_pagination',
  extends: ['pattern:pagination_bounds'],
  payload: { topic: 'safe_pagination', value: 'Clamp page index between 0 and Math.ceil(total/pageSize) - 1' },
});
The graduation chain is what makes LocusGraph more than memory. Skills retrieved during future sessions prevent the same mistakes from recurring.

Preference Tracking

Store user preferences as facts. When the same preference surfaces again, use reinforces to link back to the original. Confidence rises and the preference ranks higher in retrieval — exactly the kind of validated knowledge that should sit at the front.

Session Bookends

Bracket each session with a start event and an end event. Tag all events within the session using a consistent session: context prefix (e.g., session:2024-03-15-abc). This makes it easy to retrieve everything that happened in a given session and to track how the agent's knowledge evolved over time.

Next

Error Handling
Workflows Overview