feat(hindsight): richer session-scoped retain metadata (salvage of #6290) - #13987
Merged
Conversation
- 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>
This was referenced 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
6 tasks
This was referenced Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: threaduser_name,chat_id,chat_name,chat_type,thread_idfromMessageSourcethrough AIAgent into memory provider init kwargs (extends the existinguser_id/platformpattern onMemoryProvider).plugins/memory/hindsight/: addsretain_tags,retain_source,retain_user_prefix,retain_assistant_prefixconfig knobs;hindsight_retaintool schema gains optional per-calltagsmerged with defaults; identity fields ride along as retain metadata; transcripts use configurable user/assistant labels.Follow-ups applied on top
HERMES_SESSION_USER_IDtest that asserted against its own local assignment (exercised zero production code).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.