Enhanced auto-memory with rich few-shot format

- Updated memory reminder prompt with per-symbol char ranges
- Added two few-shot examples: Session Continuation (feature) + UTF-8 Safe Slicing (pattern)
- Updated system prompt Memory Format section to match
- Format: file -> nested symbols with [start..end] ranges and descriptions
- Enables direct read_file navigation to specific functions
This commit is contained in:
Dhanji R. Prasanna
2026-01-13 21:49:48 +05:30
parent 3a47ebe668
commit a1dfd9c0b6
3 changed files with 64 additions and 8 deletions

View File

@@ -1416,7 +1416,37 @@ impl<W: UiWriter> Agent<W> {
debug!("Auto-memory: Sending reminder to LLM ({} tools called this turn: {:?})", tools_called.len(), tools_called);
self.ui_writer.print_context_status("\nMemory checkpoint: ");
let reminder = "SYSTEM REMINDER: You used tools during this turn. If you discovered any key code locations, patterns, or entry points that aren't already in Project Memory, please call the `remember` tool now to save them. If you didn't discover anything new worth remembering, you can skip this. Respond briefly after deciding.";
let reminder = r#"MEMORY CHECKPOINT: If you discovered code locations worth remembering, call `remember` now.
Use this rich format:
### Feature Name
Brief description of what this feature/subsystem does.
- `path/to/file.rs`
- `FunctionName()` [1200..1450] - what it does, key params/return
- `StructName` [500..650] - purpose, key fields
- `related_function()` - how it connects
### Pattern Name
When to use this pattern and why.
1. First step
2. Second step
3. Key gotcha or tip
Example of a good entry:
### Session Continuation
Save/restore session state across g3 invocations using symlink-based approach.
- `crates/g3-core/src/session_continuation.rs`
- `SessionContinuation` [850..2100] - artifact struct with session state, TODO snapshot, context %
- `save_continuation()` [5765..7200] - saves to `.g3/sessions/<id>/latest.json`, updates symlink
- `load_continuation()` [7250..8900] - follows `.g3/session` symlink to restore
- `find_incomplete_agent_session()` [10500..13200] - finds sessions with incomplete TODOs for agent resume
Skip if nothing new. Be brief."#;
// Add the reminder as a user message and get a response
self.context_window.add_message(Message::new(

View File

@@ -109,17 +109,25 @@ Use this format when calling `remember`:
```
### <Feature Name>
- `<file_path>` [<start>..<end>] - `<function_name>()`, `<StructName>`
Brief description of what this feature/subsystem does.
- `<file_path>`
- `FunctionName()` [1200..1450] - what it does, key params/return
- `StructName` [500..650] - purpose, key fields
- `related_function()` - how it connects
### <Pattern Name>
When to use this pattern and why.
1. Step one
2. Step two
3. Key gotcha or tip
```
## When to Remember
**ALWAYS** call `remember` at the END of your turn when you discovered:
- A feature's location (file + char range + function/struct names)
- A feature's location with purpose and key entry points
- A useful pattern or workflow
- An entry point for a subsystem
@@ -129,9 +137,13 @@ Do NOT save duplicates - check the Project Memory section (loaded at startup) to
## Example
After discovering where WebDriver tools live:
After discovering how session continuation works:
{\"tool\": \"remember\", \"args\": {\"notes\": \"## Features\\n\\n### WebDriver Browser Automation\\n- crates/g3-core/src/tools/webdriver.rs [0..21750] - execute_webdriver_start(), execute_webdriver_navigate(), WebDriverSession\"}}
{\"tool\": \"remember\", \"args\": {\"notes\": \"### Session Continuation\\nSave/restore session state across g3 invocations using symlink-based approach.\\n\\n- `crates/g3-core/src/session_continuation.rs`\\n - `SessionContinuation` [850..2100] - artifact struct with session state, TODO snapshot, context %\\n - `save_continuation()` [5765..7200] - saves to `.g3/sessions/<id>/latest.json`, updates symlink\\n - `load_continuation()` [7250..8900] - follows `.g3/session` symlink to restore\\n - `find_incomplete_agent_session()` [10500..13200] - finds sessions with incomplete TODOs for agent resume\"}}
After discovering a useful pattern:
{\"tool\": \"remember\", \"args\": {\"notes\": \"### UTF-8 Safe String Slicing\\nRust string slices use byte indices. Multi-byte chars (emoji, CJK) cause panics if sliced mid-character.\\n\\n1. Use `s.char_indices().nth(n)` to get byte index of Nth character\\n2. Use `s.chars().count()` for length, not `s.len()`\\n3. Danger zones: display truncation, user input, any non-ASCII text\"}}
# Response Guidelines