Warm Runtime (Daemon)
Keep provider clients and MCP connections warm across praisonai run calls
from praisonaiagents import Agent
agent = Agent(name="daemon-agent", instructions="Run as a background daemon process.")
agent.start("Start the agent daemon and listen for incoming tasks.")praisonai daemon keeps provider clients and MCP connections hot in memory so repeated praisonai run calls skip cold-start entirely.
The user runs repeated praisonai run commands; the warm daemon forwards work to hot provider and MCP connections.
graph LR
subgraph "Without Daemon (Cold Start Every Time)"
A1[praisonai run] --> B1[Init Provider]
B1 --> C1[Init MCP]
C1 --> D1[Agent.start]
D1 --> E1[Result]
end
subgraph "With Daemon (Warm Path)"
A2[praisonai run] --> B2{Lockfile?}
B2 -->|Yes| C2[Forward via HTTP]
C2 --> D2[Warm Agent]
D2 --> E2[Result]
B2 -->|No / Stale| F2[In-Process Fallback]
F2 --> E2
end
classDef cold fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef warm fill:#10B981,stroke:#7C90A0,color:#fff
classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
classDef runtime fill:#189AB4,stroke:#7C90A0,color:#fff
classDef config fill:#6366F1,stroke:#7C90A0,color:#fff
class A1,B1,C1 cold
class D1,A2 agent
class B2,C2 runtime
class D2 warm
class F2 cold
class E1,E2 warm
classDef tool fill:#189AB4,color:#fff
classDef agent fill:#8B0000,color:#fffQuick Start
- Start the daemon in the background
bash praisonai daemon start --background✓ Warm runtime started in background at http://127.0.0.1:54321 (pid 12345)The daemon writes a project-local lockfile and binds to a free loopback port. All subsequent
praisonai runcalls in the same project directory automatically detect and attach to it.Edited commands, agents, skills, tools, and rules files (including
AGENTS.md/CLAUDE.md) are picked up on the next prompt. The daemon drops its warm agents and rebuilds them, and session history is rehydrated from the project session store. See Live edits during interactive sessions. - Run prompts — no extra flags needed
bash praisonai run "Write a haiku about clouds" praisonai run "Now make it rhyme" praisonai run "Translate to Spanish"Each call transparently attaches to the warm runtime. Provider and MCP clients are already initialised — only the prompt is forwarded.
- Check status and stop
bash praisonai daemon status✓ Warm runtime running at http://127.0.0.1:54321 (pid 12345).bash praisonai daemon stop✓ Stopped warm runtime (pid 12345).
How It Works
sequenceDiagram
participant User
participant run as praisonai run
participant lock as Lockfile
participant daemon as WarmRuntime (HTTP)
participant agent as Warm Agent
User->>run: praisonai run "prompt"
run->>lock: Read runtime.json
lock-->>run: {host, port, token, pid}
run->>run: pid alive?
run->>daemon: POST /healthz (Bearer token)
daemon-->>run: {ok: true}
run->>daemon: POST /run {prompt, session_id?, event_id?}
alt session_id present
daemon->>daemon: _get_session_agent(session_id, model)<br/>rehydrate once, retain history
else anonymous
daemon->>daemon: _get_agent(model)<br/>per-model stateless, cleared post-call
end
daemon->>agent: agent.start(prompt)
agent-->>daemon: result
daemon-->>run: {ok: true, result}
run-->>User: prints result
Note over run,lock: If lockfile missing, stale pid, or<br/>runtime unreachable → in-process fallback| Component | Role |
|---|---|
Lockfile (runtime.json) | Stores {host, port, token, pid} at <project_data_dir>/runtime/runtime.json. Mode 0600 — token is never world-readable. |
| WarmRuntime | Holds two agent caches: (1) one stateless warm Agent per model for anonymous (no-session) calls — history cleared after each call; (2) one stateful warm Agent per session id for --continue/--session runs — history rehydrated once and retained across turns, persisted per-turn through the project session store. Both caches evict on turn failure to prevent state bleed. |
| RuntimeClient | Thin stdlib (urllib) HTTP client. Raises RuntimeUnavailable on any error — run then falls back in-process. |
| Idle watcher | Background thread shuts down the server after --idle-timeout seconds of inactivity (default 30 min). |
Configuration Options
praisonai daemon start
| Flag | Type | Default | Description |
|---|---|---|---|
--host, -h | str | 127.0.0.1 | Loopback host to bind. Non-loopback addresses are rejected. |
--port, -p | int | 0 | Port to bind. 0 = auto-select a free port. |
--model, -m | str | None | Default model for the warm agent. |
--idle-timeout | float | 1800.0 | Seconds idle before auto-shutdown. 0 disables auto-shutdown. |
--background, -b | bool | False | Detach and run in the background. |
praisonai daemon status
| Flag | Type | Default | Description |
|---|---|---|---|
--json | bool | False | Output JSON for scripting. Returns {running, host, port, pid, base_url}. |
praisonai daemon status --json{
"running": true,
"host": "127.0.0.1",
"port": 54321,
"pid": 12345,
"base_url": "http://127.0.0.1:54321"
}praisonai daemon stop
No flags. Sends SIGTERM after a health-check ping to guard against PID reuse. Cleans up the lockfile.
When to Use Foreground vs Background
graph TB
Q{How will you use the daemon?}
Q -->|Everyday workflow| BG[--background]
Q -->|Debugging / watching logs| FG[Foreground default]
BG --> B1[Starts detached process]
BG --> B2[Returns immediately]
BG --> B3[Persists across terminal sessions]
FG --> F1[Logs visible in terminal]
FG --> F2[Ctrl-C to stop]
FG --> F3[Blocks the shell]
classDef warm fill:#10B981,stroke:#7C90A0,color:#fff
classDef cold fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef config fill:#6366F1,stroke:#7C90A0,color:#fff
class Q config
class BG,B1,B2,B3 warm
class FG,F1,F2,F3 coldWhen --continue / --session Attach Warm
When run Stays In-Process
praisonai run skips the daemon and runs locally whenever you pass any of these flags:
| Flag(s) | Why it stays in-process |
|---|---|
--mcp, --tools, --toolset | Per-invocation tool overrides need in-process state. |
--approval, --approve-all-tools | Approval flow requires interactive in-process handling. |
--memory | Memory store is managed in-process. |
--permissions overrides | Security policy must be enforced locally. |
--fork | The forked session id is minted in-process; subsequent turns against the forked id attach warm. |
--thinking, --worktree | Reasoning-effort and isolated git-worktree runs need in-process state. |
--output actions, json, stream, stream-json | Structured output modes need richer in-process event bridging. |
In all these cases, praisonai run behaves exactly as it did before the daemon feature. No flags are needed to opt out — it happens automatically.
Common Patterns
Iterating on prompts in a shell loop
praisonai daemon start --background
for topic in clouds mountains rivers; do
praisonai run "Write a haiku about $topic"
done
praisonai daemon stopOnly the first call pays setup cost. The loop body is fast — just HTTP over loopback.
Auto-shutdown at night with –idle-timeout
# Shut down after 1 hour of inactivity (3600 seconds)
praisonai daemon start --background --idle-timeout 3600
# Or disable auto-shutdown entirely (not recommended for long sessions)
praisonai daemon start --background --idle-timeout 0The default is 1800 seconds (30 minutes). The daemon shuts itself down silently when the idle timer expires.
Scripting status checks
STATUS=$(praisonai daemon status --json)
RUNNING=$(echo "$STATUS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['running'])")
if [ "$RUNNING" = "True" ]; then
echo "Daemon is up"
else
praisonai daemon start --background
fiThe --json flag returns {running, host, port, pid, base_url} — safe for jq or any JSON parser.
Using a specific model
praisonai daemon start --background --model gpt-4o
# All runs that don't specify --model will use gpt-4o from the warm agent
praisonai run "summarize this document"Security
Project rules and local tools
As of PR #4943, the warm runtime honors AGENTS.md / CLAUDE.md subtree instructions and loads project-local .praisonai/tools/*.py on every run — so the daemon now behaves identically to the cold path for these two implicit, project-scoped sources.
Previously the warm runtime built a bare agent with no subtree instruction hook and no local tools, so a daemon-forwarded praisonai run returned fluent text and exited 0 while touching nothing — indistinguishable from success until you checked the filesystem.
# Cold path (already worked)
praisonai run "list the todos" # honored ./AGENTS.md and ./.praisonai/tools/
# Warm path (now equally honored, from PR #4943)
praisonai daemon start
praisonai run "list the todos" # same rules, same tools, same resultWhen run Falls Back to In-Process
praisonai run does not forward to the daemon when you use these flags. They are handled in-process instead:
| Flag | Reason |
|---|---|
--session, --continue, --fork | Session continuity requires stateful context |
--memory | Memory backend must be initialized per-session |
--approval | Approval backends need a live terminal or channel |
--tools, --toolset | Per-invocation tool overrides change agent config |
--attach | Live session tagging for multi-terminal observation |
--output json, --stream | Structured output modes attach directly to the process |
--trace, --profile | Tracing and profiling require direct process access |
When any of these flags is set, run behaves exactly as if no daemon were running — fully backward compatible.
CLI Reference
praisonai daemon start
Start the warm runtime server.
praisonai daemon start
praisonai daemon start --background
praisonai daemon start --host 127.0.0.1 --port 8899 --model gpt-4o-mini --idle-timeout 3600| Option | Type | Default | Description |
|---|---|---|---|
--host, -h | str | 127.0.0.1 | Loopback address to bind. Non-loopback addresses are rejected. |
--port, -p | int | 0 (auto) | Port to bind. 0 picks a free port automatically. |
--model, -m | str | None | Default model for warm agents. Inherits your configured default when unset. |
--idle-timeout | float | 1800.0 | Seconds of inactivity before the daemon auto-shuts-down. 0 disables. |
--background, -b | bool | False | Detach from the terminal and run in the background. |
praisonai daemon status
praisonai daemon status
praisonai daemon status --json| Option | Type | Default | Description |
|---|---|---|---|
--json | bool | False | Machine-readable JSON output. |
praisonai daemon stop
praisonai daemon stopSends SIGTERM to the daemon process. If the lockfile is stale (PID reuse), cleans up the lockfile instead of killing a random process.
Version compatibility
The warm runtime records its package version in the lockfile. Thin clients (praisonai run, praisonai attach) require a matching major version before reusing the runtime — a stale daemon after upgrade is ignored and the CLI falls back to in-process execution (or attach exits with code 1).
After upgrading PraisonAI:
praisonai daemon stop
praisonai daemon start --backgroundSee Attach for streaming live session events from a second terminal.
Best Practices
Use –background for everyday workflows
Foreground mode is useful for debugging (you can see log output). For all other use cases, --background is simpler: it returns immediately and the daemon persists across terminal sessions.
Tune –idle-timeout carefully
The default 30-minute timeout is a good balance between warmth and resource usage. Setting --idle-timeout 0 means the daemon never shuts down automatically — only use this if you understand it will consume memory indefinitely.
One daemon per project
The lockfile is stored under the project data directory, scoped to the current project. Running two daemons in the same project will print a warning and exit. Each project directory gets its own independent daemon.
Check status before starting
praisonai daemon status
# → No warm runtime is running.
praisonai daemon start --backgroundStarting a daemon when one is already running prints a warning and exits cleanly — there is no risk of running two daemons accidentally.