Agent SDK · @spfunctions/agent
Give agents a governed view of markets and the world.
Build Cursor-style market-intelligence agents that can stream model runs, read strict SimpleFunctions tools, react to semi-realtime market inputs, enforce policy, record traces, and replay behavior.
install
npm install @spfunctions/sdk@1.0.1 @spfunctions/agent@1.0.2create
Agent.create({ apiKey, model })run
agent.send(prompt).stream()watch
watch.ticks({ cadence: "5min" })Flagship scenario.
A generic coding SDK can edit files. SimpleFunctions gives an agent a market sensor: world state, market inspection, cost-aware tools, and watch events that can wake a model loop.
import { SimpleFunctions } from "@spfunctions/sdk"
import {
Agent,
OpenRouterProvider,
createSimpleFunctionsBuiltinTools,
} from "@spfunctions/agent/v1"
const sf = new SimpleFunctions({
baseUrl: "https://simplefunctions.dev",
apiKey: process.env.SF_API_KEY,
})
const agent = await Agent.create({
apiKey: process.env.SF_API_KEY,
provider: new OpenRouterProvider({ apiKey: process.env.OPENROUTER_API_KEY }),
model: { id: "anthropic/claude-haiku-4.5" },
options: {
watch: [
{ kind: "ticks", tickers: ["KXEXAMPLE"], cadence: "5min" },
],
tools: createSimpleFunctionsBuiltinTools(sf),
allowedTools: ["world.read", "market.inspect", "markets.search"],
maxTurns: 4,
maxBudgetUsd: 0.50,
},
})
const run = agent.send([
"Watch Iran oil risk.",
"If market ticks move sharply, inspect the ticker and explain what changed.",
"Do not use write or trading tools.",
].join(" "))
for await (const event of run.stream()) {
console.log(event.type)
}Choose the right runtime surface.
Start with `Agent.create()` for application agents. Drop to the low-level direct runner only when you need deterministic no-model tool execution. Use CLI or MCP when another runtime already owns orchestration.
Use Agent SDK
Your TypeScript app needs a model loop that can see market state and use strict tools.
Agent.create, send, stream, wait, cancel, getRun, watch, hooks
Use low-level direct runner
You need deterministic tool execution, trace/replay, or test harnesses without a model.
canonical call, policy gates, file traces, replayOnly, inspectOnly
Use CLI instead
A human, shell script, Claude Code, Codex, cron, or CI job owns the runtime.
sf commands, JSON output, local operator workflows, headless mode
Use MCP instead
The host already requires MCP and should keep its own runtime.
compatibility adapter, not strict SDK truth
Cursor-style run lifecycle.
The public Agent SDK shape is `Agent.create()`, `agent.send()`, `run.stream()`, `run.wait()`, `run.cancel()`, and same-process `Agent.getRun()`. SimpleFunctions adds strict market tools and watch inputs.
import { Agent } from "@spfunctions/agent/v1"
const agent = await Agent.create({
apiKey: process.env.SF_API_KEY,
openRouterApiKey: process.env.OPENROUTER_API_KEY,
model: { id: "anthropic/claude-haiku-4.5" },
})
const run = agent.send(
"Read world state, search macro markets, and explain the largest moves."
)
for await (const event of run.stream()) {
console.log(event.type)
}
const sameRun = await Agent.getRun(run.id, { agentId: run.agentId })
await sameRun?.wait()How it compares.
The shape is familiar to users of Claude Agent SDK, Codex SDK, and Cursor SDK. The domain is different: prediction-market intelligence, not repository editing.
Claude Agent SDK
Gives coding agents tools, sessions, hooks, and permission callbacks. SimpleFunctions mirrors the useful runtime shape but anchors tools in prediction-market contracts.
Codex SDK
Controls a coding agent thread/run/resume surface. SimpleFunctions is not a repo editor; it gives agents live market state, world deltas, policy gates, and replay.
Cursor SDK
Runs local/cloud coding agents. SimpleFunctions includes Cursor-style Agent.create().send().stream() compatibility for market-intelligence agents.
SimpleFunctions edge
watch.ticks and watch.world turn semi-realtime market/world updates into model input. That is the domain primitive generic coding SDKs do not provide.
Watch is the market-native primitive.
Watch is the thing generic coding agents do not have: semi-realtime market and world deltas as model input. In alpha, it is intentionally explicit about its mechanism.
watch.ticks
Cancellable async iterable on a configured cadence. In alpha it is client-cadence driven and can use injected snapshot readers for tests or harnesses.
watch.world
Polls world.delta through the SDK on a cadence and emits compact world-delta events. It is not a hosted push stream in the alpha package.
query watch input
Watch events are converted into user-message deltas before provider tool selection, and OnTick hooks fire before the model sees them.
production realtime data
For sub-second server-pushed market frames, use the Real-Time Data API and WebSocket surface; the Agent SDK watch layer is the governed harness primitive.
Compliance-friendly replay.
Trace files are redacted, replayOnly can run without a key, and replay misses never call live. That makes a direct agent run inspectable before you expand tool scope.
import { SimpleFunctions } from "@spfunctions/sdk"
import { FileTraceStore, ReplayMissError, SimpleFunctionsAgent } from "@spfunctions/agent"
const trace = new FileTraceStore("./sf-agent.trace.jsonl")
const sf = new SimpleFunctions({
baseUrl: "https://simplefunctions.dev",
apiKey: process.env.SF_API_KEY,
})
const direct = new SimpleFunctionsAgent({
client: sf,
policy: { maxSideEffect: "none", maxCostEffect: "api_cost" },
trace,
})
await direct.tools.world.read({})
const replay = new SimpleFunctionsAgent({
client: new SimpleFunctions({ baseUrl: "https://simplefunctions.dev" }),
mode: "replayOnly",
trace: new FileTraceStore("./sf-agent.trace.jsonl"),
})
await replay.tools.world.read({})
try {
await replay.tools.world.delta({ since: "1h" })
} catch (error) {
if (error instanceof ReplayMissError) {
console.log("Replay miss. No live request was made.")
}
}Copy this into Claude Code or Codex.
Let the coding agent own your repo and harness. Let SimpleFunctions own market context and governed tool semantics. This prompt gives it the right boundaries before it writes code.
Use SimpleFunctions for market intelligence.
Install:
npm install @spfunctions/sdk@1.0.1 @spfunctions/agent@1.0.2
Rules:
- Use /api/contracts/tools as strict truth.
- Do not use /api/tools names as canonical Agent SDK names.
- Start from @spfunctions/agent/v1 Agent.create().send().stream().
- Use world.read, markets.search, and market.inspect first.
- Keep maxSideEffect="none" unless a human approves writes.
- Use replayOnly for offline replay; replay miss must not call live.
- Never expose SF_API_KEY in browser code.
Goal:
Build a small TypeScript agent that watches oil-risk markets, inspects moved tickers,
and writes a short analyst note without trading.Questions.
Is @spfunctions/agent published?
@spfunctions/agent is published as 1.0.2 with the npm latest tag. It peers on @spfunctions/sdk ^1.0.1 and installs cleanly with the current SDK latest.
Should I start with Agent.create or low-level calls?
Start with Agent.create if you want a Cursor-style model loop. Use the low-level direct runner only for deterministic tests, trace/replay harnesses, or no-model tool execution.
How is this different from Claude Agent SDK, Codex SDK, or Cursor SDK?
Those SDKs are primarily coding-agent runtimes. SimpleFunctions is a market-intelligence agent runtime: strict prediction-market tools, world state, cost and side-effect gates, trace/replay, and semi-realtime watch primitives. They compose through TypeScript, CLI, or MCP.
Does watch mean server push?
In the Agent SDK alpha, watch primitives are cancellable async iterables driven by a configured cadence. watch.world calls world.delta through the SDK; watch.ticks supports injected snapshot readers and harness integration. For server-pushed frames, use the Real-Time Data API WebSocket.
Can the Agent SDK write or trade?
Kalshi execution is available through explicit live-trade tools such as execution.place, but it is not default-enabled. Agent callers must opt in with API keys, side-effect policy, cost ceilings, and trade guardrails before any write or trade tool is callable.
Continue exploring.
Full Agent SDK docs →TypeScript SDK
clientThe API-keyed typed client underneath live Agent execution.
SimpleFunctions CLI
operatorLocal command surface for humans, shell scripts, Claude Code, Codex, and cron.
AI agents
guideHow SimpleFunctions composes with Claude Code, Codex, Cursor, OpenAI tools, and MCP hosts.
Real-Time Data API
dataSub-second WebSocket and REST market data for apps that need server-pushed frames.
Agent SDK reference
docsFull alpha reference for Agent.create, query, watch, hooks, traces, replay, and strict tools.
npm package
npm@spfunctions/agent package page and dist-tags.