Dynamically load relevant context files when delegating to subagents
Allows subagents to discover and access context created earlier in the session, preventing information loss across delegation boundaries.
When creating a context file, add metadata to manifest:
"context_files": {
"features/user-auth-context.md": {
"created": "2025-01-18T14:30:22Z",
"for": "@subagents/core/task-manager",
"keywords": ["user-auth", "authentication", "features"]
}
}
Metadata Fields:
created: Timestamp of file creationfor: Target subagent (which agent will use this)keywords: Array of searchable keywords for discoveryManifest maintains keyword index for fast lookup:
"context_index": {
"user-auth": [
"features/user-auth-context.md",
"tasks/user-auth-tasks.md"
],
"api": [
"documentation/api-docs-context.md"
]
}
Index Structure:
When delegating to subagent:
context_index for matching keywordsContext Reference Format:
Related context available at: .tmp/sessions/{session-id}/features/user-auth-context.md
Full Delegation Example:
Delegating to @subagents/code/coder-agent:
"Implement user authentication login component.
Related context available at:
- .tmp/sessions/20250118-143022-a4f2/features/user-auth-context.md
- .tmp/sessions/20250118-143022-a4f2/tasks/user-auth-tasks.md
Read these files for full context on requirements and task breakdown."
Only create when ALL of these apply:
Don't create for:
features/ - Feature development context
documentation/ - Documentation tasks
code/ - Code-related tasks
refactoring/ - Refactoring tasks
testing/ - Testing tasks
tasks/ - Task breakdowns created by task-manager
general/ - General tasks that don't fit other categories
# Context: {Task Name}
Session: {session-id}
## Request Summary
[Brief description of what needs to be done]
## Background
[Relevant context and information]
## Expected Output
[What the subagent should produce]
## Constraints
[Any limitations or requirements]
## Related Context
[Links to other context files if applicable]
Search context_index for exact keyword matches:
User: "Add login validation"
Keywords: ["login", "validation", "user-auth"]
→ Finds: features/user-auth-context.md, tasks/user-auth-tasks.md
Search context_files for matching category:
Delegating to @documentation agent
Category: "documentation"
→ Finds all files in documentation/ folder
Search context_files for files created for specific agent:
Delegating to @task-manager
Filter: "for": "@subagents/core/task-manager"
→ Finds all context files created for task-manager
1. User: "Build user authentication system"
→ OpenAgent creates: features/user-auth-context.md
→ Manifest updated with keywords: ["user-auth", "authentication", "features"]
→ Delegates to @task-manager with context file path
2. Task-manager creates: tasks/user-auth-tasks.md
→ Manifest updated with keywords: ["user-auth", "tasks", "breakdown"]
→ Both files now indexed under "user-auth"
3. User: "Implement the login component"
→ OpenAgent searches manifest for "user-auth" OR "login"
→ Finds: features/user-auth-context.md, tasks/user-auth-tasks.md
→ Delegates to @coder-agent with references to BOTH files
→ Coder-agent reads both files to understand full context
4. User: "Add password reset feature"
→ OpenAgent searches manifest for "user-auth" OR "password"
→ Finds existing user-auth context
→ Creates new: features/password-reset-context.md
→ Links to existing user-auth context
→ Delegates with all related context files
✅ No context loss: Information persists across subagent calls ✅ Automatic discovery: Related context found by keywords ✅ Flexible: Subagents read only what they need ✅ Traceable: Manifest shows all context relationships ✅ Scalable: Works with multiple context files per session ✅ Reusable: Later tasks can reference earlier context
Load related context files from manifest before delegating
When delegating to a subagent:
This ensures subagents have full context from earlier in the session.