Documentation Index
Fetch the complete documentation index at: https://docs.simplefunctions.dev/llms.txt
Use this file to discover all available pages before exploring further.
This recipe adds a model layer after a deterministic surface selection. It keeps the agent read-only and limits search breadth.
Install
npm init -y
npm install @spfunctions/sdk@1.0.0 @spfunctions/agent@1.0.0
export SF_API_KEY="sf_..."
export OPENROUTER_API_KEY="..."
Monitor
import { Agent, OpenRouterProvider } from "@spfunctions/agent/v1"
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" },
builtinTools: ["world.read", "markets.search", "market.inspect"],
options: {
maxTurns: 4,
maxBudgetUsd: 0.50,
allowedTools: ["world.read", "markets.search", "market.inspect"],
canUseTool(toolName, input) {
if (toolName === "markets.search" && input && typeof input === "object") {
return { behavior: "allow", updatedInput: { ...input, venue: "kalshi", limit: 5 } }
}
return { behavior: "allow" }
},
},
})
const run = agent.send([
"Read world state.",
"Search Kalshi markets for CPI, Fed, oil, and major legislation.",
"Inspect the most relevant ticker.",
"Return a concise analyst note with catalyst, price, risk, and next read-only action.",
"Do not create intents or trade.",
].join(" "))
const events = []
for await (const event of run.stream()) {
events.push(event)
console.log(event.type)
}
const text = events
.filter(event => event.type === "assistant" && typeof event.message === "string")
.map(event => event.message)
.join("\n")
console.log(text)
import { watch } from "@spfunctions/agent/v1"
for await (const tick of watch.ticks({
tickers: ["KXEXAMPLE"],
cadence: "5min",
cycles: 3,
})) {
console.log(tick.ticker, tick.price, tick.delta)
}
Production notes
- Keep
allowedTools narrow.
- Use
canUseTool to cap limit and force venue: "kalshi".
- Store event streams if a human will audit model behavior later.
- Add execution only in a separate policy-gated step.
Next steps
Agent SDK quickstart
First Agent SDK run.
Agent trader loop
Add deterministic gates and execution policy.