Agent basics tier · Reference card · Agents Academy

Agent basics.
One sheet.

Tool-use contract, the canonical agent loop, three memory layers, persistence patterns, and the safety perimeter every trading agent assumes from day one. Pin it; print it; come back to it.

01

Tool contract

M04

Every tool the model can invoke needs three fields:

{ name: "browse_markets", description: "List active Limitless markets matching a tag and a min volume.", input_schema: { type: "object", properties: { tag: { type: "string" }, minVol: { type: "number" } }, required: ["tag"] } }

The description is the most important field. It’s how you teach the model when this tool is the right answer.

02

The agent loop

M05
while True: r = llm.invoke(messages, tools) if r.kind == "assistant": return r # done out = run_tool(r.tool_call) messages.extend([r, out]) if step++ > CAP: # guard return TimedOut

Termination. Plain assistant message, step cap, or kill-switch flag from the dashboard.

03

Three memory layers

M06
Short-termcontext window
SessionNDJSON trace
Long-termSQLite / JSON

Don’t cross streams. Long-term state goes through tool calls, not prompt-stuffing. Session traces don’t replace state; state doesn’t replace traces.

04

Atomic write

M06
// Always: temp + rename fs.writeFile(path + ".tmp", j); fs.rename(path + ".tmp", path); // Concurrent? add a lock. flock(path, EX, () => { // write here });

Atomic rename survives crashes. Add flock when more than one process can write.

05

Trace event shape

M06
{ runId, step, timestamp, kind, // see below payload // pre-redacted }

Kinds: prompt, assistant, tool_call, tool_result, error. One line per event. Filename: YYYY-MM-DD.ndjson.

06

Do I need a vector store?

M06
  • Open positions, P&L, risk budgets.SQLite.
  • Last 30 days of fills.NDJSON + tail.
  • Daily P&L summary.CSV.
  • Thousands of human research notes. → vector store.
  • “Find similar past markets to this new one.” → vector store.
  • Anything else. → you don’t need it yet.
07

Safety perimeter

M03

Three boundaries every trading agent assumes from day one:

BoundaryMechanismIf breached
Key custodyWallet sign as a separate process / hardwareCompromised agent ≠ drained wallet
Risk capsMax position size + daily loss enforced in place_limit_order tool, not the promptHallucinated “just one more” can’t exceed cap
Kill switchFlag file ($ACADEMY_DATA_DIR/kill_switch.flag) checked at top of every loop iterationYou stop the agent in 1 cycle, panel tap or one command

Mental model. The LLM is a tenant in a sandbox you built. The walls are tools. The roof is risk caps. The door is the kill switch. None of those should depend on the model behaving well.

08

Pitfalls that bite production agents

Cross-module
  1. Stuffing state into the prompt. Context is short-term, not long-term. Use tool calls.
  2. Atomic write, two writers. Atomic rename + flock when more than one process can hold the file.
  3. Trace logs leak secrets. Pre-redact env vars, headers, anything >200 chars in tool_call.input. Rotate any key that appears.
  4. No step-count cap on the loop. An LLM that loops forever costs money and emits one bad order per iteration.
  5. Tools without idempotency. Retried tool calls must produce the same effect, place_limit_order needs a client nonce.
  6. Reading positions immediately after a fill. Indexers lag. Trust the order ack; reconcile on a separate cadence.