Skip to main content
Use with or async with on PraisonAIAgents to close agents, memory stores, and connections when a workflow finishes.
The user runs agents inside a context manager; leaving the block closes agents, memory stores, and connections automatically.

Quick Start

1

Simple Usage

2

With Configuration

Async usage with shared memory inside a FastAPI endpoint:

How It Works


Common Patterns

Shared memory cleanup

Long-running worker shutdown

Per-request isolation in servers


Best Practices

with and async with guarantee cleanup even when exceptions occur.
close() logs warnings on failure but does not raise — cleanup failures will not mask the original error.
Create a new PraisonAIAgents instance for each batch or request.
Avoid sharing a global workflow across HTTP requests — isolate resources per call.

Advanced Memory System

Shared memory stores that benefit from automatic cleanup

MongoDB Memory

MongoDB-backed memory with connection lifecycle support