Knowledge Graph
AgentOS includes a temporal knowledge graph that allows agents to build, version, and query structured knowledge about entities and their relationships. Unlike flat memory storage, the knowledge graph enables semantic queries, graph traversal, and temporal reasoning.Overview
The knowledge graph (implemented insrc/knowledge-graph.ts:1) provides:
- Temporal versioning - Track entity evolution over time
- Bidirectional relations - Automatic inverse relationship creation
- Graph traversal - BFS/DFS with depth and direction control
- Diff and timeline - Compare entity states across time periods
- Statistical analysis - Connected components, degree distribution
Core Concepts
Entities
Nodes in the graph representing things (projects, people, concepts) with typed properties
Relations
Directed edges between entities with types like “built_on”, “authored_by”, “depends_on”
Temporal Validity
Each entity version has validFrom/validUntil timestamps for time-based queries
Adding Entities
Create an entity with properties
Update an entity (creates new version)
src/knowledge-graph.ts:71).Querying the Graph
Basic Query with Depth
Time-Range Query
Query entities as they existed in a specific time window:validFrom and validUntil (src/knowledge-graph.ts:162-167).
Filtered Relations
Only traverse specific relation types:Graph Traversal
For more control over traversal direction and limits:Temporal Operations
View Version History
Compare States (Diff)
Statistics
Get graph-level metrics:src/knowledge-graph.ts:347-361, this uses DFS to count connected components.
Real-World Example: Project Knowledge
Automatic Inverse Relations
When you create a relation, the system automatically adds the inverse (src/knowledge-graph.ts:97-127):
Query Limits
From the implementation:- Max depth: 10 levels (see
src/knowledge-graph.ts:144) - Max results: 500 entities per query (see
src/knowledge-graph.ts:154) - Max nodes in traverse: 500 (see
src/knowledge-graph.ts:215)
HTTP API Endpoints
Best Practices
Use semantic relation types
Use semantic relation types
Choose meaningful, consistent relation names:
built_on, authored_by, depends_on, implements, part_of.Scope by agentId
Scope by agentId
Each agent maintains its own knowledge graph. Use consistent agentIds to separate different domains.
Set appropriate depth limits
Set appropriate depth limits
Deep traversals (>5) can be expensive. Start shallow and increase as needed.
Use temporal queries for debugging
Use temporal queries for debugging
Compare past and present states to understand how knowledge evolved.
Combine with memory
Combine with memory
Store unstructured notes in memory, structured facts in the knowledge graph.
Related Features
- Swarms - Use KG to structure findings from swarm research
- Session Replay - Track knowledge graph modifications over time
- Memory - Complement structured KG with unstructured memory