Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/agent/README.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / agent / README.md` 312 lines ยท 18960 bytes Raw Blame History Rendered 1 # seed/agent: omagent, a small coding agent in seeded Omega 2 3 omagent is an agent harness in the style of HKUDS/nanobot (MIT), written in seeded Omega. 4 Only nanobot's architecture was reused. None of its code was copied. The program is one 5 static ARM64 Linux executable (191,608 bytes with omc `5f90edea`) built from six sources: 6 7 ```sh 8 { printf 'om2\n'; cat seed/json/json.om seed/json/jsonw.om seed/net/http.om seed/net/notls.om seed/agent/path.om seed/agent/agent.om; } \ 9 | seed/out/omc > omagent && chmod +x omagent 10 ``` 11 12 `seed/agent/path.om` holds the workspace path rule (`agpathok`); the Omega Node tool adapter 13 `seed/node/tool.om` composes the same file, so both refuse the same paths. 14 The only compiler needed is the pinned `seed/out/omc`. Every implementation byte is compiled 15 from `.om`. Python appears only in the test referee `tests/check.py`, which also plays the mock 16 model server. 17 18 Status: IMPLEMENTED and EXERCISED on the host (Linux ARM64, DGX Spark) against a scripted mock 19 server. No real model server was used, and no hardware qualification applies. 20 21 ## Architecture 22 23 ``` 24 operator CLI / stdin line -> agent loop -> model backend (HTTP POST, SSE or JSON) 25 | | 26 v v 27 tool dispatcher stream parser (http.om SSE + json.om) 28 (read_file, write_file, | 29 run_command, http_fetch) v 30 | stdout (content deltas as they arrive) 31 v 32 session file (append-only JSONL), memory file (read-only) 33 ``` 34 35 ### Agent loop 36 37 One user turn runs at most `--max-rounds` model rounds (default 8, at most 64): 38 39 1. Append the user message to the history. 40 2. Send the system prompt, the memory file and the whole history to the model with the 41 four tool schemas. 42 3. Stream the reply. Content deltas go to stdout as they arrive. Tool call deltas are 43 collected by `index`, at most 8 calls per reply. 44 4. With no tool calls, the turn ends. Otherwise, run every call in order, append one `tool` 45 message per call (matched by `tool_call_id`), then go to step 2. 46 5. Hitting the round limit stops with exit 7. Interrupted turns are trimmed from the 47 in-memory history, so a later turn never sends a dangling `tool_calls` message. 48 49 With `-p PROMPT`, omagent runs one turn and exits. Without it, it reads prompts from stdin, 50 one per line, until end of file (the stdin channel). 51 52 ### Model backend 53 54 Any OpenAI-compatible chat completions endpoint reached over plain HTTP at an IPv4 literal 55 or `localhost`. The request is `{"model":..,"stream":true,"tools":[..],"messages":[..]}` 56 with `Content-Length`, `Accept: text/event-stream` and, when a key is present, 57 `Authorization: Bearer KEY`. A `text/event-stream` reply is parsed as SSE until `[DONE]`. 58 Any other content type is read as one JSON document (`choices[0].message`), which covers 59 servers that ignore `stream`. 60 61 `https://` is refused with exit 2: this build carries no TLS client. Wiring `om/tls` in is 62 proposed and NOT_RUN. Point omagent only at a model server you run. The resident server on 63 127.0.0.1:18091 must not be used for tests. 64 65 ### Tool protocol 66 67 The tools are OpenAI function tools whose `arguments` is a JSON object (a JSON string holding 68 an object, or a raw object, both accepted): 69 70 | tool | arguments | permission | result | 71 |---|---|---|---| 72 | `read_file` | `path` | always | file bytes, at most 64 KiB plus a truncation marker | 73 | `write_file` | `path`, `content` | `--allow-write` | `ok: wrote N bytes to PATH` | 74 | `run_command` | `argv` (1..63 strings) | `argv[0]` exactly equal to an `--allow-cmd` entry | output, then `[exit status N]`, `[killed by signal N]` or `[killed: timeout after S s]` | 75 | `http_fetch` | `url` (`http://` only) | canonical `HOST:PORT` on an `--allow-fetch` entry | `status=N` then the body, at most 64 KiB | 76 77 A refused call is answered with a tool message that starts with `refused:` and names the 78 permission, and the loop continues. The model sees the refusal; nothing runs. Result text is 79 repaired to valid UTF-8 before it enters the history. 80 81 ### Memory 82 83 - Session memory: `--session FILE` is an append-only JSONL file (opened `O_APPEND|O_CREAT`, 84 mode 0600). Each line is one message object. At start-up, the last 768 KiB is loaded. Any 85 line that is not a valid message object stops omagent with exit 8 before contacting the 86 model. This includes a final line cut short by a crash; the operator then deletes that line. 87 - History limits: each message is at most 256 KiB. Older messages are dropped from the request, 88 at a user-message boundary, when the history passes 512 KiB or 4096 messages. The session file 89 keeps everything. 90 - Long-term memory: `--memory FILE` (at most 64 KiB, read once) is appended to the system prompt. 91 omagent never writes it. Keep it outside the workspace if the model must not edit it 92 through `write_file`. 93 94 Relative `--session` and `--memory` paths resolve against the directory omagent started in, 95 before it enters `--workdir`. Keep the session file outside the workspace too. 96 97 ### Channels 98 99 Two channels exist now: the CLI one-shot (`-p`) and stdin lines. Both are first-party. These are 100 PROPOSED and not built: an HTTP channel (an OpenAI-compatible `/v1/chat/completions` server using 101 the `seed/net` server half, like `nanobot serve`) and chat adapters (Matrix, IRC, Telegram). 102 Adapters need TLS and are the natural home for omega-bridge or other universal adapters. 103 104 ## Safety model 105 106 1. **The model is untrusted.** Every byte it sends passes `http.om` (status line, headers, 107 chunked or close-delimited body, SSE framing) and `json.om` under fixed caps: 256 KiB per 108 JSON reply or SSE event, 128 KiB reply text, 8 tool calls, and per call 255 bytes of id, 109 127 bytes of name and 64 KiB of arguments. A reply that breaks a cap, is not JSON, carries 110 an `error` object, or ends before `[DONE]` or a `finish_reason` stops omagent with exit 6. 111 Nothing from that reply runs. 112 2. **Tool permissions are explicit.** By default, only `read_file` inside the workspace is 113 allowed. Writing, programs and fetches each need their own flag. Programs are named by 114 absolute path, and there is no shell and no PATH search. 115 3. **The workspace is a jail by path rules.** 116 - Paths must be relative. 117 - No part may be empty, `.` or `..`. No control byte is allowed. 118 - Every prefix is checked with `lstat` and must not be a symbolic link. 119 - The final open uses `O_NOFOLLOW`. 120 - Limit: the checks and the open are separate system calls, so a concurrent local process 121 that swaps a directory for a link between them could escape (TOCTOU). Proposed fix: 122 `openat2` with `RESOLVE_BENEATH` as a host word. The effect-manifest work in `seed/effects` 123 is the proposed outer sandbox layer. 124 4. **Commands are bounded.** 125 - Children run with an empty environment and stdin on `/dev/null`. 126 - stdout and stderr go to one close-on-exec pipe, and at most 64 KiB is kept. 127 - Each command runs as the leader of its own process group (`setpgid` on both sides of the 128 fork, as in `seed/node/auth.om`). 129 - When the direct child exits, omagent reaps it and SIGKILLs the rest of its group, so a 130 background grandchild cannot outlive the call or hold the pipe open; the output read then 131 ends at end of file. The call returns within about 50 ms of the child's exit. 132 - At the `--cmd-timeout` deadline (default 10 s), the whole group gets SIGKILL and the child 133 is reaped. 134 5. **No secrets in logs.** 135 - The API key is read from `OMAGENT_API_KEY` (or `--key-env NAME`), never from argv. It must 136 be bytes 0x21..0x7e. 137 - The key appears only in the Authorization header. The header buffer is zeroed after the 138 write. 139 - stderr carries only fixed messages and `omagent: tool NAME: ok|refused|error`. 140 - Tool arguments and results are never echoed to stderr. 141 - The session file stores messages, not headers. 142 - The tests assert that the key never appears in stdout, stderr or the session file, and 143 that the mock server did receive it. 144 6. **Timeouts.** `--timeout` (default 120 s) bounds each model request, both idle time and the 145 whole body. Connecting has a 5 s limit. 146 147 ## CLI 148 149 ``` 150 omagent --url http://IP:PORT/PATH --model NAME [-p PROMPT] [--workdir DIR] 151 [--session FILE] [--memory FILE] [--allow-cmd /ABS/PATH]... [--allow-write] 152 [--allow-fetch HOST:PORT]... [--timeout S] [--cmd-timeout S] [--max-rounds N] 153 [--key-env NAME] | --version | --help 154 ``` 155 156 Exit codes: 157 158 | code | meaning | 159 |---|---| 160 | 0 | ok | 161 | 2 | usage, configuration, `--workdir` or a bad key | 162 | 3 | connect or send failed | 163 | 4 | HTTP status other than 200 (stderr shows the status and the first 512 sanitized body bytes) | 164 | 5 | model timeout or read failure | 165 | 6 | malformed model output | 166 | 7 | `--max-rounds` reached | 167 | 8 | session or memory file | 168 | 9 | a message could not be encoded, or the history is full | 169 170 ## Tests 171 172 ```sh 173 nice -n 19 ionice -c3 python3 seed/agent/tests/check.py 174 ``` 175 176 The test builds omagent with `seed/out/omc` and starts a scripted mock model server on a 177 kernel-chosen 127.0.0.1 port. It then runs 32 conversations: 178 179 - plain SSE and JSON replies 180 - every tool, plus two calls in one reply 181 - refusals: a program not on the allowlist, programs disabled, `..`, an absolute path, a 182 symbolic link, writing disabled, an unknown tool, a fetch host not on the allowlist, https 183 - malformed output: a bad event, a truncated stream, an error object, a bad call index, 184 HTTP 500 185 - a model timeout, a command timeout and the round limit 186 - a command whose background grandchild must die when it exits (the call returns in under 187 5 s with a 10 s `--cmd-timeout`), and a timed-out command whose child and grandchild must 188 both die; both scan `/proc` for survivors 189 - a command that closes its output, sleeps 0.3 s and exits 3 must report `[exit status 3]`: 190 end of file is not exit (`/bin/echo` closes stdout before it exits), so the group's SIGKILL 191 must not overtake a child that is still finishing 192 - session reload, a corrupt session line, no key, two stdin lines, connection refused 193 194 Negative controls follow. Two wrong expectations must fail. Nine source mutants must each be 195 caught: allowlist bypass, `..` allowed, symlink followed, fetch allowlist bypass, write flag 196 ignored, end of stream without `[DONE]` accepted, SIGKILL to the direct child only (not its 197 group) after it exits or at the deadline, and end of file taken as the child's exit. Output: 198 `AGENT-CHECK PASS cases=35 mutants=9`. 199 Exit 0 means PASS, 1 FAIL, and 3 NOT_RUN (no compiler). 200 201 ## Host dependencies 202 203 | dependency | version | purpose | Omega replacement | 204 |---|---|---|---| 205 | `seed/out/omc` | pin sha256 `2c824805`... (omega-mv main) | compiler | itself (seeded) | 206 | Linux ARM64 kernel | host | system calls through compiled host words | none (platform) | 207 | Python 3 | 3.12 on the Spark | test referee and mock server only, not on the product path | a `.om` mock server on `seed/net` (proposed) | 208 | nanobot-ai | 0.3.5 on Python 3.12.3, in a separate venv | comparison arm of `bench/` only | none needed (not a dependency of omagent) | 209 210 ## Compared with nanobot 211 212 ### Feature matrix 213 214 nanobot-ai 0.3.5 (paths relative to its installed `nanobot/` package) against omagent (`agent.om` 215 lines at this commit). Status: HAS (equivalent), PARTIAL (narrower), MISSING (absent). 216 217 | feature | nanobot evidence | omagent | omagent evidence | 218 |---|---|---|---| 219 | model/tool loop with an iteration cap | `agent/runner.py`, `maxToolIterations` `config/schema.py:129` | HAS | `agturn` :2237, `--max-rounds` :82, :161 | 220 | streamed replies (SSE) | `providers/openai_compat_provider.py:2124` | HAS | `agsse` :1498; non-stream JSON too, `agjsonbody` :1527 | 221 | read and write a file | `read_file`/`write_file` `agent/tools/filesystem.py:281,546` | HAS (no offset/limit/pages on read) | `agtread` :1762, `agtwrite` :1804 | 222 | edit_file, list_dir, find_files, grep, apply_patch | `filesystem.py:869,1111`, `search.py:215,514`, `apply_patch.py:84` | MISSING | | 223 | shell command | `exec` `agent/tools/shell.py:248` (through a shell) | PARTIAL: argv exec of allowlisted programs, no shell | `agtrun` :1965, `agallowed` :1849 | 224 | persistent exec sessions | `exec_session`, `list_exec_sessions` `exec_session.py:565,722` | MISSING | | 225 | web fetch | `web_fetch` `agent/tools/web.py:1114` (https, redirects, extraction) | PARTIAL: plain `http://` to allowlisted HOST:PORT, raw body | `agtfetch` :2039 | 226 | web search | `web_search` `web.py:367` | MISSING | | 227 | workspace confinement | `restrictToWorkspace` `schema.py:401` (default off) | HAS (always on: no `..`, absolute paths or symlinks) | `agpathok` :1735 | 228 | command deny-list / timeouts | built-in deny-list `shell.py` ~213-232, timeout `:97` | PARTIAL: allowlist instead of deny-list; timeout and child exit kill the whole process group | `agexec` :1957, `--cmd-timeout` :81 | 229 | MCP client (stdio, SSE, streamable HTTP) | `agent/tools/mcp.py:1365,1412`, `schema.py:362` | MISSING | | 230 | session history | `session/manager.py`, sessions dir | HAS (one JSONL file per `--session`) | `agsload` :1032, `agappend` :917 | 231 | history compaction / consolidation | Consolidator and AutoCompact `agent/loop.py:433,443`, summaries `agent/memory.py:803-824` | PARTIAL: drops the oldest whole turns, no summaries | `agcompact` :896 | 232 | long-term memory and Dream | `memory/MEMORY.md`, `DreamConfig` `schema.py:53` (gateway only) | PARTIAL: read-only `--memory` file, nothing written back | `agmemload` :755 | 233 | system prompt from workspace templates and skills | `cli/agent.py:154`, `skills/` (11 built-in) | MISSING (fixed system prompt plus memory file) | `agsysmsg` :1093 | 234 | skills | `skills/`, `disabledSkills` `schema.py:146` | MISSING | | 235 | providers, presets, fallback models | about 46 providers `schema.py:240`, `fallbackModels` `:128` | PARTIAL: one OpenAI-compatible endpoint, plain HTTP only, Bearer key | `agurl` :420, `agkeyload` :720 | 236 | subagents | `spawn` `agent/tools/spawn.py:63`, `agent/subagent.py:100` | MISSING | | 237 | messages and session tools, goals | `message.py:117`, `session_messages.py:81,153`, `sessions.py:88,165`, `long_task.py:159,290` | MISSING | | 238 | chat channels | 17 channels in `channels/` (Telegram, Slack, Discord, ...) | MISSING (CLI only: `-p` or stdin lines) | `agline` :2289 | 239 | WebUI, gateway, OpenAI-compatible API server | `webui/`, `GatewayConfig` `schema.py:353`, `ApiConfig` `:333` | MISSING | | 240 | cron and heartbeat | `cron` tool `agent/tools/cron.py:118`, heartbeat `schema.py:326` | MISSING | | 241 | image generation, CLI apps, `my` | `image_generation.py:121`, `cli_apps.py:99`, `self.py:149` | MISSING | | 242 | transcription | `TranscriptionConfig` `schema.py:42` | MISSING | | 243 | API key kept out of logs and child environments | | HAS (checked by every test case) | `tests/check.py` | 244 245 omagent lacks MCP, subagents, skills, web search, the editing and search tools, exec sessions, 246 summarizing memory, multiple providers, TLS, chat channels, the WebUI and API server, cron and 247 heartbeat, image generation and transcription. What it has is the four-tool coding loop above. 248 249 ### Equal-work benchmark 250 251 `bench/equal_bench.py` runs both programs through the same session: 252 - the same prompt and the same scripted mock, `bench/equal_mock.py`; 253 - streamed replies, four model requests per session: `read_file`, then `write_file`, then one 254 echo through the shell tool, then the final answer; 255 - the same advertised tools: nanobot is reduced to `read_file`, `write_file`, `exec` and 256 `web_fetch` by `bench/nb_minimal.py`, because its config cannot drop the rest. It also has no 257 MCP, no channels, every built-in skill disabled, `restrictToWorkspace`, and a fresh session each 258 run; 259 - the mock checks every tool result, and the driver checks the written file and the final answer. 260 261 Remaining differences: 262 - nanobot's system prompt is larger: 43,230 request bytes per session against 7,480 (5.78x). 263 - nanobot's command runs as `env echo gamma-789` through `sh`, because its workspace guard 264 refuses `/bin/echo`. omagent runs `/bin/echo` directly. 265 266 A negative control (omagent without `--allow-write`) is graded BAD. 267 268 MEASURED on 2026-10-26 with omc `2c824805` (binary sha256 `3eb8e93e`..., 188,268 bytes): 269 - N=30 paired runs per core class and model delay, arm order alternating; 270 - client pinned with `taskset` to X925 cpu 5 or A725 cpu 1; 271 - all 240 runs graded ok; 272 - warm page cache; the Spark was heavily loaded by other work (load average 28 to 45 during the 273 runs, recorded per group), so absolute times are noisy, while the paired order keeps the 274 comparison fair. 275 276 A first run misnamed one skill, so nanobot's `update-setup` skill stayed enabled. That skill 277 added 1,468 request bytes per session (3.3% of nanobot's 44,698). The numbers below are from the 278 rerun with every built-in skill disabled. They are a little different from the first run, partly 279 because the machine was busier. 280 281 Wall times include the same Python launcher and `/usr/bin/time` for both arms. Medians, with ratios 282 from Wolfram: 283 284 | measure | omagent | nanobot | nanobot/omagent | 285 |---|---|---|---| 286 | launch to first model request, X925 / A725 | 5.5 / 9.0 ms | 831 / 2228 ms | 167x / 255x | 287 | full session, instant mock, X925 / A725 | 14.2 / 23.1 ms | 1206 / 2917 ms | 92x / 126x | 288 | full session, mock at 50 ms per chunk, X925 / A725 | 1838 / 1850 ms | 3758 / 5020 ms | 2.02x / 2.73x | 289 | peak RSS | 2,584 KiB | 142,838 to 143,046 KiB | 55.3x | 290 291 On-disk footprint: 292 - omagent is the 188,268-byte static binary and nothing else. 293 - During the session, nanobot loaded 1,894 module files totaling 51,602,687 bytes: 3.06 MB of its 294 own package, 41.65 MB of third-party packages and 6.90 MB of the standard library. On top of that 295 comes the 7,845,048-byte interpreter, which makes 316x. 296 - nanobot's full installation is 336,116,353 bytes of site-packages, plus the standard library and 297 the interpreter. 298 299 Once the model is slow, the harness matters much less. With the mock spending about 1.8 s per 300 session, omagent's advantage falls from 92x to 2.02x (X925) and from 126x to 2.73x (A725). The 301 absolute gap stays at 1.2 to 3.2 s per session, mostly nanobot's 0.8 to 2.4 s startup, and 302 amounts to 50% (X925) and 63% (A725) of nanobot's session time. Against a real model that takes 303 seconds per reply, the share is smaller again. NOT_RUN: a real model server. 304 305 Raw rows, machine state, the Wolfram input and output, and the footprint lists are filed in the 306 operator handoff `OmegaBot/eqbench2/` (the first, flawed run is in `OmegaBot/eqbench/`). 307 308 ## Limits and NOT_RUN 309 310 - TLS model endpoints and fetches: NOT_RUN (refused by design in this build). 311 - Real model servers (vLLM, llama.cpp, MAX): NOT_RUN. Only the scripted mock was used. 312 - One request at a time; no parallel tool calls; the TOCTOU limit above.