The Playground App is used to serve Agents, Teams and Workflows using a FastAPI server with several endpoints to manage and interact with Agents, Workflows, and Teams on the Agno Playground.

Example Usage

Create an agent, and serve it with Playground:

from agno.agent import Agent
from agno.memory.agent import AgentMemory
from agno.memory.db.postgres import PgMemoryDb
from agno.models.openai import OpenAIChat
from agno.playground import Playground, serve_playground_app
from agno.storage.postgres import PostgresStorage

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-4o"), # Ensure OPENAI_API_KEY is set
    memory=AgentMemory(
        db=PgMemoryDb(
            table_name="agent_memory",
            db_url=db_url,
        ),
        create_user_memories=True,
        update_user_memories_after_run=True,
        create_session_summary=True,
        update_session_summary_after_run=True,
    ),
    storage=PostgresStorage(
        table_name="agent_sessions", db_url=db_url, auto_upgrade_schema=True
    ),
    add_history_to_messages=True,
    num_history_responses=3,
    add_datetime_to_instructions=True,
    markdown=True,
)

app = Playground(
    agents=[
        basic_agent,
    ]
).get_app()

if __name__ == "__main__":
    serve_playground_app("basic_playground_app:app", port=7777, reload=True)

To run:

  1. Ensure your PostgreSQL server is running and accessible via the db_url.
  2. Set the OPENAI_API_KEY environment variable.
  3. The Playground UI will be available at http://localhost:7777. API docs (if enabled in settings) are typically at http://localhost:7777/docs.
  4. Use playground with Agent Playground .

Core Components

  • Playground: Wraps Agno agents, teams, or workflows in an API.
  • serve_playground_app: Serves the Playground FastAPI app using Uvicorn.

The Playground class is the main entry point for creating Agno Playground applications. It allows you to easily expose your agents, teams, and workflows through a web interface with Agent Playground or Agent UI.

Playground Class

Initialization Parameters

ParameterTypeDefaultDescription
agentsOptional[List[Agent]]NoneList of Agno Agent instances.
teamsOptional[List[Team]]NoneList of Agno Team instances.
workflowsOptional[List[Workflow]]NoneList of Agno Workflow instances.
settingsOptional[PlaygroundSettings]NonePlayground configuration. Defaults if None.
api_appOptional[FastAPI]NoneExisting FastAPI app. A new one is created if None.
routerOptional[APIRouter]NoneExisting APIRouter. A new one is created if None.
app_idOptional[str]NoneApp identifier (autogenerated if not set).
nameOptional[str]NoneName for the App.
descriptionOptional[str]NoneDescription for the App.

Provide at least one of agents, teams, or workflows.

Key Methods

MethodParametersReturn TypeDescription
get_appuse_async: bool = True
prefix: str = "/v1"
FastAPIReturns configured FastAPI app (async by default). Sets prefix, error handlers, CORS, docs.
get_routerAPIRouterReturns the synchronous APIRouter for playground endpoints.
get_async_routerAPIRouterReturns the asynchronous APIRouter for playground endpoints.

Endpoints

Endpoints are available at the specified prefix (default /v1) combined with the playground router’s prefix (/playground). For example, the status endpoint is typically /v1/playground/status.

Serving the Application

serve_playground_app serves the Playground’s FastAPI app using Uvicorn.

Parameters

ParameterTypeDefaultDescription
appUnion[str, FastAPI]N/AFastAPI app instance or import string (Required).
hoststr"localhost"Host to bind.
portint7777Port to bind.
reloadboolFalseEnable auto-reload for development.