Supervisor¶
Monitors child agents and supervisors. Applies restart strategies on failure.
See Supervision for a full guide.
civitas.supervisor.Supervisor(name, children=None, strategy='ONE_FOR_ONE', max_restarts=3, restart_window=60.0, backoff='CONSTANT', backoff_base=1.0, backoff_max=60.0)
¶
Manages child processes with restart strategies.
When a child crashes, the supervisor applies the configured restart strategy. If max_restarts is exceeded within restart_window, the supervisor escalates to its parent or stops permanently.
Source code in civitas/supervisor.py
start()
async
¶
Start all children and begin monitoring them.
Source code in civitas/supervisor.py
stop()
async
¶
Stop all children gracefully.
Source code in civitas/supervisor.py
add_remote_child(name, heartbeat_interval=5.0, heartbeat_timeout=2.0, missed_heartbeats_threshold=3)
¶
Register a remote child for heartbeat-based monitoring.
Remote children are agents running in a Worker process. They are monitored via periodic heartbeat pings instead of task callbacks.
Source code in civitas/supervisor.py
all_agents()
¶
Recursively collect all AgentProcess instances in the tree.
Source code in civitas/supervisor.py
all_supervisors()
¶
Recursively collect all Supervisor instances (including self).
Source code in civitas/supervisor.py
civitas.supervisor.RestartStrategy
¶
Bases: Enum
Strategy used by a Supervisor when a child process crashes.
civitas.supervisor.BackoffPolicy
¶
Bases: Enum
Delay strategy applied between successive restart attempts.
DynamicSupervisor¶
Starts empty. Children are added and removed at runtime via self.spawn() / self.despawn(). Always uses ONE_FOR_ONE. See Dynamic supervision for a full guide.
civitas.supervisor.DynamicSupervisor(name, max_children=None, max_total_spawns=None, restart='transient', max_restarts=3, restart_window=60.0, **kwargs)
¶
Bases: AgentProcess
Dynamic supervisor — starts empty, children added at runtime via spawn().
Declared as a static child in topology YAML under type: dynamic_supervisor.
Only its children change at runtime. Enforces ONE_FOR_ONE restart semantics —
no escalation to parent on restart exhaustion; fires on_child_terminated instead.
Agents call self.spawn() / self.despawn() / self.stop() to manage children. All requests travel as bus messages (civitas.dynamic.*) so the same API works in-process (v0.4) and cross-process (v0.5).
Source code in civitas/supervisor.py
on_spawn_requested(agent_class, name, config)
async
¶
Governance veto hook. Return False to deny the spawn request.
Default implementation approves all requests. Subclass to enforce allowlists, rate limits, or policy checks.
Source code in civitas/supervisor.py
all_dynamic_agents()
¶
on_stop()
async
¶
Cancel all dynamic children on shutdown.
Source code in civitas/supervisor.py
civitas.supervisor.RestartMode
¶
Bases: Enum
Restart policy for dynamic children.