fleet-memory/hindsight-integrations/llamaindex/hindsight_llamaindex/__init__.py
DK09876 d93dfea8ce
fix(llamaindex): document_id, memory API, and ReAct trace fixes (#777)
* fix(llamaindex): use uuid for document_id and sync version metadata

- Replace timestamp-based document_id with uuid4 hex to prevent
  collisions on rapid retains (timestamp_ms can duplicate in tight loops)
- Sync __version__ in __init__.py to match pyproject.toml (0.1.2)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(docs): pass memory to run() instead of ReActAgent constructor

LlamaIndex 0.14.x ReActAgent does not accept a memory parameter in
its constructor — it's silently dropped via **kwargs. Memory must be
passed to agent.run(memory=...) where AgentWorkflow picks it up.

Also fixes the undefined `tools` variable (now `tools=[]`).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(llamaindex): strip ReAct reasoning traces from retained assistant messages

HindsightMemory.put/aput now extracts only the final Answer: text from
assistant messages containing ReAct reasoning (Thought:/Action:/Observation:
prefixes), preventing internal reasoning traces from polluting long-term memory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(llamaindex): fix docstring example to pass memory to run()

The HindsightMemory class docstring showed the broken pattern of passing
memory= to the ReActAgent constructor, which silently drops it. Updated
to show the correct pattern: pass memory to agent.run().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 18:33:03 +02:00

40 lines
1 KiB
Python

"""Hindsight memory integration for LlamaIndex agents.
Provides two complementary patterns:
- **Tools** (``HindsightToolSpec``, ``create_hindsight_tools``):
Agent-driven memory via LlamaIndex's ``BaseToolSpec``.
The agent decides when to retain/recall/reflect.
- **Memory** (``HindsightMemory``):
Automatic memory via LlamaIndex's ``BaseMemory`` interface.
Messages are stored on ``put()`` and recalled on ``get()``.
Usage::
from hindsight_llamaindex import HindsightToolSpec, create_hindsight_tools
from hindsight_llamaindex import HindsightMemory
"""
from .config import (
HindsightLlamaIndexConfig,
configure,
get_config,
reset_config,
)
from .errors import HindsightError
from .memory import HindsightMemory
from .tools import HindsightToolSpec, create_hindsight_tools
__version__ = "0.1.2"
__all__ = [
"configure",
"get_config",
"reset_config",
"HindsightLlamaIndexConfig",
"HindsightError",
"HindsightToolSpec",
"create_hindsight_tools",
"HindsightMemory",
]