retrieve_session() returns the same shape on every managed agent backend so you can write code once and switch providers freely.
Quick Start
Schema
All four fields are always present with sensible defaults:| Field | Type | Default | Values |
|---|---|---|---|
id | str | "" | Session ID, empty if none |
status | str | "unknown" | idle, running, error, unknown, none |
title | str | "" | Session title (Anthropic only sets this) |
usage | Dict[str, int] | {"input_tokens": 0, "output_tokens": 0} | Always has both keys |
Status Values
| Status | Meaning |
|---|---|
idle | Session exists and ready for input |
running | Session actively processing (Anthropic) |
error | Session hit an error (Anthropic) |
unknown | No session / status unavailable |
none | Local backend with no session ID |
Empty Session Defaults
Before starting any turn you still get a valid dict — noKeyError, no .get() guards:
Building a Custom Backend
Import the protocol directly frompraisonaiagents.managed:
Common Patterns
Cost monitoring
Provider-agnostic logging
Best Practices
Don't guard with .get()
Don't guard with .get()
Every key is always present.
info["usage"]["input_tokens"] is always safe.Check status before sending
Check status before sending
Use
status == "idle" before sending a new message to avoid overlapping turns.Handle backend differences
Handle backend differences
LocalManagedAgent always returns title="". Only AnthropicManagedAgent sets it.Use stable import path
Use stable import path
from praisonaiagents.managed import ManagedBackendProtocol is the stable, recommended path.Related
Overview of managed agent backends
Run managed agents locally

