Skip to main content

Google ADK integration for Hindsight - persistent long-term memory for ADK agents

Project description

hindsight-google-adk

Persistent long-term memory for Google ADK agents via Hindsight.

The package gives you two complementary patterns:

  • HindsightMemoryService — Implements ADK's BaseMemoryService. Pass it to Runner(memory_service=...) and sessions are automatically retained on completion; agents calling search_memory get results back from Hindsight.
  • create_hindsight_tools(...) — Returns a list of ADK FunctionTool instances (hindsight_retain, hindsight_recall, hindsight_reflect) the model can call inside a turn.

Installation

pip install hindsight-google-adk

Quick Start: Automatic Memory

import asyncio
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService

from hindsight_google_adk import HindsightMemoryService

memory = HindsightMemoryService.from_url(
    hindsight_api_url="https://api.hindsight.vectorize.io",
    api_key="hsk_...",
)

agent = LlmAgent(name="assistant", model="gemini-2.0-flash")

runner = Runner(
    app_name="my-app",
    agent=agent,
    session_service=InMemorySessionService(),
    memory_service=memory,
)

When a session ends, Runner calls add_session_to_memory, which retains the session's events to a Hindsight bank keyed by (app_name, user_id). When the agent (or another call) invokes search_memory(app_name, user_id, query), the integration runs a Hindsight recall and returns the results as ADK MemoryEntry objects.

Quick Start: Explicit Tools

from google.adk.agents import LlmAgent
from hindsight_google_adk import create_hindsight_tools

tools = create_hindsight_tools(
    bank_id="user-123",
    hindsight_api_url="https://api.hindsight.vectorize.io",
    api_key="hsk_...",
)

agent = LlmAgent(name="assistant", model="gemini-2.0-flash", tools=tools)

The agent now has three tools (toggle with include_retain / include_recall / include_reflect):

  • hindsight_retain(content) — store information to long-term memory
  • hindsight_recall(query) — search memory and return matches
  • hindsight_reflect(query) — synthesize a coherent answer from memory

Global Configuration

For shared defaults, call configure(...) once at startup:

from hindsight_google_adk import configure

configure(
    hindsight_api_url="https://api.hindsight.vectorize.io",
    api_key=None,                      # falls back to HINDSIGHT_API_KEY env var
    bank_id_template="{app_name}::{user_id}",
    budget="mid",
    max_tokens=4096,
)

Subsequent HindsightMemoryService.from_url() and create_hindsight_tools() calls use the global config as a fallback.

Bank ID Derivation

By default, each (app_name, user_id) pair gets its own bank: "{app_name}::{user_id}". Override with bank_id_template:

# Per-user bank shared across apps
HindsightMemoryService.from_url(..., bank_id_template="user::{user_id}")

# Static bank shared across all users
HindsightMemoryService.from_url(..., bank_id_template="my-shared-bank")

Configuration Reference

Argument Default Description
hindsight_api_url https://api.hindsight.vectorize.io Hindsight API URL (Cloud by default).
api_key HINDSIGHT_API_KEY env Bearer token for Hindsight Cloud.
bank_id_template "{app_name}::{user_id}" Format string for deriving the bank id.
budget "mid" Recall budget: low/mid/high.
max_tokens 4096 Max tokens for recall results.
tags None Extra tags added to retains. app: and user: are always added.
recall_tags None Extra tags appended to recall queries. user: is always added.
recall_tags_match "any" Tag match mode: any / all / any_strict / all_strict.
mission None If set, the bank is created (idempotent) on first use with this fact-extraction mission.
context "google-adk" Provenance label attached to retained content.

Memory Scoping with Tags

Each retained session/event carries app:<app_name> and user:<user_id> tags. Recall queries automatically include user:<user_id> so users never see each other's memories. Pass tags=[...] to extend the retain set or recall_tags=[...] to filter recall further.

Connection Modes

Hindsight Cloud (recommended)

HindsightMemoryService.from_url(
    hindsight_api_url="https://api.hindsight.vectorize.io",
    api_key="hsk_...",
)

Self-hosted

HindsightMemoryService.from_url(hindsight_api_url="http://localhost:8888")

Error Handling

All add_* and search_memory methods are resilient: Hindsight failures are logged but never propagate to the Runner. The explicit tools raise HindsightError on failure so the agent can react.

Requirements

  • Python 3.10+
  • google-adk>=2.0
  • hindsight-client>=0.4.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hindsight_google_adk-0.1.0.tar.gz (164.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hindsight_google_adk-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file hindsight_google_adk-0.1.0.tar.gz.

File metadata

  • Download URL: hindsight_google_adk-0.1.0.tar.gz
  • Upload date:
  • Size: 164.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hindsight_google_adk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edfdaa497f7ddd87179d710ec987c7795dd36be9ff43c4b60b901ed08da56903
MD5 333d14ade810448cbdf1ce95cee11449
BLAKE2b-256 908dda110b0db2e7830e8c381156c4fb0ccadff86d765a4f8fbdc2cdde5707aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for hindsight_google_adk-0.1.0.tar.gz:

Publisher: release-integration.yml on vectorize-io/hindsight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hindsight_google_adk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hindsight_google_adk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7508f7aa768b591d06d245a3891be3ada18e30a0a4faebf5c770f38a5a972d51
MD5 7f227e6bde21b96d9676269089f62916
BLAKE2b-256 548d600fe20bcf2e797dc36d0fc0492ac70c1a40a9cbc2b339bd9d4d41ca0321

See more details on using hashes here.

Provenance

The following attestation bundles were made for hindsight_google_adk-0.1.0-py3-none-any.whl:

Publisher: release-integration.yml on vectorize-io/hindsight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page