Setup guides · Python
Custom Loop
For an agent that calls a provider's API itself. You wrap each unit of work, each model call and each tool call once, where your loop already makes them.
Your coding agent can do the attaching. Ask it:
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 Python SDK into your agent's environment from the release's wheel (the same file comes with the program; it isn't on the Python package index) and tell it where nomi is:
pip install "nomi-sdk @ https://github.com/joshbodunrin/nomi/releases/download/v1.0.0/nomi_sdk-1.0.0-py3-none-any.whl"
export MYAGENT_NOMI_ENABLED=1
export MYAGENT_NOMI_ENDPOINT=http://127.0.0.1:4320
export MYAGENT_NOMI_TOKEN_FILE="$HOME/.nomi/write-token" 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.
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.
Attach
-
Create one observer where your process starts, and pass it to the code that needs it:
from nomi import Observer observer = Observer.from_env("my-agent", project="my-repo", agent="my-agent", prefix="MYAGENT_NOMI")projectnames the codebase andagentthe agent in it, so one home can hold several agents without mixing their runs. It always returns a usable observer. When it is switched off or set up wrong, every call does nothing andobserver.setupsays why, so your code needs no checks around it. -
Wrap each unit of work a person would debug (a ticket, a pull request, a conversation turn):
with observer.observe("handle_ticket", workflow="support", group=ticket.id, step="resolve"): ...groupjoins separate runs of the same item into one work item. -
Record each model call with the helper that matches your client:
reply = observer.anthropic(client.messages.create, request) # or observer.responses(...), observer.chat_completions(...)For anything else (a local model’s own client, streaming, async code), record the call yourself:
with observer.model_call("llama-3-8b", provider="ollama", input=prompt, max_output_tokens=800) as call: text, usage = await stream_and_collect(prompt) call.finish(text, usage=usage)finishtakes the reply, the usage (OpenAI, Anthropic or plain counter names, and Ollama’sprompt_eval_countandeval_count; 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. The local models guide has a full example on Ollama. -
Record each tool call. Give a side effect an
action_idand anattempt, so a retry reads as a retry of the same action rather than a new one:with observer.tool("issue_refund", {"order": order_id}, action_id=f"refund:{order_id}", attempt=str(n)) as call: refund = payments.refund(order_id, amount) call.result(refund) call.effect("committed", f"payments:{refund.id}") -
Declare what only your code knows (see below).
Recorded
- Model calls through the helpers: the model, tokens, the output cap your code asked for, and the prompt and reply. With no cap passed, the limit is unknown, not zero.
- The provider:
responses()andchat_completions()sayopenaionly when the client sends to api.openai.com. For any other address the provider is unknown and the step shows where the request went; aprovider=you pass tochat_completions()is kept. - Reasoning text, kept apart from the reply: what you pass to
finish(reasoning=), and areasoningorreasoning_contentfield in a Chat Completions reply. - The provider client’s own retries: a failed call, or one made with
with_raw_response, shows how many attempts the client made. A call that succeeded with a parsed reply says they aren’t reported. - Tool calls: arguments, result, duration, errors, and each attempt of one action.
- Every step’s file, function and line, and the commit that ran, with whether it had uncommitted changes.
- 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 log line.
Declared by your code
- Decisions:
observer.decision("refund_declined", reason)for a result, orkind="issue"for a problem your agent caught itself. Neither marks the run failed. - Effects:
committed,completed,not_appliedorunknownon a tool call. - Expected exceptions:
from_env(..., expected=(RateLimitWait,))ends a run as deferred, not failed. - Waits:
observer.idle("daily_quota", until=resume_at)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. Provider responses aren’t understood automatically; the helpers map the fields they support.
- A stream through
chat_completions(..., stream=True): the app reads it after the step ends, so the call has no reply, tokens or end (“reply not observed”). Record a stream withmodel_call()instead. - Hidden reasoning, and content the provider doesn’t return.
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?”