Hot Reload
Edit an agent file while calls are in flight, and OpenRTC re-imports it and swaps every live session to the new class on its next turn. This is somethinglivekit-agents cannot do, because each of its sessions runs in its own OS
process. OpenRTC can, because in coroutine mode the agent class is an object in
shared memory.
Hot reload is coroutine-mode only (
isolation="coroutine", the default). Process
mode runs one subprocess per session and cannot swap a class in place. openrtc start never hot reloads; openrtc dev enables it by default.Enable it
How a reload happens
Detect
A debounced file watcher notices the edited module and hands the change to the reload coordinator.
Validate
The coordinator re-imports the file into a fresh module object and compiles it. Nothing is swapped until the import succeeds and a local
Agent subclass is found.Swap new sessions
The registered
AgentConfig.agent_cls is replaced, so every session that starts from now builds the new class.Rollback safety
The whole point of hot reload is iteration speed, so a bad save must never poison the running pool.| Condition | Behavior |
|---|---|
SyntaxError on save | Keep the running class; log restaurant.py:12: .... No swap. |
ImportError or any import-time exception | Roll sys.modules back to the prior module; log the traceback. No swap. |
Module no longer defines an Agent subclass | Keep the running class; report a failed reload. |
| Agent file deleted | Keep the loaded class live; log a warning. |
ERROR and leaves every live session exactly where it was.
Pinning critical flows
Some flows cannot tolerate a behavior change mid-session (payment confirmation, multi-step authentication). Wrap them so a reload skips that session until the block exits:is_pinned(session) reports the current
state.
Scope
- One agent is reloaded at a time.
- Only agents with a known
source_path(fromdiscover()oradd(..., source_path=...)) are watchable; agents registered with a bare class are not. - Pinning is per session and manual (no pin-by-predicate).
