Common Patterns
Proven patterns for building wisdom into your agents with LocusGraph.
Graduation Chains
The most powerful pattern in LocusGraph turns mistakes into skills through three stages: mistake, pattern, skill.
Step 1: Store a mistake. When an agent makes an error, record it as an observation with 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' },
});Preference Tracking
Store user preferences as facts. When the same preference surfaces again, use reinforces to link back to the original. This raises its confidence score, ensuring it ranks higher in retrieval results.
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.