Skip to content

The agent

This section explains how one desk thinks. Everything here applies to each of the four desks separately.

A desk does nothing until something wakes it: your message, a scheduled check, a heartbeat, a price alert, a fill, a webhook, or the daily rollover. Each of these becomes a trigger in the desk's queue, and the desk takes them one at a time. One trigger is one turn.

A turn

In a turn the desk is given its instructions and the trigger, and its model either answers or asks for tools. The tools run, their results go back to the model, and the loop repeats until the model answers without asking for a tool, or until 20 rounds have passed.

The agent loop A trigger starts a turn; the model is asked, its tool calls run through the tool registry and the loop guard, and the loop repeats until the model answers without a tool. one desk inside the gateway Trigger "What time is it?" Agent loop ask the model run the tools it asks for give it the results repeat until it answers at most 20 rounds a turn Loop guard refuses the same call with the same arguments after 3 times Event bus every step, live: tool_call · text_delta Gemma 4 31b on Ollama, on the RTX 4090 num_ctx 32768 reply streams in pieces Tool registry checks the arguments first get_time 60 s limit · errors become results output capped at 20,000 characters 1 question + tool list 2 "call get_time" 3 "Friday 23:02 IST" 4 the answer going to the model coming from the model One turn, two rounds: the model asks for a tool, reads the result, then answers.
The agent loop for Qwen and Gemma. The orange dots are the model's tool calls going through the tool registry; the blue dots are results going back to the model. The loop guard stops a call that repeats with the same arguments.

Claude works the same way, but the loop runs inside Claude Code, which trading-agent drives through the Claude Agent SDK. trading-agent's tools are served to it in the same process, Claude Code's own tools are switched off, and a hook refuses any tool that is not one of trading-agent's.

The Claude Code backend A trigger goes to the Claude turn runner, which drives Claude Code; Claude calls trading-agent tools through an in-process tool server and every step is published on the event bus. this computer: the gateway process and its Claude Code process Trigger "What time is it?" Claude turn runner one session per desk, resumed after a crash refuses to start while ANTHROPIC_API_KEY is set Claude Code the SDK's bundled copy bypassPermissions no settings files read all built-in tools off In-process tool server allow-list hook, then the same executor Gemma uses: loop guard · checks · 60 s · cap get_time Event bus streamed text, and rate_limit · model_usage Claude Opus 5.5 at Anthropic, on your Max subscription apiKeySource: none 5-hour and weekly limits 1 question + tool list 2 "call get_time" 3 "Friday 23:19 IST" 4 the answer going to Claude coming from Claude Claude Code runs the loop; every tool call still comes back into the gateway and passes through the same protections.
The Claude backend. Claude Code runs the loop, calls trading-agent's tools through an in-process tool server, and every step is published on the event bus like a local model's.

The pages in this section

Page What it covers
Models The backends, the model router and its fallback, and Claude through the Max subscription
Tools All 49 tools, the bash sandbox, the browser and web search
Memory Sessions, the daily rollover, notes, Memory.md, checkpoints and context compression
Skills Procedures the desks load when a task matches, and the ones they write themselves
Subagents Helpers a desk hands tasks to, in parallel
Scheduling and watching Cron jobs, heartbeats, scheduled checks, the market watcher, price alerts and webhooks
Extensions MCP servers, untrusted text, the knowledge base, hooks, packages and apps