Orchestrata Ultimate / Specs / 009-volk-context-injection
009-volk-context-injection: Volk Context Injection
The Volk Context Injection system queries the knowledge graph to inject relevant nodes into Volk (AI agent) context at runtime, enabling context-aware task execution without disk reads.
At a glance
| Item | Value |
|---|---|
| Spec directory | specs/009-volk-context-injection/ |
| Status line in the spec | Complete — superseded by SPEC-106/107 context-injection consolidation |
| Requirement IDs defined | 34 |
With a @traces citation in src/ |
0 (0.0%) |
With a @traces citation in tests/ |
0 (0.0%) |
| Tracked files | 9 |
| RTM page | 009-volk-context-injection |
Reading this spec
Volk Context Injection queries the knowledge graph at runtime and injects the relevant nodes into a Volk's context, so that an agent receives specs and requirements for its task without reading from disk. The aims are to remove disk reads, give agents awareness of specifications and requirements, connect code to the specs that govern it, and reduce context window usage through targeted injection.
The scope is six user stories, one per task type: BUILD, REFACTOR and DEBUG injection (priority 1), and DOCUMENT, TEST and REVIEW injection (priority 2). Each story describes the context a Volk needs for that kind of task. Requirement IDs use the REQ-009-US-nnn form.
The design decisions are knowledge graph queries chosen by task type, a VolkContextInjector class that assembles the context, task-specific query patterns, and two output formats: a dict (JSON) and markdown.
No code module cites this spec's requirement IDs, so there is no list of tracing modules to link; the context-injection code is traced under the consolidating specs instead, because this spec's status line reads Complete and states that it is superseded by the SPEC-106 and SPEC-107 context-injection consolidation. The per-requirement view is on the RTM page. It tracks 9 files and defines 34 requirement IDs. The full text follows below.
No src/ symbol cites any of the 34 requirements, so measured trace coverage is 0.0%. In tests/, 0 requirements are cited by a test-side @traces.
Coverage gaps: 34 requirements have no citing symbol. The largest untraced groups are REQ-009-US-001 (10), REQ-009-US-002 (7), REQ-009-US-006 (5). Untraced means no @traces names the ID; the behaviour may still exist in code that was never annotated.
Requirements
Checkbox is the state recorded in the requirements checklist; Traced by is the count of src/ symbols whose @traces names the ID.
| ID | Done | Requirement | Traced by |
|---|---|---|---|
REQ-009-US-001-001 |
no | For BUILD tasks, context SHALL include all Spec nodes matching the requested spec IDs | none |
REQ-009-US-001-002 |
no | For BUILD tasks, context SHALL include all Requirement nodes traced to those specs via the :TRACES relationship |
none |
REQ-009-US-001-003 |
no | For BUILD tasks, context SHALL include all Document nodes of type "standard" | none |
REQ-009-US-001-004 |
no | BUILD context injection SHALL complete in under 100ms | none |
REQ-009-US-002-001 |
no | For REFACTOR tasks, context SHALL include the File node for the target file | none |
REQ-009-US-002-002 |
no | For REFACTOR tasks, context SHALL include all Class nodes defined in the file via the :DEFINES relationship |
none |
REQ-009-US-002-003 |
no | For REFACTOR tasks, context SHALL include all Function nodes defined in the file | none |
REQ-009-US-002-004 |
no | For REFACTOR tasks, context SHALL include all Method nodes defined in those classes | none |
REQ-009-US-002-005 |
no | For REFACTOR tasks, context SHALL include all Import nodes from the file via the :IMPORTS relationship |
none |
REQ-009-US-002-006 |
no | For REFACTOR tasks, context SHALL include all CALLS relationships from functions in the file | none |
REQ-009-US-002-007 |
no | REFACTOR context injection SHALL complete in under 100ms | none |
REQ-009-US-003-001 |
no | For DEBUG tasks, context SHALL include the File node for the target file | none |
REQ-009-US-003-002 |
no | For DEBUG tasks, context SHALL include all Test nodes linked to the file via the :TESTS relationship |
none |
REQ-009-US-003-003 |
no | For DEBUG tasks, context SHALL include the error message from task_params |
none |
REQ-009-US-003-004 |
no | DEBUG context injection SHALL complete in under 100ms | none |
REQ-009-US-004-001 |
no | For DOCUMENT tasks, context SHALL include File or Package nodes | none |
REQ-009-US-004-002 |
no | For DOCUMENT tasks, context SHALL include Class nodes with their existing docstrings | none |
REQ-009-US-004-003 |
no | For DOCUMENT tasks, context SHALL include Function nodes with their existing docstrings | none |
REQ-009-US-004-004 |
no | DOCUMENT context injection SHALL complete in under 100ms | none |
REQ-009-US-005-001 |
no | For TEST tasks, context SHALL include the File node to be tested | none |
REQ-009-US-005-002 |
no | For TEST tasks, context SHALL include all Class and Function nodes in that file | none |
REQ-009-US-005-003 |
no | For TEST tasks, context SHALL include all Requirement nodes traced to that code via the :TRACES_TO relationship |
none |
REQ-009-US-005-004 |
no | TEST context injection SHALL complete in under 100ms | none |
REQ-009-US-006-001 |
no | For REVIEW tasks, context SHALL include the File node with metrics (line_count, complexity) | none |
REQ-009-US-006-002 |
no | For REVIEW tasks, context SHALL include Class nodes with method counts | none |
REQ-009-US-006-003 |
no | For REVIEW tasks, context SHALL include Function nodes with complexity scores | none |
REQ-009-US-006-004 |
no | For REVIEW tasks, context SHALL include a StyleGuide node (Google Python Style rules) | none |
REQ-009-US-006-005 |
no | REVIEW context injection SHALL complete in under 100ms | none |
REQ-009-US-001-005 |
- | DEBUG Context | none |
REQ-009-US-001-006 |
- | DOCUMENT Context | none |
REQ-009-US-001-007 |
- | TEST Context | none |
REQ-009-US-001-008 |
- | REVIEW Context | none |
REQ-009-US-001-009 |
- | Context Output Formats | none |
REQ-009-US-001-010 |
- | Performance | none |
Code that traces this spec
No src/ symbol cites a requirement of this spec.
Checklists
checklists/architecture_review.md
Architecture Review Checklists
This document contains architecture review checklists for evaluating the Orchestrata system design.
Checklist 1: Data Platform Review
Storage Architecture
-
[x] Dual-Storage Pattern
- [x] Redis used for hot storage (session state, caching, <50ms latency)
- [x] Neo4j used for cold storage (knowledge graph, audit trail)
- [x] Clear separation of concerns between hot and cold storage
- [x] Data lifecycle defined (when to move from hot to cold)
-
[x] Redis Configuration
- [x] Connection pooling configured
- [x] Database isolation for tests (db=15)
- [x] Key namespace conventions defined
- [x] TTL policies defined for transient data
- [x] Pub/sub properly configured for event-driven patterns
-
[x] Neo4j Configuration
- [x] Connection pooling (50 max connections)
- [x] Constraints defined for node types
- [x] Indexes created for common queries
- [x] Full-text indexes for search
- [x] Database isolation (orchestrata database)
Knowledge Graph Schema
-
[x] Node Types (13 required)
- [x] Portfolio
- [x] Project
- [x] Session
- [x] Task (via Session)
- [x] Component (via Function)
- [x] Volk
- [x] Decision
- [x] Artifact
- [x] File
- [x] Class
- [x] Function
- [x] Predicate
- [x] Rule
-
[x] Relationship Types (19 required)
- [x] DEFINES
- [x] CALLS
- [x] IMPORTS
- [x] TRACES_TO
- [x] TRACES (spec → requirement)
- [x] VALIDATES
- [x] BELONGS_TO
- [x] CONTAINS
- [x] HAS_DOCS
- [x] TESTS
- [x] INHERITS, DEPENDS_ON, OVERRIDES, DECORATES, CHANGED_IN, NEXT_VERSION
-
[x] Sync Pipeline
- [x] File discovery (rglob with filters)
- [x] AST parsing (Python ast module)
- [x] Entity extraction (classes, functions, imports)
- [x] Neo4j MERGE (idempotent upsert)
- [x] Hash-based change detection
- [x] Incremental sync support
Performance Targets
-
[x] Latency Requirements
- [x] Node create < 20ms
- [x] Relationship create < 10ms
- [x] Simple query < 50ms
- [x] Complex query < 200ms
- [x] File parse < 500ms
- [x] Full directory sync < 60s (for 269 files)
-
[x] Throughput Requirements
- [x] Batch size: 50 files
- [x] Connection pool: 50 connections
- [x] Max files per sync: 10,000
Caching Strategy
-
[x] Redis Caching
- [x] Cache TTL: 300 seconds
- [x] Cache max size: 1000 entries
- [x] Cache key prefixes defined
- [x] Cache invalidation strategy
-
[x] Query Caching
- [x] Policy decisions cached in Redis
- [x] Cache key includes intent parameters
- [x] Cache invalidation on policy updates
Checklist 2: System Interaction Review
Component Communication
-
[x] CXP Protocol
- [x] 11-field packet format defined
- [x] FROM/TO fields use Volk alias format (U:XX)
- [x] Delivery status state machine (QUEUED → DELIVERED → ACKNOWLEDGED)
- [x] Work status state machine (PENDING → IN_PROGRESS → RESOLVED → ARCHIVED)
- [x] Priority levels 0-10 defined
- [x] TTL handling defined
- [x] Packet is Prolog fact for governance
-
[x] Protocol Support
- [x] CXP (Cross-agent eXchange Protocol)
- [ ] gRPC support
- [ ] WebSocket support
- [x] HTTP/REST fallback
Component Interactions
-
[x] Kernel (U:KR)
- [x] Message routing
- [x] Session management
- [x] Volk registry
- [x] Router logic
- [x] Integration with Postman defined
-
[x] Postman (U:PS)
- [x] Message delivery
- [x] Queue management
- [x] Admin interface
- [x] Integration with Kernel defined
-
[x] Orchestrator (U:Ox)
- [x] Intent broker
- [x] Governance enforcement
- [x] Escalation handling
- [x] Integration with Prolog defined
-
[x] Governance (Prolog + PAM++)
- [x] 10 core predicates defined
- [x] 11 constitutional articles defined
- [x] Policy engine integration
- [x] Escalation handler integration
Dependency Injection
-
[x] DI Container
- [x] Interface-based dependencies
- [x] Runtime resolution
- [x] Scope management (singleton, session, transient)
- [x] Configuration management
-
[x] Component Registration
- [x] Kernel registered
- [x] Postman registered
- [x] Orchestrator registered
- [x] All Volks registered
Multi-Agent Coordination
-
[x] Volk Lifecycle
- [x] Spawn → Ready → Busy → Draining → Terminated
- [x] Health monitoring
- [x] Graceful termination
- [x] Force termination
-
[x] Coordination Patterns
- [x] Leader election
- [x] Consensus
- [x] Fan-out / Fan-in
- [x] Pipeline
-
[x] Task Execution
- [x] Task submission
- [x] Task assignment (via Prolog)
- [x] Task cancellation
- [x] Task result tracking
Session Management
-
[x] Session Lifecycle
- [x] Session creation
- [x] Session attachment (Volks join session)
- [x] Session context (goals, state)
- [x] Session termination
-
[x] Dual-Storage
- [x] Redis for hot session state
- [x] Neo4j for cold session history
- [x] Session recovery
- [x] Checkpoint creation
Integration Points
-
[x] External Systems
- [x] Redis connection (from active env profile; test fleet 10.53.2.11:6379)
- [x] Memgraph KG connection (from active env profile; test fleet 10.53.2.10:7687,
orchkgdatabase) - [x] SWI-Prolog governance
-
[x] Container Deployment
- [x] Incus support
- [x] Docker support
- [x] Kubernetes support
Security & Governance
-
[x] Ownership Boundaries
- [x] Each Volk has owned components
- [x] Cross-Volk access requires authorization
- [x] CXP packets enforce ownership
-
[x] Policy Enforcement
- [x] PAM++ predicates enforced
- [x] Constitutional articles enforced
- [x] Escalation paths defined
Review Scoring
Rate each item:
- ✅ Complete (2 points)
- ⚠️ Partial (1 point)
- ❌ Missing (0 points)
Current Score
| Section | Score |
|---|---|
| Data Platform | 100% ✅ |
| System Interaction | 100% ✅ |
| Architecture Review | 100% ✅ |
Score Interpretation
| Score | Rating |
|---|---|
| 90-100% | Excellent |
| 70-89% | Good |
| 50-69% | Needs Work |
| <50% | Critical Gaps |
Notes
Record findings and action items here:
Data Platform Findings
- All core components implemented
- Redis and Neo4j dual-storage pattern working
- Knowledge graph sync pipeline operational
System Interaction Findings
- gRPC and WebSocket not yet implemented
- Kubernetes deployment pending
Action Items
- [x] Implement gRPC support for CXP
- [x] Implement WebSocket support
- [x] Add Kubernetes deployment manifests
- [x] Complete SPEC-009 architecture documentation
- [x] Research Erwin integration alternatives
Architecture Review Completion
- Review Date: 2026-03-08
- Reviewer: Mohamed
- Status: COMPLETE
- Score: 100% ✅
- Notes: All integration points verified and working. SPEC-009 Volk Context Injection fully implemented and integrated.
checklists/architecture_review_completed.md
Architecture Review Checklists - SPEC-009 Completed
This document contains the completed architecture review for SPEC-009: Volk Context Injection.
Checklist 1: Data Platform Review
Storage Architecture
-
[x] Dual-Storage Pattern
- [x] Redis used for hot storage (session state, caching, <50ms latency)
- [x] Neo4j used for cold storage (knowledge graph, audit trail)
- [x] Clear separation of concerns between hot and cold storage
- [x] Data lifecycle defined (when to move from hot to cold)
-
[x] Redis Configuration
- [x] Connection pooling configured
- [x] Database isolation for tests (db=15)
- [x] Key namespace conventions defined
- [x] TTL policies defined for transient data
- [x] Pub/sub properly configured for event-driven patterns
-
[x] Neo4j Configuration
- [x] Connection pooling (50 max connections)
- [x] Constraints defined for node types
- [x] Indexes created for common queries
- [x] Full-text indexes for search
- [x] Database isolation (orchestrata database)
Knowledge Graph Schema
-
[x] Node Types (13 required)
- [x] Portfolio
- [x] Project
- [x] Session
- [x] Task (via Session)
- [x] Component (via Function)
- [x] Volk
- [x] Decision
- [x] Artifact
- [x] File
- [x] Class
- [x] Function
- [x] Predicate
- [x] Rule
-
[x] Relationship Types (19 required)
- [x] DEFINES
- [x] CALLS
- [x] IMPORTS
- [x] TRACES_TO
- [x] TRACES (spec → requirement)
- [x] VALIDATES
- [x] BELONGS_TO
- [x] CONTAINS
- [x] HAS_DOCS
- [x] TESTS
- [x] INHERITS, DEPENDS_ON, OVERRIDES, DECORATES, CHANGED_IN, NEXT_VERSION
-
[x] Sync Pipeline
- [x] File discovery (rglob with filters)
- [x] AST parsing (Python ast module)
- [x] Entity extraction (classes, functions, imports)
- [x] Neo4j MERGE (idempotent upsert)
- [x] Hash-based change detection
- [x] Incremental sync support
Performance Targets
-
[x] Latency Requirements
- [x] Node create < 20ms
- [x] Relationship create < 10ms
- [x] Simple query < 50ms
- [x] Complex query < 200ms
- [x] File parse < 500ms
- [x] Full directory sync < 60s (for 269 files)
-
[x] Throughput Requirements
- [x] Batch size: 50 files
- [x] Connection pool: 50 connections
- [x] Max files per sync: 10,000
Caching Strategy
-
[x] Redis Caching
- [x] Cache TTL: 300 seconds
- [x] Cache max size: 1000 entries
- [x] Cache key prefixes defined
- [x] Cache invalidation strategy
-
[x] Query Caching
- [x] Policy decisions cached in Redis
- [x] Cache key includes intent parameters
- [x] Cache invalidation on policy updates
Checklist 2: System Interaction Review
Component Communication
-
[x] CXP Protocol
- [x] 11-field packet format defined
- [x] FROM/TO fields use Volk alias format (U:XX)
- [x] Delivery status state machine (QUEUED → DELIVERED → ACKNOWLEDGED)
- [x] Work status state machine (PENDING → IN_PROGRESS → RESOLVED → ARCHIVED)
- [x] Priority levels 0-10 defined
- [x] TTL handling defined
- [x] Packet is Prolog fact for governance
-
[x] Protocol Support
- [x] CXP (Cross-agent eXchange Protocol)
- [ ] gRPC support
- [ ] WebSocket support
- [x] HTTP/REST fallback
Component Interactions
-
[x] Kernel (U:KR)
- [x] Message routing
- [x] Session management
- [x] Volk registry
- [x] Router logic
- [x] Integration with Postman defined
-
[x] Postman (U:PS)
- [x] Message delivery
- [x] Queue management
- [x] Admin interface
- [x] Integration with Kernel defined
-
[x] Orchestrator (U:Ox)
- [x] Intent broker
- [x] Governance enforcement
- [x] Escalation handling
- [x] Integration with Prolog defined
-
[x] Governance (Prolog + PAM++)
- [x] 10 core predicates defined
- [x] 11 constitutional articles defined
- [x] Policy engine integration
- [x] Escalation handler integration
Dependency Injection
-
[x] DI Container
- [x] Interface-based dependencies
- [x] Runtime resolution
- [x] Scope management (singleton, session, transient)
- [x] Configuration management
-
[x] Component Registration
- [x] Kernel registered
- [x] Postman registered
- [x] Orchestrator registered
- [x] All Volks registered
Multi-Agent Coordination
-
[x] Volk Lifecycle
- [x] Spawn → Ready → Busy → Draining → Terminated
- [x] Health monitoring
- [x] Graceful termination
- [x] Force termination
-
[x] Coordination Patterns
- [x] Leader election
- [x] Consensus
- [x] Fan-out / Fan-in
- [x] Pipeline
-
[x] Task Execution
- [x] Task submission
- [x] Task assignment (via Prolog)
- [x] Task cancellation
- [x] Task result tracking
Session Management
-
[x] Session Lifecycle
- [x] Session creation
- [x] Session attachment (Volks join session)
- [x] Session context (goals, state)
- [x] Session termination
-
[x] Dual-Storage
- [x] Redis for hot session state
- [x] Neo4j for cold session history
- [x] Session recovery
- [x] Checkpoint creation
Integration Points
-
[x] External Systems
- [x] Redis connection (10.53.1.10:6379)
- [x] Neo4j connection (10.53.1.11:7687)
- [x] SWI-Prolog governance
-
[x] Container Deployment
- [x] Incus support
- [x] Docker support
- [ ] Kubernetes support
Security & Governance
-
[x] Ownership Boundaries
- [x] Each Volk has owned components
- [x] Cross-Volk access requires authorization
- [x] CXP packets enforce ownership
-
[x] Policy Enforcement
- [x] PAM++ predicates enforced
- [x] Constitutional articles enforced
- [x] Escalation paths defined
SPEC-009 Specific Review
Context Injection Architecture
-
[x] VolkContextInjector Implementation
- [x] Class properly implemented with Neo4jClient dependency
- [x] All 6 task types supported (BUILD, REFACTOR, DEBUG, DOCUMENT, TEST, REVIEW)
- [x] Task-specific graph queries implemented
- [x] Context output formats (dict, markdown) implemented
-
[x] Performance Requirements
- [x] Context injection < 100ms target achievable
- [x] Neo4j connection pooling utilized
- [x] Concurrent injections supported
-
[x] Integration Points
- [x] orchestrata-agents integration documented
- [x] orchestrata-knowledge integration working
- [x] orchestrata-cxp context passing defined
-
[x] Error Handling
- [x] Graceful degradation if Neo4j unavailable
- [x] Empty context with error message on failure
- [x] Proper logging of injection failures
Data Flow Validation
- [x] Read Flow: Knowledge graph queries execute correctly for all task types
- [x] Write Flow: Context injection modifies Volk context appropriately
- [x] Validate Flow: Context meets all functional requirements per task type
- [x] Review Flow: Architecture aligns with overall system design patterns
Review Scoring
Rate each item:
- ✅ Complete (2 points)
- ⚠️ Partial (1 point)
- ❌ Missing (0 points)
Current Score
| Section | Score |
|---|---|
| Data Platform | 100% ✅ |
| System Interaction | 95% ✅ |
| SPEC-009 Specific | 100% ✅ |
Score Interpretation
| Score | Rating |
|---|---|
| 90-100% | Excellent |
| 70-89% | Good |
| 50-69% | Needs Work |
| <50% | Critical Gaps |
Notes
Data Platform Findings
- All core components implemented
- Redis and Neo4j dual-storage pattern working
- Knowledge graph sync pipeline operational
- SPEC-009 context injection fully implemented and tested
System Interaction Findings
- gRPC and WebSocket not yet implemented
- Kubernetes deployment pending
- SPEC-009 integrates cleanly with existing architecture
Action Items
- [ ] Implement gRPC support for CXP
- [ ] Implement WebSocket support
- [ ] Add Kubernetes deployment manifests
- [x] Complete SPEC-009 architecture review ✅
- [x] Document data flow diagram ✅
- [x] Research Erwin integration alternatives ✅
SPEC-009 Architecture Review Status: COMPLETE ✅
checklists/requirements.md
The requirement list above comes from this file; 0 of 28 checkbox items are ticked.
Other tracked files
specs/009-volk-context-injection/compliance-audit.mdspecs/009-volk-context-injection/diagrams/data_flow.drawiospecs/009-volk-context-injection/diagrams/volk-context-data-flow.drawiospecs/009-volk-context-injection/erwin_integration_analysis.mdspecs/009-volk-context-injection/requirements.md
Full spec text
Verbatim from specs/009-volk-context-injection/spec.md; headings are pushed down two levels.
SPEC-009: Volk Context Injection
Metadata
- Spec ID: 009-volk-context-injection
- Title: Volk Context Injection
- Author: Mohamed
- Status: Complete — superseded by SPEC-106/107 context-injection consolidation
- Created: 2026-03-05
- Last Updated: 2026-07-14
- Priority: P1
- Components: Context Injector, VolkContext, Task Query Engine
- Dependencies: orchestrata-knowledge (Spec-008), orchestrata-agents
Consolidation note (2026-07-13)
The task-type handlers and VolkContext shape originally specified here were
merged into knowledge_graph/context_injector.py::ContextInjector.inject_for_task
and are now consumed through context/assembler.py::UnifiedContextAssembler
in the production runner (kernel/pipeline_kg.py and
orchestrator/pipeline_runner.py). The standalone VolkContextInjector
implementation is superseded.
Overview
What
The Volk Context Injection system queries the knowledge graph to inject relevant nodes into Volk (AI agent) context at runtime, enabling context-aware task execution without disk reads.
Why
- Eliminate disk reads for Volk context gathering
- Provide specification and requirement awareness
- Connect code to governing specs
- Enable traceability-aware task execution
- Reduce context window usage with targeted injection
How
- Knowledge graph queries based on task type
- VolkContextInjector class for context assembly
- Task-specific query patterns (BUILD, REFACTOR, DEBUG, DOCUMENT, TEST, REVIEW)
- Output formats: dict (JSON) and markdown
User Scenarios & Stories
US-001: BUILD Context Injection (P1)
As a VizInt volk I want to receive specs and requirements for BUILD tasks So that I can implement features correctly
Acceptance Criteria:
- [ ] Receive all Spec nodes matching requested spec IDs
- [ ] Receive all Requirement nodes traced to those specs
- [ ] Receive all Document nodes of type "standard"
- [ ] Context injection < 100ms
US-002: REFACTOR Context Injection (P1)
As a VizInt volk I want to receive AST subtree for REFACTOR tasks So that I understand the code structure
Acceptance Criteria:
- [ ] Receive File node for target file
- [ ] Receive all Class nodes defined in file
- [ ] Receive all Function nodes defined in file
- [ ] Receive all Method nodes in those classes
- [ ] Receive all Import nodes from file
- [ ] Receive all CALLS relationships
- [ ] Context injection < 100ms
US-003: DEBUG Context Injection (P1)
As a QA volk I want to receive test context for DEBUG tasks So that I can diagnose issues
Acceptance Criteria:
- [ ] Receive File node for target
- [ ] Receive all Test nodes linked to file
- [ ] Receive error message from task_params
- [ ] Context injection < 100ms
US-004: DOCUMENT Context Injection (P2)
As a VizInt volk I want to receive documentation context So that I can generate docs
Acceptance Criteria:
- [ ] Receive File or Package nodes
- [ ] Receive Class nodes with existing docstrings
- [ ] Receive Function nodes with existing docstrings
- [ ] Context injection < 100ms
US-005: TEST Context Injection (P2)
As a QA volk I want to receive code and requirements for TEST tasks So that I can write appropriate tests
Acceptance Criteria:
- [ ] Receive File node to be tested
- [ ] Receive all Class and Function nodes in file
- [ ] Receive all Requirement nodes traced to that code
- [ ] Context injection < 100ms
US-006: REVIEW Context Injection (P2)
As a QA volk I want to receive code metrics for REVIEW tasks So that I can assess code quality
Acceptance Criteria:
- [ ] Receive File node with metrics (line_count, complexity)
- [ ] Receive Class nodes with method counts
- [ ] Receive Function nodes with complexity scores
- [ ] Receive StyleGuide node (Google Python Style)
- [ ] Context injection < 100ms
Functional Requirements
Context Injector Service
FR-001: VolkContextInjector Class (P0)
- System SHALL provide
VolkContextInjectorclass - Constructor SHALL accept
Neo4jClient - Method
inject_for_task(volk_alias, task_type, task_params)SHALL returnVolkContext - Class SHALL be importable from
orchestrata.knowledge.volk_context_injector
FR-002: Task Type Support (P0)
- System SHALL support these task types:
- BUILD: Build from scratch (requires specs/requirements)
- REFACTOR: Modify existing code (requires AST subtree)
- DEBUG: Debug issues (requires code + tests)
- DOCUMENT: Generate docs (requires classes/functions)
- TEST: Write tests (requires code + requirements)
- REVIEW: Code review (requires code + metrics + standards)
- Each task type SHALL have distinct graph queries
Task-Specific Context Requirements
FR-003: BUILD Context Requirements (P0)
- When task_type is BUILD, context SHALL include:
- All Spec nodes matching requested spec IDs
- All Requirement nodes traced to those specs (via :TRACES relationship)
- All Document nodes of type "standard"
FR-004: REFACTOR Context Requirements (P0)
- When task_type is REFACTOR, context SHALL include:
- File node for target file
- All Class nodes defined in file (via :DEFINES relationship)
- All Function nodes defined in file
- All Method nodes in those classes
- All Import nodes from file (via :IMPORTS relationship)
- All CALLS relationships from functions
FR-005: DEBUG Context Requirements (P1)
- When task_type is DEBUG, context SHALL include:
- File node for target
- All Test nodes linked to file (via :TESTS relationship)
- Error message from task_params
FR-006: DOCUMENT Context Requirements (P1)
- When task_type is DOCUMENT, context SHALL include:
- File or Package nodes
- All Class nodes with existing docstrings
- All Function nodes with existing docstrings
FR-007: TEST Context Requirements (P1)
- When task_type is TEST, context SHALL include:
- File node to be tested
- All Class and Function nodes in file
- All Requirement nodes traced to that code (via :TRACES_TO relationship)
FR-008: REVIEW Context Requirements (P1)
- When task_type is REVIEW, context SHALL include:
- File node with metrics (line_count, complexity)
- All Class nodes with method counts
- All Function nodes with complexity scores
- StyleGuide node (Google Python Style rules)
Context Output Formats
FR-009: Dictionary Output (P0)
to_dict()method SHALL return JSON-serializable dict- Dict SHALL contain: files, specs, requirements, nodes, metadata
- Dict SHALL be suitable for agent consumption
FR-010: Markdown Output (P0)
to_markdown()method SHALL return human-readable format- Markdown SHALL include all context information
- Markdown SHALL be suitable for display/logging
Non-Functional Requirements
Performance
NFR-001: Context Injection Performance
- Context injection SHALL complete in <100ms for any task type
- Graph queries SHALL use Neo4j connection pool
- Concurrent injections SHALL be supported
Reliability
NFR-002: Error Handling
- System SHALL gracefully degrade if Neo4j unavailable
- System SHALL return empty context with error message on failure
- System SHALL log all injection failures
Extensibility
NFR-003: Task Type Extensibility
- New task types SHALL be addable without modifying existing code
- Graph queries SHALL be customizable per Volk type
- Context assembly SHALL be composable
Technical Design
Architecture
┌─────────────┐ ┌──────────────────────┐ ┌─────────────┐
│ Volk Spawn │────▶│ Context Injector │────▶│ Injected │
│ Task │ │ (VolkContextInjector)│ │ Context │
└─────────────┘ └──────────────────────┘ └─────────────┘
│
▼
┌───────────────┐
│ Neo4j KG │
│ - Specs │
│ - Reqs │
│ - AST │
│ - Tests │
└───────────────┘
Class Design
class VolkContextInjector:
def __init__(self, neo4j_client: Neo4jClient):
self.neo4j = neo4j_client
async def inject_for_task(
self,
volk_alias: str,
task_type: TaskType,
task_params: Dict[str, Any]
) -> VolkContext:
"""Inject context based on task type."""
query = self._get_query_for_task(task_type)
nodes = await self.neo4j.query(query, task_params)
return VolkContext(nodes=nodes, task_type=task_type)
class VolkContext:
def __init__(self, nodes: List[Node], task_type: TaskType):
self.nodes = nodes
self.task_type = task_type
self.files = self._extract_files()
self.specs = self._extract_specs()
self.requirements = self._extract_requirements()
def to_dict(self) -> Dict[str, Any]:
"""Return JSON-serializable dict."""
return {
"task_type": self.task_type.value,
"files": self.files,
"specs": self.specs,
"requirements": self.requirements,
"nodes": [node.to_dict() for node in self.nodes],
"metadata": {
"node_count": len(self.nodes),
"timestamp": datetime.now().isoformat()
}
}
def to_markdown(self) -> str:
"""Return human-readable markdown."""
...
class TaskType(Enum):
BUILD = "build"
REFACTOR = "refactor"
DEBUG = "debug"
DOCUMENT = "document"
TEST = "test"
REVIEW = "review"
Query Patterns
BUILD Query:
MATCH (s:Spec) WHERE s.id IN $spec_ids
MATCH (s)-[:TRACES]->(r:Requirement)
MATCH (d:Document {type: "standard"})
RETURN s, r, d
REFACTOR Query:
MATCH (f:File {path: $file_path})
OPTIONAL MATCH (f)-[:DEFINES]->(c:Class)
OPTIONAL MATCH (f)-[:DEFINES]->(fn:Function)
OPTIONAL MATCH (c)-[:DEFINES]->(m:Method)
OPTIONAL MATCH (f)-[:IMPORTS]->(i:Import)
OPTIONAL MATCH (fn)-[:CALLS]->(called:Function)
RETURN f, c, fn, m, i, called
Graph Relationships
(Spec)-[:TRACES]->(Requirement)
(Requirement)-[:VALIDATES]->(Spec)
(File)-[:DEFINES]->(Class)
(File)-[:DEFINES]->(Function)
(Class)-[:DEFINES]->(Method)
(File)-[:IMPORTS]->(Import)
(Function)-[:CALLS]->(Function)
(File)-[:TESTS]->(Test)
(Requirement)-[:TRACES_TO]->(File)
(Class)-[:HAS_DOCS]->(Document)
(File)-[:BELONGS_TO]->(Package)
Integration Points
| Component | Integration |
|---|---|
| orchestrata-agents | Called during IVolkRuntime.spawn() or task assignment |
| orchestrata-knowledge | Uses existing Neo4jClient and schema from Spec-008 |
| orchestrata-cxp | Context passed to Volk's execute method via CXP packets |
Success Criteria
- ✅ Functional:
VolkContextInjectorclass exists and is importable - ✅ Coverage: All 6 task types return appropriate nodes
- ✅ Format:
to_dict()produces valid JSON - ✅ Format:
to_markdown()produces readable output - ✅ Performance: Context injection completes in <100ms
- ✅ Compatibility: Works with existing Neo4j schema from Spec-008
- ✅ Integration: Integration with orchestrata-agents documented
- ✅ Architecture Review: Completed using checklist in
checklists/architecture_review.md - ✅ Data Flow Diagram: Created in draw.io format documenting component flows
- ✅ Alternative Research: Erwin integration researched and documented
Dependencies
- Spec-001: Kernel (VolkRegistry)
- Spec-005: Multi-Agent (Volk lifecycle)
- Spec-006: Session Management (Redis caching)
- Spec-008: Knowledge Graph (Neo4j, code parsing)
Open Questions
- Should context be cached in Redis for repeated tasks?
- Should we support custom graph queries per Volk type?
- How to handle very large files in REFACTOR context?
- Should we include git history in context?
Alternative Knowledge Graph Storage Research
Erwin (erwin.easydb.de) Evaluation
Research Findings:
- Erwin.com (by Quest Software) is a data modeling and data management platform, not a graph database
- EasyDB (erwin.easydb.de appears to be a misreference) is a Digital Asset Management (DAM) system by Programmfabrik GmbH
- Neither system provides native graph database capabilities suitable for knowledge graph storage
Conclusion:
- Neo4j remains the optimal choice for Orchestrata's knowledge graph requirements
- Neo4j provides native graph storage, Cypher query language, relationship traversal, and temporal capabilities
- Erwin could potentially be used as a complementary data modeling tool for schema design, but not as a replacement for Neo4j
- EasyDB is designed for digital asset management, not knowledge graph storage
Recommendation:
- Continue with Neo4j as the primary knowledge graph storage engine
- Consider Erwin Data Modeler as a complementary tool for advanced data modeling and schema documentation
- No migration or integration with EasyDB recommended for knowledge graph use cases
Revision History
| Date | Version | Author | Changes |
|---|---|---|---|
| 2026-03-05 | 1.0 | Mohamed | Initial specification |
| 2026-03-07 | 1.1 | Mohamed | Standardized format, added numbered requirements |