AgentOS serve: reload is unsupported

Why AgentOS.serve(reload=True) cannot hot-reload and how to get reload instead

A programmatically built AgentOS cannot hot-reload — serve(reload=True) warns and serves without reload.

Diagram

AgentOS serve(reload=True)

🤖 AgentOS(agents=[…])

⚙️ serve(reload=True)

⚠️ UserWarning

✅ Serves without reload

Quick Start

  1. What happens today

    serve(reload=True) on a programmatic AgentOS emits a UserWarning and runs without reload:

    python
    from praisonai import AgentOS
    from praisonaiagents import Agent
    
    assistant = Agent(name="assistant", instructions="Be helpful.")
    
    AgentOS(agents=[assistant]).serve(reload=True)
    # UserWarning: reload is unsupported for a programmatically built AgentOS;
    # serving without reload.

    The CLI praisonai app --reload prints the same guidance in yellow.

  2. Get reload with a module factory

    Expose your AgentOS as a module-level factory and run uvicorn against the import string:

    python
    # mymodule.py
    from praisonai import AgentOS
    from praisonaiagents import Agent
    
    def create_app():
        return AgentOS(agents=[Agent(name="assistant", instructions="Be helpful.")]).get_app()
    bash
    uvicorn "mymodule:create_app" --factory --reload

Why reload is unsupported

Uvicorn’s reload worker runs in a separate process and re-imports the target module.

Diagram
Reload workerMain processYouReload workerMain processYouNo module-level app — starts emptyAgentOS(agents=[…]).serve(reload=True)Build Agent/Team/Flow in memorySpawn reload worker (fresh process)Re-import target moduleUserWarning + serve without reload

A programmatically built AgentOS(agents=[...]) has no importable module-level app. The reload worker would start empty and fail, so serve(reload=True) warns and serves without reload rather than crash.

PathReload behaviour
AgentOS.serve(reload=True)UserWarning, serves without reload
praisonai app --reloadYellow guidance line, serves without reload
uvicorn "mymodule:create_app" --factory --reloadReload works — uvicorn owns the import

Common Patterns

Development with reload

Point uvicorn at your factory so edits to mymodule.py reload automatically:

bash
uvicorn "mymodule:create_app" --factory --reload --port 8000

Production without reload

For production, call serve() directly — reload is a development-only convenience:

python
from praisonai import AgentOS
from praisonaiagents import Agent

AgentOS(agents=[Agent(name="assistant", instructions="Be helpful.")]).serve(port=8000)

Best Practices

Use a module factory for live reload

Expose create_app() returning AgentOS(...).get_app() and run uvicorn "mymodule:create_app" --factory --reload. Uvicorn controls the import, so each edit re-imports cleanly.

Don't rely on reload in production

Reload re-imports on every change and adds overhead. Serve with AgentOS(...).serve() (no reload) in production.

Prefer CLI serve commands for reloadable files

praisonai serve agents --reload, praisonai serve unified --reload, and praisonai serve recipe --reload all hot-reload because they load from a file via an app factory. See Serve.


Related