-
Notifications
You must be signed in to change notification settings - Fork 3
Auto Capture System
Comprehensive guide to automatic memory extraction from conversations.
The auto-capture system automatically extracts important information from conversations using AI. Version 2.0 introduces a prompt-based system replacing the previous token-based approach.
Token-based auto-capture has been removed. The following configuration options are no longer supported:
autoCaptureTokenThresholdautoCaptureMinTokensautoCaptureMaxMemoriesautoCaptureSummaryMaxLengthautoCaptureContextWindow
Migration required: Remove these options from your configuration file.
- Session Idle Detection: Triggers when conversation pauses
- Prompt Analysis: Analyzes last uncaptured user prompt and AI response
- Memory Extraction: AI identifies important information
- Scope Assignment: Determines user vs project scope
- Prompt Linking: Creates bidirectional link between prompt and memory
- Skip Logic: Non-technical conversations are skipped and prompts deleted
- Context Continuity: Includes previous project memory for context
- Background Processing: Runs without blocking conversation
How It Differs from Token-Based:
- Old: Monitored cumulative token count, triggered at threshold
- New: Triggers on session idle, analyzes single prompt-response pair
- Benefits: Simpler, more predictable, lower cost, better quality
Why Prompt-Based:
- Ensures each prompt gets analyzed individually
- Prevents missing important information between captures
- Reduces API costs (analyzes less context)
- Creates clear prompt-memory relationships
- Easier to understand and debug
The system automatically skips non-technical conversations:
- AI returns
type: "skip"for casual/non-technical content - Prompt is deleted from database
- No memory is created
- Keeps database clean and focused
Examples of Skipped Content:
- Greetings and casual chat
- Simple questions with no learning value
- Off-topic discussions
- Repetitive queries
Each capture includes the previous project memory for context:
# Previous Project Memory
[Content of last project memory]
---
# Current Conversation
User: [prompt]
Assistant: [response]Horizontal rules (---) separate sections for clear AI parsing.
{
"userMemoryAnalysisInterval": 10,
"autoCaptureMaxIterations": 5,
"autoCaptureIterationTimeout": 30000
}Type: boolean
Default: true
Enable or disable auto-capture.
{
"autoCaptureEnabled": true
}Type: string
Default: openai-chat
AI provider for memory extraction.
Supported Providers:
{
"memoryProvider": "openai-chat"
}{
"memoryProvider": "anthropic"
}{
"memoryProvider": "openai-responses"
}Provider Selection:
-
openai-chat: OpenAI Chat Completions API (GPT-4, GPT-3.5) -
anthropic: Anthropic Messages API (Claude) -
openai-responses: OpenAI Responses API (experimental)
Type: string
Required: Yes
AI model for memory extraction.
OpenAI Models:
{
"memoryProvider": "openai-chat",
"memoryModel": "gpt-4"
}Supported: gpt-4, gpt-4-turbo, gpt-3.5-turbo
Anthropic Models:
{
"memoryProvider": "anthropic",
"memoryModel": "claude-3-5-sonnet-20241022"
}Supported: claude-3-5-sonnet-20241022, claude-3-opus-20240229, claude-3-sonnet-20240229
Model Selection:
- GPT-4: Best quality, higher cost
- GPT-3.5-Turbo: Good balance, lower cost
- Claude-3.5-Sonnet: Excellent quality, fast
- Claude-3-Opus: Highest quality, highest cost
Type: string
Required: Yes
API endpoint for memory extraction.
Provider URLs:
OpenAI:
{
"memoryApiUrl": "https://api.openai.com/v1"
}Anthropic:
{
"memoryApiUrl": "https://api.anthropic.com/v1"
}OpenAI-compatible (Groq, etc.):
{
"memoryApiUrl": "https://api.groq.com/openai/v1"
}Type: string
Required: Yes
API key for authentication.
{
"memoryApiKey": "sk-your-api-key-here"
}Environment Variable:
Alternatively, set environment variable:
export OPENAI_API_KEY=sk-your-api-key-hereType: number
Default: 10
Number of prompts between user learning analysis.
{
"userMemoryAnalysisInterval": 10
}Tuning:
- Lower (5): More frequent analysis, higher cost
- Default (10): Balanced
- Higher (20): Less frequent, lower cost
See User Learning System below.
Type: number
Default: 5
Maximum retry iterations for capture.
{
"autoCaptureMaxIterations": 5
}Type: number
Default: 30000
Timeout per iteration in milliseconds.
{
"autoCaptureIterationTimeout": 30000
}Separate from auto-capture, the user learning system analyzes batches of prompts to identify patterns.
- Tracks prompts with
user_learning_capturedflag - Triggers after N prompts (default: 10)
- Analyzes batch of prompts for patterns
- Generates user-scoped memories about:
- Coding style preferences
- Communication patterns
- Tool preferences
- Skill level indicators
- Independent from prompt-based auto-capture
{
"userMemoryAnalysisInterval": 10
}Set to 0 to disable user learning analysis.
- User patterns require batch analysis, not per-conversation
- Different tracking flag prevents data loss
- Can be disabled independently
- Different trigger mechanism
Once configured, auto-capture runs automatically:
- Have conversations with the AI agent
- System monitors session activity
- Captures trigger on idle
- Memories stored in background
- Prompts linked to memories
- No user interaction required
Force immediate capture:
memory({ mode: "capture-now" })Useful for:
- Capturing important conversation immediately
- Testing auto-capture configuration
- Forcing capture before session end
Enable or disable at runtime:
memory({ mode: "auto-capture-toggle" })Returns new state:
Auto-capture is now: enabled
Check auto-capture performance:
memory({ mode: "auto-capture-stats" })Returns:
- Total captures performed
- Total memories created
- Last capture timestamp
- Linked prompts count
User Scope:
- Personal preferences
- Coding style
- Tool preferences
- Communication patterns
- General knowledge
Project Scope:
- Architecture decisions
- Technology choices
- Implementation details
- Bug fixes
- Feature requirements
Factors Affecting Quality:
- Model Selection: Better models extract more accurately
- Conversation Quality: Clear discussions yield better memories
- Context Continuity: Previous memory provides better context
- Skip Logic: Prevents noise from casual conversations
Optimization:
For best results:
- Use GPT-4 or Claude-3.5-Sonnet
- Maintain clear, structured conversations
- Provide explicit context when needed
- Let skip logic filter out noise
Each captured memory is linked to its source prompt:
- Bidirectional relationship stored in database
-
user_prompts.linked_memory_idpoints to memory - Memory metadata includes prompt reference
- Web interface shows visual link indicators
- Trace memory origin
- Cascade delete support
- Timeline view with context
- Better debugging and auditing
Delete memory and linked prompt together:
DELETE /api/memories/:id?cascade=trueDelete prompt and linked memory together:
DELETE /api/prompts/:id?cascade=truePer Capture:
- Single prompt-response pair: ~500-1000 tokens
- Model call: ~$0.005-0.015 per capture (GPT-4)
- Frequency: Per conversation session
Monthly Estimate:
- Active usage: 50 conversations/day
- Captures: ~50 per day
- Cost: ~$7.50-22.50/month (GPT-4)
Use Cheaper Models:
{
"memoryModel": "gpt-3.5-turbo"
}Reduces cost by 90% with slight quality decrease.
Use Claude:
{
"memoryProvider": "anthropic",
"memoryModel": "claude-3-5-sonnet-20241022"
}Good balance of quality and cost.
Disable User Learning:
{
"userMemoryAnalysisInterval": 0
}Reduces batch analysis costs.
View auto-capture statistics:
memory({ mode: "auto-capture-stats" })Access statistics in web interface:
- Open
http://127.0.0.1:4747 - View timeline with linked prompts
- See capture statistics
Check OpenCode logs for capture events:
[AutoCapture] Triggered on session idle
[AutoCapture] Analyzing prompt: <prompt_id>
[AutoCapture] Extracted memory: <memory_id>
[AutoCapture] Linked prompt to memory
Verify Configuration:
{
"autoCaptureEnabled": true,
"memoryProvider": "openai-chat",
"memoryModel": "gpt-4",
"memoryApiUrl": "https://api.openai.com/v1",
"memoryApiKey": "sk-..."
}Check API Key:
Test API key:
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer sk-your-api-key"Check Logs:
Look for errors in OpenCode logs.
Check Skip Logic:
System may be skipping non-technical conversations. This is expected behavior.
Check Conversation Quality:
Ensure conversations contain extractable technical information.
Force Capture:
memory({ mode: "capture-now" })Check Database:
Verify user_prompts.linked_memory_id is populated.
Check Web Interface:
Timeline should show link indicators.
Check Logs:
Look for linking errors in logs.
Start with Defaults:
{
"autoCaptureEnabled": true,
"memoryProvider": "openai-chat",
"memoryModel": "gpt-4",
"userMemoryAnalysisInterval": 10
}Monitor and Adjust:
Check statistics regularly and tune based on results.
Use Appropriate Model:
Balance cost and quality based on needs.
Be Explicit:
State important information clearly.
Provide Context:
Explain decisions and reasoning.
Structured Discussions:
Organize conversations logically.
Review Captured Memories:
Periodically check quality of auto-captured memories.
Run Deduplication:
Remove duplicate memories created by auto-capture.
Monitor Costs:
Track API usage and adjust settings if needed.
Delete these from your config:
{
"autoCaptureTokenThreshold": 10000,
"autoCaptureMinTokens": 20000,
"autoCaptureMaxMemories": 10,
"autoCaptureSummaryMaxLength": 0,
"autoCaptureContextWindow": 3
}Add these to your config:
{
"memoryProvider": "openai-chat",
"userMemoryAnalysisInterval": 10,
"autoCaptureMaxIterations": 5,
"autoCaptureIterationTimeout": 30000
}- Old: Captured multiple memories at token threshold
- New: Captures single memory per prompt on session idle
- Old: No prompt tracking
- New: Full prompt-memory linking
- Old: No skip logic
- New: Automatic skip for non-technical content
- Memory Operations - Manual memory management
- Configuration Guide - All configuration options
- Web Interface - Unified timeline view
- Performance Tuning - Optimization strategies
{ "autoCaptureEnabled": true, "memoryProvider": "openai-chat", "memoryModel": "gpt-4", "memoryApiUrl": "https://api.openai.com/v1", "memoryApiKey": "sk-your-api-key-here" }