The heart of OmegaClaw. One function, omegaclaw, tail-recurses forever.
(= (omegaclaw) (omegaclaw 1))Outer run.metta simply calls (omegaclaw).
Initializes state:
(initLoop)— configures all loop parameters (see reference-configuration.md).(initMemory)— configures memory parameters and loads the embedding model.(initChannels)— opens the active communication channel.
Also creates shared state slots:
&prevmsg— last received human message.&lastresults— previous turn's skill results, for the next prompt.&loops— countdown until the agent goes idle.
- Decrement
&loops(turns > 1 only). - Build the prompt —
getContextassemblesPROMPT + SKILLS + LAST_SKILL_USE_RESULTS + HISTORY + TIMEplus an output-format instruction requiring a tuple of up to 5 skill s-exprs. - Receive —
(receive)via the active channel. - Detect new input — compare against
&prevmsg. If different and non-empty, reset&loopstomaxNewInputLoops. - Set next wake —
&nextWakeAt := now + wakeupInterval. - Call the LLM — dispatches on
provider:OpenAI→useGPTAnthropic→lib_llm_ext.useClaudeASICloud→lib_llm_ext.useMiniMax- else →
lib_llm_ext.useAsi1
- Repair parentheses —
helper.balance_parenthesesfixes common mismatches before parsing. - Parse —
sreadon the repaired string; if it does not start with(, the loop feeds back a reminder prompt. - Dispatch skills —
(superpose $sexpr)runs each skill, capturing errors viaHandleError. - Record —
addToHistoryappends human message + response + any errors tomemory/history.metta, provided something new happened. - Save last results — into
&lastresultsfor the next turn's prompt. - Sleep —
(sleep (sleepInterval)). - Recurse —
(omegaclaw (+ 1 $k)).
When &loops hits zero and no new message has arrived, the loop skips the LLM call. When now > &nextWakeAt, it grants maxWakeLoops + 1 extra turns so the agent can do self-initiated work (cleanup, summarization, etc.).
Two kinds of error are reported back into &error:
- Parse failure (
MULTI_COMMAND_FAILURE_...) — the LLM did not produce a valid s-expression. - Per-skill failure (
SINGLE_COMMAND_FORMAT_ERROR_...) — one skill call failed.
Errors are appended to the episodic trace so the agent sees them and can self-correct.
- introduction.md#architecture — the architecture diagram.
- reference-internals-skill-dispatch.md — how individual skills resolve.