Skip to content

[FEATURE] Support long-term memory for agentsΒ #1256

@supreme-gg-gg

Description

@supreme-gg-gg

πŸ“‹ Prerequisites

πŸ“ Feature Summary

Add support for long-term memory

❓ Problem Statement / Motivation

Why do we need long term memory?

Sessions can track history (events) and temporary data for a single ongoing conversation. But in order for agents to recall information from past conversations (from the same or different session), we need a memory service to support "long-term knowledge", similar to a searchable archive or knowledge library that the agent can consult, potentially containing information from many past chats or other sources.

πŸ’‘ Proposed Solution

System Overview

  • Agent (Python ADK): Uses KagentMemoryService to send/retrieve memories via HTTP and generate embeddings, configured from the CRDs
  • Controller (Go): Exposes /api/memory endpoints to manage vector storage
  • Storage (Postgres): Stores embeddings and metadata in the agent_memory table.

Components

  1. HTTP server endpoints (Go)
  • POST /api/memory/sessions: Accepts (text, vector) pairs. Stores in agent_memory.
  • POST /api/memory/search: Accepts (query_vector). Performs cosine similarity search in pgvector
  1. Kagent ADK (Python)

KagentMemoryService will BaseMemoryService with two methods:

  • add_session_to_memory: Uses LiteLLM to generate embeddings using the configured embedding model, send vectors to Kagent API
  • search_memory: Embed query and send query_vector to Kagent API

This will be created and passed to the Runner if memory is enabled on the agent. The agent will use tools to either optionally or preload memory. After each agent execution, a callback will save the session to memory using the memory service. These are documented further in the ADK memory interface: https://google.github.io/adk-docs/sessions/memory/

  1. Embedding Model Config
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
spec:
  embedding:
    provider: OpenAI # or AzureOpenAI, Vertex, Ollama
    model: "text-embedding-3-small"
  1. Agent Configuration
spec:
  declarative:
    memory:
      enabled: true
      modelConfig: "embedding-model-config"
  1. Data Model

The user can configure whether to extend the database to use vector-extensions in Helm Chart:

// helm/kagent/values.yaml
database:
  postgres:
    vector:
      enabled: true # Default: true

We will use pgvector for Postgres (production) and sqlite-vector (https://github.com/sqliteai/sqlite-vector) for sqlite (development).

Table: agent_memory

id: UUID
agent_name: String (Tenant)
user_id: String (Tenant)
content: Text (Chunk)
embedding: Vector (Size varies by model)
metadata: JSONB (Source session ID, timestamp)

πŸ”„ Alternatives Considered

  • Use the Qdrant MCP server or similar options: https://google.github.io/adk-docs/tools/third-party/qdrant/ However this requires using a cloud-hosted solution for the vector DB. Note that if you wish to use an external Vector database (like qdrant, chroma, pinecone), you can still use the MCP approach and disable the internal pgvector memory service.

  • Use pinecone or qdrant in cluster: this was a popular approach perhaps a year ago, but right now the best practice is to keep relational data and vector data in the same database as extensions like pgvector mature and reach similar performance as dedicated vector databases. This not only provides tighter integration and less overhead, but also better metadata query performance.

🎯 Affected Service(s)

Multiple services / System-wide

πŸ“š Additional Context

The feature will first be rolled out in ADK. Then, support to BYO agents will be added via the kagent packages to LangGraph, CrewAI, OpenAI SDK.

πŸ™‹ Are you willing to contribute?

  • I am willing to submit a PR for this feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions