Skip to content

Self-learning gaps: no procedural memory, proactive strategy injection, or tool fallback chains #25

Description

@xinhuagu

Problem

When the agent encounters a non-UTF-8 file (e.g., COBOL .cbl in EBCDIC/Shift-JIS/GBK), read_file fails and the agent gives up, asking the user to convert the file manually. After multiple such failures, the self-learning pipeline (ErrorDetector → persist → StrategyRefiner) only stores a generic text description like:

ERROR_RECOVERY: Tool 'read_file' error: invalid byte sequence — resolved by: using iconv to convert encoding

This is insufficient — the agent never learns to autonomously recover from the same error in future sessions.

Root Cause Analysis

The self-learning pipeline (Issues #13-#18) captures what happened but not how to act on it. Four specific gaps:

1. No Procedural Memory (multi-step recovery recipes)

ErrorInsight stores a single-sentence description. It cannot represent executable multi-step recovery:

1. file -i <path>                          → detect encoding
2. iconv -f <detected> -t utf-8 <path>    → convert
3. read_file <converted_path>              → re-read

The architecture plan's procedural memory type (step-by-step recipes) is not yet implemented.

2. No Proactive Strategy Injection

Learned experiences are only used during detection (cross-session confidence boosting). They are never injected into the system prompt before a tool call. Ideal behavior:

"Last time .cbl files were EBCDIC. Check encoding with file -i before reading."

Currently, auto-memory uses passive TF-IDF retrieval for prompt injection, but learned SUCCESSFUL_STRATEGY entries from the self-improvement pipeline are not surfaced proactively when relevant tools are about to be called.

3. No Tool Fallback Chain

When read_file fails with an encoding error, the agent should autonomously execute a fallback chain instead of asking the user. There is no mechanism for learned experiences to modify tool execution behavior (e.g., retry with encoding detection).

4. Error Classification Too Coarse

ErrorDetector treats all read_file failures the same. Different error types need different recovery strategies:

Error Type Recovery
Encoding error Detect charset → iconv → re-read
File not found Search for correct path → retry
Permission denied Check permissions → chmod/sudo
File too large Read with offset/limit

Proposed Solutions

P0: ReadFileTool charset auto-detection

  • Use java.nio.charset.CharsetDetector or file -i heuristic before reading
  • Fallback chain: try UTF-8 → detect charset → convert → read
  • This fixes the immediate problem at the tool layer

P1: RecoveryRecipe (procedural memory)

  • Extend Insight sealed interface with a new RecoveryRecipe permit
  • Fields: triggerPattern (error signature), steps: List<RecoveryStep>, confidence
  • RecoveryStep record: toolName, description, parameterTemplate
  • ErrorDetector learns multi-step patterns when agent self-corrects across multiple tool calls

P2: Proactive strategy injection into system prompt

  • Before each tool call, query memory for SUCCESSFUL_STRATEGY entries matching the tool name
  • Inject relevant strategies as "learned tips" in the system prompt or tool description
  • Enables the agent to avoid known pitfalls before they happen

P3: Error classifier + recovery strategy mapping

  • Classify errors by type (encoding, path, permission, size, timeout, etc.)
  • Map each error class to a specific RecoveryRecipe
  • ErrorDetector produces typed insights instead of generic text

Priority

P0 (tool fix) is the most impactful immediate change. P1-P3 enhance the self-learning system's ability to learn and apply multi-step recovery autonomously.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions