nomi

Setup guides · TypeScript

Custom Loop

For an agent that calls a provider's API itself, with the Anthropic or OpenAI JavaScript client or any other. You wrap each unit of work, each model call and each tool call once, where your loop already makes them.

Versions
TypeScript SDK (runnomi-sdk) 1.0.0, installed from the release's packed file; Node 22 or later, run on Node 22.13.0 only; any model provider
Route
The TypeScript SDK at the places your loop calls models and tools

Your coding agent can do the attaching. Ask it:

Use the attach-nomi skill and add nomi to this agent.

It finds the places to hook in and asks you the few things only you know. The steps below are what it does.

Start nomi

nomi is one program, nomi. Download it from the releases page, then:

nomi init
nomi configure -mode sdk -source my-agent -receiver-listen 127.0.0.1:4320
nomi start                                   # leave this running
nomi browser -home "$HOME/.nomi"  # opens the run view

Everything it records lives in ~/.nomi; -home on any command chooses another folder. nomi doctor says whether it's healthy.

Install the TypeScript SDK (runnomi-sdk 1.0.0) into your agent from the release's packed file. It isn't on npm, so keep the whole address. Then tell it where nomi is:

cd /path/to/your/agent
npm install https://github.com/joshbodunrin/nomi/releases/download/v1.0.0/runnomi-sdk-1.0.0.tgz
export MYAGENT_NOMI_ENABLED=1
export MYAGENT_NOMI_ENDPOINT=http://127.0.0.1:4320
export MYAGENT_NOMI_TOKEN_FILE="$HOME/.nomi/write-token"

npm records that address in package.json and the lockfile, so another machine or CI installs the same file. This was checked with npm 10.9.2 from a packed file on disk, from ES module and CommonJS applications; pnpm, yarn and bun weren't.

The SDK has no runtime dependencies and works from ES modules and CommonJS. The settings are read by Observer.fromEnv with prefix: "MYAGENT_NOMI"; the SDK reads the token file itself, so the token is never on a command line. Events are held in memory and sent in the background: what can't be delivered is counted and reported as lost. To keep events on disk through an outage or a restart, set MYAGENT_NOMI_SPOOL_DIR and MYAGENT_NOMI_SOURCE.

These are the same-machine settings. Your agent can also run in a container or on another machine of yours and send to the same nomi: where nomi runs has what changes, and the attach skill can set it up.

nomi never changes how your agent runs: if it’s off, down or hanging, your agent carries on with the same output.

What you need

  • The SDK needs Node 22 or later. Its tests ran on Node 22.13.0 only.
  • The helpers were tested with @anthropic-ai/sdk 1.12.0 and with openai 6.49.0 and 7.62.0.
  • Every test ran against a local stand-in for the provider. Nothing was run against a real provider API.

How it fits

Your loop owns the model calls, the tool dispatch and the retries, and it keeps them. Nothing records automatically here: you mark the places your loop already has, once each, rather than every role or business tool. The provider client isn’t wrapped or patched, and the request it sends is the same with and without nomi.

JavaScript has no with, so every scope is a function that takes the body as its last argument, runs it once and returns what it returns: a value for a synchronous body, a promise for an async one. The body’s errors are rethrown unchanged.

Attach

  1. Create one observer where your process starts, and pass it to the code that needs it:

    import { Observer } from "runnomi-sdk";
    
    const observer = Observer.fromEnv("my-agent", { project: "my-repo", agent: "my-agent", prefix: "MYAGENT_NOMI" });
    

    project names the codebase and agent the agent in it, so one home can hold several agents without mixing their runs. It never throws and always returns a usable observer. When it is switched off or set up wrong, every call does nothing and observer.setup and observer.notes say why, so your code needs no checks around it.

  2. Wrap each unit of work a person would debug (a ticket, a pull request, a conversation turn):

    const answer = await observer.observe("handle_ticket", { workflow: "support", group: ticket.id, step: "resolve" }, async () => {
      // ...
    });
    

    group joins separate runs of the same item into one work item. Pass the body’s AbortSignal as signal and an abort ends the scope as cancelled, not failed.

  3. Record each model call with the helper that matches your client. The first argument is a function that takes the arguments, because a JavaScript method passed alone loses its client:

    const reply = await observer.anthropic((args) => client.messages.create(args), request);
    // or, with the openai client:
    await observer.chatCompletions((args) => openai.chat.completions.create(args), request, { client: openai });
    await observer.responses((args) => openai.responses.create(args), request, { client: openai });
    

    For anything else (a local model’s own client, a stream), record the call yourself:

    const text = await observer.modelCall("llama-3-8b", { provider: "ollama", input: prompt, maxOutputTokens: 800 }, async (call) => {
      const { text, usage } = await streamAndCollect(prompt);
      call.finish({ output: text, usage });
      return text;
    });
    

    The arguments can be a variable typed with the client’s own parameter interface (Anthropic.MessageCreateParamsNonStreaming, OpenAI.Chat.ChatCompletionCreateParamsNonStreaming), and the client’s return type comes back. Arguments written in place that hold a message literal need their type said once, as { ... } satisfies Anthropic.MessageCreateParamsNonStreaming: TypeScript otherwise reads role: "user" as a string and the client’s create rejects it.

    finish takes the reply, the usage (OpenAI, Anthropic, Ollama or plain counter names; a name it doesn’t read is named on the step, never dropped silently) and, when the model returns it, reasoning for its thinking text.

  4. Record each tool call. Give a side effect an actionId and an attempt, so a retry reads as a retry of the same action rather than a new one:

    const refund = await observer.tool("issue_refund", { arguments: { order: orderId }, actionId: `refund:${orderId}`, attempt: String(n) }, async (call) => {
      const done = await payments.refund(orderId, amount);
      call.result(done);
      call.effect("committed", `payments:${done.id}`);
      return done;
    });
    
  5. Declare what only your code knows (see below), and before the process ends:

    await observer.close();
    

    An observer made by fromEnv also closes, with a one-second limit, when the event loop empties, so a script that simply ends still delivers. process.exit(), an uncaught exception and a signal skip that.

Recorded

  • Model calls through the helpers: the requested and returned model, tokens, the stop reason, the output cap your code asked for, the response ID, and the prompt and reply. With no cap passed, the limit is unknown, not zero.
  • The provider: with { client } passed, responses() and chatCompletions() say openai only when the client sends to api.openai.com. For any other address the provider is unknown and the step shows where the request went. { provider: "name" } names it yourself. With neither, it isn’t recorded.
  • Reasoning text, kept apart from the reply: what you pass to finish({ reasoning }), and a reasoning or reasoning_content field in a Chat Completions reply.
  • Tool calls: arguments, result, duration, errors, and each attempt of one action.
  • Errors: the error’s class name and, where the error carries one, its HTTP status. An abort (AbortError, the provider clients’ APIUserAbortError) is recorded as cancelled, not as an error; a TimeoutError is an error.
  • Every scope’s file, function and line, and the commit that ran, with whether it had uncommitted changes. For compiled or bundled TypeScript the position is resolved through the file’s source map (tested with tsc, an esbuild bundle and tsx). When a named source map can’t be read, the scope has no location and says why.
  • Each scope’s start, sent at once: a process killed mid-run leaves a run shown as not finished, never as succeeded.
  • Events lost while nomi was down, counted and shown on the run once the SDK reaches nomi again in the same process; otherwise only in your agent’s stderr line.

Declared by your code

  • Decisions: observer.decision("refund_declined", reason) for a result, or { kind: "issue" } as the third argument for a problem your agent caught itself. Neither marks the run failed.
  • Effects: committed, completed, not_applied or unknown on a tool call.
  • Expected exceptions: fromEnv(..., { expected: [RateLimitWait] }) ends a run as deferred, not failed.
  • Waits: observer.idle("daily_quota", resumeAt) when your agent waits on purpose, so waiting and hung look different.

What it can’t see

  • Anything your loop doesn’t pass through a helper.
  • A stream (stream: true) or an unread response (.asResponse()) through the three helpers: the step says its reply was not observed. Record a stream with modelCall() and finish().
  • The provider client’s own retries: always shown as not reported.
  • A tool function’s own position: a tool step’s location is where observer.tool was called.
  • Hidden reasoning, and content the provider doesn’t return.
  • Values that aren’t plain JSON data (class instances, Date, Map, functions): the field is marked omitted, never stringified.

When nomi is down

Your agent’s output, exit code and requests to the provider are the same with nomi up, down, never answering, answering 500 or refusing the token. What isn’t delivered is counted and said once on stderr. With durable delivery on (NOMI_SPOOL_DIR), the SDK keeps its events on disk and sends them when nomi is back.

In every guide: nothing below a tool’s boundary, such as HTTP retries in your own client, is seen unless your code declares its attempts. Retries inside a provider’s client library show as one longer model call; the step gives the client’s attempts where the route reports them, and otherwise says they aren’t reported. A model nomi has no price for, such as a local one, has its cost shown as unpriced, never as $0. A run that was still open when nomi stopped says its end was not received: its outcome is unknown, not interrupted.

Connect your coding agent

nomi includes a server with read-only tools for your coding agent, and a debug skill that teaches it to keep what was observed, what your code declared and what is unknown apart. Pick yours:

Claude Code

claude mcp add nomi -s user -- nomi mcp
mkdir -p ~/.claude/skills && cp -R skills/debug-agent-with-nomi ~/.claude/skills/

Codex

codex mcp add nomi -- nomi mcp
mkdir -p ~/.codex/skills && cp -R skills/debug-agent-with-nomi ~/.codex/skills/

Cursor, in ~/.cursor/mcp.json (or .cursor/mcp.json for one project)

{"mcpServers": {"nomi": {"type": "stdio", "command": "nomi", "args": ["mcp"]}}}

Cursor's debug skill (the skill needs Cursor 2.4 or later)

mkdir -p ~/.cursor/skills && cp -R skills/debug-agent-with-nomi ~/.cursor/skills/

Cursor also reads skills from ~/.claude/skills/, so if the skills are already installed for Claude Code, nothing needs copying.

Then open a session in your agent's repository and ask, for example:

  • “What went wrong in my agent's last few runs?”
  • “Why did this run fail?”
  • “What changed between these two runs?”