Main brain and state machine#
The main brain: a supervisor that keeps a state machine over the robot’s sub-agents and may consult a local language model.
Structure#
Sub-agents (
MotorSubAgent,SensorSubAgent,PerceptionSubAgent,Heartbeat) each watch one sub-system and report aStatuswith a health level (OK,WARN,FAULT,HEALING,FAILED). The motor sub-agent wrapsMotorAgent, which does its own local self-healing.State machine (
StateMachine): the robot is in oneMode(BOOT,CALIBRATING,NOMINAL,DEGRADED,HOLD,SAFE_STOP). Only the transitions inTRANSITIONSexist; anything else is refused and logged.Brain (
RuleBrainorLocalLLMBrain): when a sub-system reports something other than OK, the brain picks one action from the set allowed in the current mode. A local LLM can be the brain, but it only proposes: its reply must be JSON with an allowed action, and hard rules run first and cannot be overridden (anyFAILEDsub-agent meansSAFE_STOP;SAFE_STOPis left only by a humanreset). An unparsable or disallowed reply falls back to the rule brain and is counted.Supervisor (
Supervisor): runs the sub-agents every step, fires state-machine events, asks the brain, applies the action to the command, and keeps an incident log.
The LLM is optional and runs locally (ollama_generate() talks to an Ollama server on this machine; any str -> str
callable works). No language model ships with the library and none was run during development: the LLM path is tested with
scripted replies only.
Classes
Health level a sub-agent reports, from fine ( |
|
Operating mode of the robot, the states of the supervisor's state machine. |
|
Reports the motor agent's view: healing a fault, failed (safe stop) or fine. |
|
Encoder, MEMS and quantum accelerometer health. |
|
Grounding confidence: WARN while the instruction is ambiguous (the gate would ask). |
|
Watchdog: FAILED if no telemetry arrived within |
|
Deterministic policy; also the fallback when the LLM misbehaves. |
|
Ask a local language model to choose the action. |
|
The main brain's loop: sub-agent statuses -> state-machine events -> brain decision -> command limits. |
Functions
A |
|
Two-leg move under the main brain. |
- class Health(*values)[source]#
Bases:
EnumHealth level a sub-agent reports, from fine (
OK) to out of service (FAILED).
- class Mode(*values)[source]#
Bases:
EnumOperating mode of the robot, the states of the supervisor’s state machine.
- class Status(name: 'str', health: 'Health', message: 'str' = '', data: 'dict' = <factory>)[source]#
Bases:
object
- class MotorSubAgent[source]#
Bases:
objectReports the motor agent’s view: healing a fault, failed (safe stop) or fine.
- class SensorSubAgent(quantum_timeout=3.0, bias_limit=0.15)[source]#
Bases:
objectEncoder, MEMS and quantum accelerometer health.
- class PerceptionSubAgent[source]#
Bases:
objectGrounding confidence: WARN while the instruction is ambiguous (the gate would ask).
- class Heartbeat(timeout=0.5)[source]#
Bases:
objectWatchdog: FAILED if no telemetry arrived within
timeoutseconds.
- class RuleBrain[source]#
Bases:
objectDeterministic policy; also the fallback when the LLM misbehaves.
- class LocalLLMBrain(generate, fallback=None)[source]#
Bases:
objectAsk a local language model to choose the action.
generate(prompt) -> stris any local text generator.The prompt carries the mode, every status and the allowed actions; the reply must contain
{"action": ..., "reason": ...}. A reply that is not JSON, or names an action that is not allowed in this mode, is discarded and the rule brain decides (counted instats).
- class Supervisor(subagents=None, brain=None, calibrate_steps=20, recover_steps=40, dt=0.05, slow_factor=0.5)[source]#
Bases:
objectThe main brain’s loop: sub-agent statuses -> state-machine events -> brain decision -> command limits.
- ollama_generate(model='llama3.2', host='http://localhost:11434', timeout=30.0)[source]#
A
generatefunction for a local Ollama server (needs Ollama running on this machine; not exercised in the test suite).
- run_supervised_episode(act, rng, faults=(), brain=None, steps=100, switch_at=30, tol=0.0625, heal=True, dropped_telemetry_at=None)[source]#
Two-leg move under the main brain. Returns the final error, the mode trace and the supervisor.
dropped_telemetry_at(seconds) stops telemetry from arriving from then on, which the heartbeat must catch.