Last updated

Quickstart: Add Memory to Existing Agent

Add durable memory to an existing agent loop in a few steps.

What You Will Build

  • Retrieve relevant memory before model generation
  • Write key outcomes back to memory after response
  • Reuse memory in later turns and sessions

Prerequisites

  • PAPR_MEMORY_API_KEY configured in your environment
  • A stable external_user_id from your application identity

Minimal Setup

  1. Add one retrieval call before generation.
  2. Add one writeback call after generation.
  3. Validate with a second retrieval query.

1) Retrieve Context Before Generation

curl -X POST "https://memory.papr.ai/v1/memory/search?max_memories=20&max_nodes=15&response_format=toon" \
  -H "X-API-Key: $PAPR_MEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Client-Type: curl" \
  -d '{
    "query": "What relevant context should I use for this request?",
    "external_user_id": "user_123",
    "enable_agentic_graph": true
  }'

2) Generate Your Agent Response

Use the retrieved context in your LLM prompt and run your existing inference step.

3) Store the New Learning

curl -X POST https://memory.papr.ai/v1/memory \
  -H "X-API-Key: $PAPR_MEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Client-Type: curl" \
  -d '{
    "content": "User confirmed they want weekly updates and concise summaries.",
    "external_user_id": "user_123",
    "metadata": {
      "role": "assistant",
      "category": "preference"
    },
    "memory_policy": {
      "mode": "auto"
    }
  }'

4) Validate in One Query

curl -X POST https://memory.papr.ai/v1/memory/search \
  -H "X-API-Key: $PAPR_MEMORY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Client-Type: curl" \
  -d '{
    "query": "What summary and update preferences does this user have?",
    "external_user_id": "user_123",
    "enable_agentic_graph": true
  }'

Validation Checklist

  • Retrieval returns context before generation.
  • Writeback persists a new memory item.
  • Validation query returns the new learning.

Troubleshooting

If validation returns no results, confirm you are using the same external_user_id on both write and search, then check Error Playbook.

Next Steps