Agent skill
context-retrieval
Retrieve relevant episodic context from memory for informed decision-making. Use when you need past episodes, patterns, or solutions to similar tasks.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/context-retrieval
SKILL.md
Context Retrieval
Retrieve relevant episodic context from memory for informed decision-making.
Retrieval Methods
Semantic Search (Preferred)
When embeddings available:
let context = memory
.retrieve_relevant_context(
"implement async batch updates",
task_context,
limit: 5
)
.await?;
Advantages: Finds semantically similar tasks, captures intent
Keyword Search (Fallback)
// SQL index-based search
SELECT * FROM episodes
WHERE task_type = ? AND tags LIKE ?
ORDER BY timestamp DESC
LIMIT ?;
Advantages: Fast, no embedding computation, deterministic
Retrieval Strategy
- Parse query (key terms, domain, task type)
- Check embedding availability
- Query cache (redb) first, fall back to Turso
- Rank by relevance or recency
- Filter and limit results
- Format context structure
Context Filtering
// By domain
TaskContext { domain: "storage".to_string(), .. }
// By task type
task_type_filter: Some("implementation")
// By recency (last 30 days)
since: Some(now - Duration::days(30))
// By success only
verdict: Some(Verdict::Success)
Response Format
pub struct RetrievedContext {
pub episodes: Vec<EpisodeSummary>,
pub patterns: Vec<Pattern>,
pub heuristics: Vec<Heuristic>,
pub relevance_scores: Vec<f32>,
}
pub struct EpisodeSummary {
pub id: String,
pub task_description: String,
pub verdict: Verdict,
pub key_steps: Vec<String>,
pub reflection: String,
pub relevance: f32,
}
Usage Examples
// Find similar implementation tasks
let retrieved = memory
.retrieve_relevant_context(query, context, 10)
.await?;
// Find common tool sequences
let patterns = memory
.get_patterns_by_type("ToolSequence")
.filter(|p| p.success_rate > 0.8)
.await?;
// Find error resolutions
let solutions = memory
.retrieve_error_resolutions("borrow checker error", 5)
.await?;
Troubleshooting
| Issue | Solution |
|---|---|
| Low recall | Check embeddings, expand tags, increase limit |
| Slow retrieval | Check cache, verify indexes, reduce result set |
| Poor relevance | Use semantic search, improve query, filter by domain |
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?