agent_with_memory/

directory
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: Apache-2.0

README

Agent with memory (agent_with_memory)

Examples that wire long-term memory into agent-sdk-go. Pick one backend per run.

Backend Package Example entrypoint
Weaviate pkg/memory/weaviate go run ./agent_with_memory/weaviate
PostgreSQL + pgvector pkg/memory/pgvector go run ./agent_with_memory/pgvector

Store mode is selected with MEMORY_STORE_MODE (always or ondemand; default ondemand). Both backends support both modes. task examples:local runs four combinations (each backend × each mode).

Uses the same Docker stack as retriever examples (../docker/). task infra:weaviate:up / task infra:pgvector:up creates the memory class/table (AgentMemory / agent_memories) in addition to retriever schema. No seed rows for memory — rows are written by agent runs.

Prerequisites

  • RuntimeAGENT_RUNTIME=local (default): in-process, no Temporal. Optional AGENT_RUNTIME=temporal: from examples/, run task infra:temporal:up (and task infra:temporal:wait if the example fails to connect). See temporal-setup.md.
  • examples/.envLLM_APIKEY, LLM_MODEL, and EMBEDDING_OPENAI_APIKEY (see .env.defaults)
  • Task (go-task) and Docker (task infra:weaviate:up or task infra:pgvector:up)

From examples/:

task infra:status    # see what is up

Example behavior

  • Store modeMEMORY_STORE_MODE=always extracts and stores at run end; ondemand registers save_memory for the LLM during the run (default).
  • No CLI args — two runs in one process: run 1 stores a preference, run 2 recalls it.
  • With args — single custom prompt.
  • ScopeMEMORY_USER_ID in .env (default demo-user); must be the same across runs you want to share memories.

Set MEMORY_RECALL_ENABLED=false in .env for store-only (skip load before LLM).

Use SHOW_TELEMETRY=true to see total_memory_stores on run 1 when store succeeds.


Weaviate

Weaviate embeds memory text via nearText (text2vec-openai in Docker).

Setup
cd examples
task infra:weaviate:up
task infra:weaviate:down   # when finished

Compose: docker/docker-compose.yml. Seed: docker/weaviate/seed.sh (creates class AgentMemory).

EMBEDDING_OPENAI_APIKEY must be set in examples/.env before up. After a key change: task infra:weaviate:down && task infra:weaviate:up.

Verify the memory class exists:

curl -s http://localhost:8080/v1/schema | jq '.classes[].class'
# expect Document and AgentMemory
Environment
WEAVIATE_HOST=localhost:8080
WEAVIATE_SCHEME=http
WEAVIATE_MEMORY_CLASS=AgentMemory
MEMORY_USER_ID=demo-user
MEMORY_RECALL_ENABLED=true
MEMORY_RECALL_LIMIT=10
MEMORY_RECALL_MIN_SCORE=0.35
Run
go run ./agent_with_memory/weaviate
go run ./agent_with_memory/weaviate "Remember my favorite color is blue"
SHOW_TELEMETRY=true go run ./agent_with_memory/weaviate
Weaviate troubleshooting
Symptom What to do
missing class data / memory recall error on first run Usually empty class — Weaviate returns null not [] (fixed in SDK). Update and re-run; or MEMORY_RECALL_ENABLED=false for store-only
Class AgentMemory missing from schema task infra:weaviate:down && task infra:weaviate:up; verify: curl -s http://localhost:8080/v1/schema | jq '.classes[].class'
Compose / API key errors Set EMBEDDING_OPENAI_APIKEY, then task infra:weaviate:down && task infra:weaviate:up
Connection refused :8080 task infra:status, curl -s http://localhost:8080/v1/.well-known/ready, docker logs weaviate
Run 2 does not recall run 1 Same MEMORY_USER_ID; ensure run 1 completed and run-end store succeeded (check LOG_LEVEL=debug or SHOW_TELEMETRY=true)
Port 8080 / 50051 in use task infra:weaviate:down; set WEAVIATE_HTTP_PORT / WEAVIATE_GRPC_PORT before up
LOG_LEVEL=debug go run ./agent_with_memory/weaviate

pgvector

Client-side OpenAI-compatible embeddings, then cosine search in Postgres (pgvector).

Setup
cd examples
task infra:pgvector:up
task infra:pgvector:down   # when finished

Schema: docker/pgvector/setup.sql (table agent_memories). Seed: docker/pgvector/seed.sh.

Default DSN (in .env.defaults): postgres://postgres:secret@localhost:5432/vectordb?sslmode=disable

Verify the memory table exists:

docker exec pgvector psql -U postgres -d vectordb -c "\d agent_memories"
Environment
PGVECTOR_DSN=postgres://postgres:secret@localhost:5432/vectordb?sslmode=disable
PGVECTOR_MEMORY_TABLE=agent_memories
EMBEDDING_OPENAI_MODEL=text-embedding-3-small
EMBEDDING_OPENAI_APIKEY=sk-...
MEMORY_USER_ID=demo-user
MEMORY_RECALL_ENABLED=true
MEMORY_RECALL_LIMIT=10
MEMORY_RECALL_MIN_SCORE=0.35

With Anthropic/Gemini chat, EMBEDDING_OPENAI_APIKEY is still required (not LLM_APIKEY).

Run
go run ./agent_with_memory/pgvector
go run ./agent_with_memory/pgvector "What answer style do I prefer?"
SHOW_TELEMETRY=true go run ./agent_with_memory/pgvector
pgvector troubleshooting
Symptom What to do
relation "agent_memories" does not exist task infra:pgvector:down && task infra:pgvector:up; verify with \d agent_memories above
embedding config / Anthropic chat Set EMBEDDING_OPENAI_APIKEY; re-run task infra:pgvector:up
PGVECTOR_DSN is required Use default DSN or match compose PGVECTOR_* vars
Run 2 does not recall run 1 Same MEMORY_USER_ID; ensure run 1 finished without error and the LLM called save_memory (check LOG_LEVEL=debug or SHOW_TELEMETRY=true)
Dimension / SQL errors Model must match vector(1536) in setup.sql
Port 5432 in use task infra:pgvector:down; set PGVECTOR_PORT and update PGVECTOR_DSN
LOG_LEVEL=debug go run ./agent_with_memory/pgvector

Directories

Path Synopsis
Package common holds shared configuration and agent options for the agent_with_memory examples.
Package common holds shared configuration and agent options for the agent_with_memory examples.
Example agent using PostgreSQL pgvector for long-term memory.
Example agent using PostgreSQL pgvector for long-term memory.
Example agent using Weaviate for long-term memory.
Example agent using Weaviate for long-term memory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL