Last updated

AutoGen Integration

Add persistent memory to AutoGen agent workflows with Papr retrieval before response generation and writeback after each turn.

What You Build

  • Conversation-aware retrieval for each agent turn
  • Persistent memory for decisions and outcomes
  • User-scoped context that survives session restarts

Prerequisites

  • Papr API key in PAPR_MEMORY_API_KEY
  • AutoGen runtime where pre-turn and post-turn hooks are available
  • Stable external_user_id from your app identity model

Integration Pattern

  1. Retrieve relevant memory before the agent replies.
  2. Inject memory context into the prompt or system state.
  3. Store the resulting decision summary after the turn.

Minimal Setup

  1. Add a pre-turn retrieval helper in your AutoGen flow.
  2. Add a post-turn writeback helper for decision summaries.
  3. Run a multi-turn session and verify continuity.

Python Skeleton

import os
from papr_memory import Papr

client = Papr(x_api_key=os.environ.get("PAPR_MEMORY_API_KEY"))


def retrieve_context(prompt: str, external_user_id: str):
    return client.memory.search(
        query=prompt,
        external_user_id=external_user_id,
        enable_agentic_graph=True,
        max_memories=20,
        max_nodes=15,
    )


def store_turn(summary: str, external_user_id: str):
    return client.memory.add(
        content=summary,
        external_user_id=external_user_id,
        metadata={"role": "assistant", "category": "decision"},
        memory_policy={"mode": "auto"},
    )

Validation Checklist

  • Memory retrieval runs before every AutoGen turn
  • Turn summaries become searchable in subsequent turns
  • Retrieval quality improves over repeated workflows

Troubleshooting

If turn memory is missing, verify writeback executes after each turn and check Error Playbook.