Skip to content

🧠 [P1] Agent recall optimization β€” ensure memories are actually used by Hermes agentsΒ #181

Closed

Description

@ajianaz

Problem

Uteke auto-recall hook works correctly β€” it fires on agent:start, queries relevant memories, and writes results to /tmp/hermes/uteke-context/{agent}.md. However, agents frequently ignore the recalled context despite it being available.

Root Cause Analysis

  1. Context file is passive β€” The hook writes to a file, but agents must explicitly read_file() it. LLMs tend to skip reading context files unless strongly prompted.

  2. No injection into system prompt β€” Unlike knowledge tool which has search_knowledge baked into the SOUL.md instructions, uteke recall results are stored in a side-file that agents "should" read but often forget.

  3. Recall timing β€” The hook runs on agent:start which is correct, but the context file gets overwritten each turn. If the agent doesn't read it in the first response, the opportunity is lost.

  4. Dual namespace confusion β€” Hook queries both hermes-knowledge and {agent} namespaces, but the agent's SOUL.md only mentions manual uteke recall β€” no instruction to read the auto-generated context file.

  5. No feedback loop β€” Agents don't report whether they used recalled memories. No metric to measure recall utilization.

Proposal: Multi-layered Recall Optimization

Layer 1: Direct System Prompt Injection (High Impact, Low Effort)

Instead of writing to a file that agents must read, inject recalled memories directly into the message context via the hook system.

Implementation:

# In handler.py handle() function for agent:start
# Instead of (or in addition to) writing to file:
# Return the recalled context so gateway can inject it

def handle(event_type: str, context: dict):
    if event_type == "agent:start":
        # ... recall logic ...
        
        # Option A: Return as hook result for gateway injection
        return {
            "inject_system": "\n".join(formatted_results),
            "inject_section": "uteke-recall"  # marker for dedup
        }

Gateway would prepend this to the user message or append to system prompt.

Layer 2: Hermes Plugin Integration (High Impact, Medium Effort)

Create a proper Hermes tool plugin that wraps uteke as a native tool:

# In agent config.yaml tools section
tools:
  - name: uteke_recall
    description: "Recall relevant memories from local uteke store"
    command: "uteke recall"
    auto_run: true  # run automatically at session start

This makes uteke a first-class tool like knowledge β€” agents see it in their tool list and are prompted to use it.

Layer 3: Persistent Recall Summary in SOUL.md (Medium Impact, Low Effort)

Add a section to SOUL.md templates:

## Uteke Context (Auto-Loaded)
> The following memories were auto-recalled for this session.
> File: /tmp/hermes/uteke-context/{agent}.md
> ⚠️ YOU MUST read this file before responding to any message.

Layer 4: Recall Metrics and Dashboard (Low Impact, High Effort)

Track recall utilization:

  • recall_count β€” how many times recall fired
  • usage_count β€” how many times agent referenced recalled content
  • hit_rate β€” usage_count / recall_count

Expose via uteke stats --detailed or a dashboard.

Layer 5: Smart Recall Caching (Medium Impact, Medium Effort)

Currently recall runs on every agent:start event (every message). Optimize:

  • Cache recall results keyed by message hash
  • Only re-run if message topic changes significantly (>0.3 embedding distance)
  • TTL cache: reuse results for follow-up messages in same topic
  • Invalidate on topic shift detection

This reduces uteke CPU usage and prevents context file thrashing.

Recommended Priority

Layer Impact Effort Priority
Layer 1: System prompt injection High Low P1 β€” Do first
Layer 3: SOUL.md instruction fix High Low P1 β€” Do first
Layer 2: Hermes plugin tool Medium Medium P2
Layer 5: Smart caching Medium Medium P2
Layer 4: Metrics dashboard Low High P3

Acceptance Criteria

  • Agent reads recalled memories in >90% of sessions (measured by checking if recalled content appears in agent responses)
  • Recall context is visible in agent's first response without manual file read
  • No performance regression (recall + injection < 500ms total)
  • Works for all Hermes agents (namespace-aware)
  • Backward compatible β€” existing hook + file approach still works as fallback

Related

Activity

  1. added
    scope:core
    scope:integration
    type:feature
    v0.1.0
    enhancement
    and removed
    type:feature
    on Jun 7, 2026
  2. added this to the milestone on Jun 11, 2026
  3. ajianaz commented on Jun 11, 2026

    @ajianaz
    CollaboratorAuthor

    🧠 Update: Room as Natural Recall Trigger (from SurrealDB analysis, #286)

    Room Solves the Recall Gap

    The root problem identified in this issue β€” agents ignoring recalled context β€” has a natural solution via Rooms (#286):

    How Room Fixes This

    1. Auto-detect room: Hermes gateway detects Discord thread ID β†’ auto-sets --room flag β†’ agent automatically has room context
    2. No file reading needed: Room context is returned directly via uteke recall --room <id> β€” no passive file that agents must remember to read
    3. Cross-agent continuity: When CTO stores analysis and Zeko joins later, Zeko recalls room β†’ gets CTO context without explicit handoff
    4. Session continuation: New session in same thread β†’ auto-recall room β†’ "Previously discussed: SurrealDB, graph layer, license risks"

    Implementation: Room-Aware Recall Hook

    # In Hermes hook handler.py
    def handle(event_type, context):
        if event_type == "agent:start":
            thread_id = context.get("thread_id")
            if thread_id:
                # Auto-join room and recall context
                room_context = subprocess.run(
                    ["uteke", "recall", "--room", thread_id, "--summary", "--json"],
                    capture_output=True, text=True
                )
                return {
                    "inject_system": room_context.stdout,
                    "inject_section": "uteke-room-context"
                }

    Updated Acceptance Criteria (add to existing)

    • Hermes hook auto-detects thread/room ID on agent:start
    • Auto-recall room context on session start (no manual file read)
    • Room context injected into system prompt (not side file)
    • Agent stores contributions to room automatically (--room auto-set)
    • Cross-agent recall: Zeko can see CTO room contributions
    • Metrics: track room recall hit rate (was context used?)

    Dependency Note

    #286 (Room) must be implemented first β€” room tables and CLI must exist before hooks can use them. This issue (#181) becomes the integration layer between room feature and Hermes gateway. Order: #249 β†’ #286 β†’ #246 β†’ #248 β†’ #247 β†’ THIS (#181).

  4. added 2 commits that reference this issue on Jun 12, 2026
  5. added a commit that references this issue on Jul 2, 2026
  6. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:mediumscope:corescope:integrationv0.1.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions