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)