Skip to content

feat(hindsight): richer session-scoped retain metadata (salvage of #6290) - #13987

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e6acc55f
Apr 22, 2026
Merged

feat(hindsight): richer session-scoped retain metadata (salvage of #6290)#13987
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e6acc55f

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #6290 by @Abnertheforeman onto current main (PR was ~118 commits behind).

Summary

Native Hindsight retains now carry gateway session identity (user, chat, thread) as metadata, support configurable retain tags/source/transcript labels, and merge per-call tool tags with configured defaults.

Changes

  • run_agent.py, gateway/run.py: thread user_name, chat_id, chat_name, chat_type, thread_id from MessageSource through AIAgent into memory provider init kwargs (extends the existing user_id/platform pattern on MemoryProvider).
  • plugins/memory/hindsight/: adds retain_tags, retain_source, retain_user_prefix, retain_assistant_prefix config knobs; hindsight_retain tool schema gains optional per-call tags merged with defaults; identity fields ride along as retain metadata; transcripts use configurable user/assistant labels.
  • Docs + README updated.

Follow-ups applied on top

  • Dropped a tautological HERMES_SESSION_USER_ID test that asserted against its own local assignment (exercised zero production code).
  • Added AUTHOR_MAP entry so release notes attribute commits to @Abnertheforeman.

Validation

scripts/run_tests.sh tests/plugins/memory/test_hindsight_provider.py tests/agent/test_memory_user_id.py tests/gateway/test_session_env.py → 70/70 passed.

Closes #6290. Original commits squashed with @Abnertheforeman's authorship preserved via --author.

Abnertheforeman and others added 2 commits April 22, 2026 05:23
- Add configurable retain_tags / retain_source / retain_user_prefix /
  retain_assistant_prefix knobs for native Hindsight.
- Thread gateway session identity (user_name, chat_id, chat_name,
  chat_type, thread_id) through AIAgent and MemoryManager into
  MemoryProvider.initialize kwargs so providers can scope and tag
  retained memories.
- Hindsight attaches the new identity fields as retain metadata,
  merges per-call tool tags with configured default tags, and uses
  the configurable transcript labels for auto-retained turns.

Co-authored-by: Abner <abner.the.foreman@agentmail.to>
Comment thread plugins/memory/hindsight/__init__.py Dismissed
Comment thread plugins/memory/hindsight/__init__.py Dismissed
@teknium1
teknium1 merged commit ba7e8b0 into main Apr 22, 2026
11 of 13 checks passed
@teknium1
teknium1 deleted the hermes/hermes-e6acc55f branch April 22, 2026 12:27
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery tool/memory Memory tool and memory providers labels Apr 22, 2026
kkangg1 added a commit to kkangg1/hermes-agent that referenced this pull request Jun 3, 2026
The hindsight_retain tool calls client.aretain() without retain_async, defaulting to False (synchronous mode). On banks with significant data, synchronous processing exceeds the 120s timeout, producing:

  Tool hindsight_retain returned error (120.01s): {"error": "Failed to store memory: "}

The auto-retain path (sync_turn) works correctly because it passes retain_async=self._retain_async (True) to aretain_batch.

Fix add retain_async=True to _build_retain_kwargs in the tool handler (1 line).

## What does this PR do?

Add retain_async=True to the _build_retain_kwargs call in the hindsight_retain tool handler, making the tool use asynchronous processing consistent with the auto-retain path (sync_turn). Previously the tool defaulted to retain_async=False (synchronous mode), causing timeouts on banks with significant data when the Hindsight APIs LLM extraction took longer than 120 seconds.

## Related Issues

- Closes NousResearch#29079 (Embedded Hindsight retain reports failure while async retain later appears in recall)
- References NousResearch#7974 (Bug hindsight_retain tool fails with Connection refused while hindsight_recall works)
- Follow-up to PR NousResearch#13987 (feat richer session-scoped retain metadata introduced _build_retain_kwargs without retain_async)
- Similar to PR NousResearch#9869 (Hindsight plugin hardcoded 30s timeout causes hindsight_reflect to fail same timeout pattern)

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- plugins/memory/hindsight/__init__.py Add retain_async=True parameter to _build_retain_kwargs() call in handle_tool_call for hindsight_retain (line 1508)

## How to Test

1. Start Hermes with memory provider hindsight (local or cloud)
2. Call hindsight_retain with any content via CLI or gateway session
3. Observe the tool returns success within seconds instead of timing out at 120s
4. Verify retained content appears in hindsight_recall

## Checklist

### Code

- [x] Ive read the Contributing Guide
- [x] My commit messages follow Conventional Commits
- [x] I searched for existing PRs to make sure this isnt a duplicate
- [x] My PR contains only changes related to this fix/feature (no unrelated commits)

### Documentation

- [x] N/A Documentation update not needed (one-line fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants