Contexts & Graphs
Contexts and graphs are how LocusGraph organizes structured agent knowledge. Graphs isolate workspaces. Contexts group related learnings inside a workspace.
Why Scope Matters
An agent that retrieves everything from one big bucket gets noise. An agent that retrieves from a tight, well-shaped scope gets validated knowledge it can actually use. Graphs and contexts are the two scoping layers that make that possible.
Graph IDs
A graph is a top-level workspace for structured agent knowledge. Each graph is fully isolated — knowledge in one graph cannot be retrieved from another.
Use separate graphs for:
- Different projects
- Different teams
- Different agents
- Production vs. staging environments
Pass graph_id when initializing the client or on each API call. The default value is "default".
Context IDs
Context IDs group related knowledge within a graph. They follow a type:name format:
skill:react_best_practices
session:20250319_ab3f
project:locusgraph_docs
task:onboarding_flowThe type prefix (before the colon) lets you query all contexts of a given type. For example, retrieve all skill: contexts to see every skill the agent has graduated across the graph.
Format Rules
Context IDs are normalized automatically: lowercased, spaces replaced with underscores, truncated to 256 characters.
| Rule | Detail |
|---|---|
| Format | type:name |
| Valid characters | a-z, 0-9, _, -, : |
| Max length | 256 characters |
| Case | Lowercased on admission |
| Spaces | Converted to _ |
These are all valid:
skill:error_handling
session:2025-03-19_morning
project:my-api
user:preferencesThese are normalized:
skill:React Best Practices -> skill:react_best_practices
MY_SKILL:Testing -> my_skill:testingCommon Context Types
The type prefix serves as a namespace. These are conventions, not enforced categories — but staying close to them keeps retrieval predictable.
| Type | Use Case |
|---|---|
skill | Graduated capabilities and best practices |
session | Conversation or interaction boundaries |
project | Project-scoped knowledge |
task | Task-specific context |
error | Error patterns and fixes |
user | Per-user preferences and history |
agent:<role> | Multi-agent role boundaries (e.g., agent:planner) |
Scoping in Practice
When storing an event, pass context_id to attach it to a context:
{
"event_kind": "fact",
"source": "agent",
"context_id": "skill:react_best_practices",
"payload": { "topic": "hooks", "value": "prefer useReducer for complex state" }
}When retrieving, filter by context to narrow results:
{
"query": "state management",
"context_id": "skill:react_best_practices",
"limit": 10
}Graph Strategy
| Setup | Suggested Graphs |
|---|---|
| Solo agent on one product | One graph |
| Team with shared agents | One graph per project + scoped contexts per agent |
| Multi-tenant SaaS | One graph per tenant |
| Prod + staging | Separate graphs to keep test data out of prod retrieval |