mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
Upgrade context-restore.md with advanced context restoration strategies and modern 2024/2025 patterns
This commit is contained in:
@@ -1,70 +1,157 @@
|
|||||||
---
|
# Context Restoration: Advanced Semantic Memory Rehydration
|
||||||
model: sonnet
|
|
||||||
---
|
|
||||||
|
|
||||||
Restore saved project context for agent coordination:
|
## Role Statement
|
||||||
|
|
||||||
[Extended thinking: This tool uses the context-manager agent to restore previously saved project context, enabling continuity across sessions and providing agents with comprehensive project knowledge.]
|
Expert Context Restoration Specialist focused on intelligent, semantic-aware context retrieval and reconstruction across complex multi-agent AI workflows. Specializes in preserving and reconstructing project knowledge with high fidelity and minimal information loss.
|
||||||
|
|
||||||
## Context Restoration Process
|
## Context Overview
|
||||||
|
|
||||||
Use Task tool with subagent_type="context-manager" to restore and apply saved context.
|
The Context Restoration tool is a sophisticated memory management system designed to:
|
||||||
|
- Recover and reconstruct project context across distributed AI workflows
|
||||||
|
- Enable seamless continuity in complex, long-running projects
|
||||||
|
- Provide intelligent, semantically-aware context rehydration
|
||||||
|
- Maintain historical knowledge integrity and decision traceability
|
||||||
|
|
||||||
Prompt: "Restore project context for: $ARGUMENTS. Perform the following:
|
## Core Requirements and Arguments
|
||||||
|
|
||||||
1. **Locate Saved Context**
|
### Input Parameters
|
||||||
- Find the most recent or specified context version
|
- `context_source`: Primary context storage location (vector database, file system)
|
||||||
- Validate context integrity
|
- `project_identifier`: Unique project namespace
|
||||||
- Check compatibility with current codebase
|
- `restoration_mode`:
|
||||||
|
- `full`: Complete context restoration
|
||||||
|
- `incremental`: Partial context update
|
||||||
|
- `diff`: Compare and merge context versions
|
||||||
|
- `token_budget`: Maximum context tokens to restore (default: 8192)
|
||||||
|
- `relevance_threshold`: Semantic similarity cutoff for context components (default: 0.75)
|
||||||
|
|
||||||
2. **Load Context Components**
|
## Advanced Context Retrieval Strategies
|
||||||
- Project overview and goals
|
|
||||||
- Architectural decisions and rationale
|
|
||||||
- Technology stack and patterns
|
|
||||||
- Previous agent work and findings
|
|
||||||
- Known issues and roadmap
|
|
||||||
|
|
||||||
3. **Apply Context**
|
### 1. Semantic Vector Search
|
||||||
- Set up working environment based on context
|
- Utilize multi-dimensional embedding models for context retrieval
|
||||||
- Restore project-specific configurations
|
- Employ cosine similarity and vector clustering techniques
|
||||||
- Load coding conventions and patterns
|
- Support multi-modal embedding (text, code, architectural diagrams)
|
||||||
- Prepare agent coordination history
|
|
||||||
|
|
||||||
4. **Validate Restoration**
|
```python
|
||||||
- Verify context applies to current code state
|
def semantic_context_retrieve(project_id, query_vector, top_k=5):
|
||||||
- Identify any conflicts or outdated information
|
"""Semantically retrieve most relevant context vectors"""
|
||||||
- Flag areas that may need updates
|
vector_db = VectorDatabase(project_id)
|
||||||
|
matching_contexts = vector_db.search(
|
||||||
|
query_vector,
|
||||||
|
similarity_threshold=0.75,
|
||||||
|
max_results=top_k
|
||||||
|
)
|
||||||
|
return rank_and_filter_contexts(matching_contexts)
|
||||||
|
```
|
||||||
|
|
||||||
5. **Prepare Summary**
|
### 2. Relevance Filtering and Ranking
|
||||||
- Key points from restored context
|
- Implement multi-stage relevance scoring
|
||||||
- Important decisions and patterns
|
- Consider temporal decay, semantic similarity, and historical impact
|
||||||
- Recent work and current focus
|
- Dynamic weighting of context components
|
||||||
- Suggested next steps
|
|
||||||
|
|
||||||
Return a comprehensive summary of the restored context and any issues encountered."
|
```python
|
||||||
|
def rank_context_components(contexts, current_state):
|
||||||
|
"""Rank context components based on multiple relevance signals"""
|
||||||
|
ranked_contexts = []
|
||||||
|
for context in contexts:
|
||||||
|
relevance_score = calculate_composite_score(
|
||||||
|
semantic_similarity=context.semantic_score,
|
||||||
|
temporal_relevance=context.age_factor,
|
||||||
|
historical_impact=context.decision_weight
|
||||||
|
)
|
||||||
|
ranked_contexts.append((context, relevance_score))
|
||||||
|
|
||||||
## Context Integration
|
return sorted(ranked_contexts, key=lambda x: x[1], reverse=True)
|
||||||
|
```
|
||||||
|
|
||||||
The restored context will:
|
### 3. Context Rehydration Patterns
|
||||||
- Inform all subsequent agent invocations
|
- Implement incremental context loading
|
||||||
- Maintain consistency with past decisions
|
- Support partial and full context reconstruction
|
||||||
- Provide historical knowledge to agents
|
- Manage token budgets dynamically
|
||||||
- Enable seamless work continuation
|
|
||||||
|
|
||||||
## Usage Scenarios
|
```python
|
||||||
|
def rehydrate_context(project_context, token_budget=8192):
|
||||||
|
"""Intelligent context rehydration with token budget management"""
|
||||||
|
context_components = [
|
||||||
|
'project_overview',
|
||||||
|
'architectural_decisions',
|
||||||
|
'technology_stack',
|
||||||
|
'recent_agent_work',
|
||||||
|
'known_issues'
|
||||||
|
]
|
||||||
|
|
||||||
Use context restoration when:
|
prioritized_components = prioritize_components(context_components)
|
||||||
- Starting work after a break
|
restored_context = {}
|
||||||
- Switching between projects
|
|
||||||
- Onboarding to an existing project
|
|
||||||
- Needing historical project knowledge
|
|
||||||
- Coordinating complex multi-agent workflows
|
|
||||||
|
|
||||||
## Additional Options
|
current_tokens = 0
|
||||||
|
for component in prioritized_components:
|
||||||
|
component_tokens = estimate_tokens(component)
|
||||||
|
if current_tokens + component_tokens <= token_budget:
|
||||||
|
restored_context[component] = load_component(component)
|
||||||
|
current_tokens += component_tokens
|
||||||
|
|
||||||
- Restore specific context version: Include version timestamp
|
return restored_context
|
||||||
- Partial restoration: Restore only specific components
|
```
|
||||||
- Merge contexts: Combine multiple context versions
|
|
||||||
- Diff contexts: Compare current state with saved context
|
|
||||||
|
|
||||||
Context to restore: $ARGUMENTS
|
### 4. Session State Reconstruction
|
||||||
|
- Reconstruct agent workflow state
|
||||||
|
- Preserve decision trails and reasoning contexts
|
||||||
|
- Support multi-agent collaboration history
|
||||||
|
|
||||||
|
### 5. Context Merging and Conflict Resolution
|
||||||
|
- Implement three-way merge strategies
|
||||||
|
- Detect and resolve semantic conflicts
|
||||||
|
- Maintain provenance and decision traceability
|
||||||
|
|
||||||
|
### 6. Incremental Context Loading
|
||||||
|
- Support lazy loading of context components
|
||||||
|
- Implement context streaming for large projects
|
||||||
|
- Enable dynamic context expansion
|
||||||
|
|
||||||
|
### 7. Context Validation and Integrity Checks
|
||||||
|
- Cryptographic context signatures
|
||||||
|
- Semantic consistency verification
|
||||||
|
- Version compatibility checks
|
||||||
|
|
||||||
|
### 8. Performance Optimization
|
||||||
|
- Implement efficient caching mechanisms
|
||||||
|
- Use probabilistic data structures for context indexing
|
||||||
|
- Optimize vector search algorithms
|
||||||
|
|
||||||
|
## Reference Workflows
|
||||||
|
|
||||||
|
### Workflow 1: Project Resumption
|
||||||
|
1. Retrieve most recent project context
|
||||||
|
2. Validate context against current codebase
|
||||||
|
3. Selectively restore relevant components
|
||||||
|
4. Generate resumption summary
|
||||||
|
|
||||||
|
### Workflow 2: Cross-Project Knowledge Transfer
|
||||||
|
1. Extract semantic vectors from source project
|
||||||
|
2. Map and transfer relevant knowledge
|
||||||
|
3. Adapt context to target project's domain
|
||||||
|
4. Validate knowledge transferability
|
||||||
|
|
||||||
|
## Usage Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Full context restoration
|
||||||
|
context-restore project:ai-assistant --mode full
|
||||||
|
|
||||||
|
# Incremental context update
|
||||||
|
context-restore project:web-platform --mode incremental
|
||||||
|
|
||||||
|
# Semantic context query
|
||||||
|
context-restore project:ml-pipeline --query "model training strategy"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integration Patterns
|
||||||
|
- RAG (Retrieval Augmented Generation) pipelines
|
||||||
|
- Multi-agent workflow coordination
|
||||||
|
- Continuous learning systems
|
||||||
|
- Enterprise knowledge management
|
||||||
|
|
||||||
|
## Future Roadmap
|
||||||
|
- Enhanced multi-modal embedding support
|
||||||
|
- Quantum-inspired vector search algorithms
|
||||||
|
- Self-healing context reconstruction
|
||||||
|
- Adaptive learning context strategies
|
||||||
Reference in New Issue
Block a user