> ## 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.

# Agent market monitor

> Build a read-only Agent SDK monitor with strict tools, bounded search, watch inputs, and traceable output.

This recipe adds a model layer after a deterministic surface selection. It keeps the agent read-only and limits search breadth.

## Install

```bash theme={null}
npm init -y
npm install @spfunctions/sdk@1.0.1 @spfunctions/agent@1.0.2
export SF_API_KEY="sf_..."
export OPENROUTER_API_KEY="..."
```

## Monitor

```ts theme={null}
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)
```

## Add semi-realtime input

```ts theme={null}
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

<CardGroup cols={2}>
  <Card title="Agent SDK quickstart" href="/start/agent-sdk-quickstart">
    First Agent SDK run.
  </Card>

  <Card title="Agent trader loop" href="/cookbook/agent-trader-loop">
    Add deterministic gates and execution policy.
  </Card>
</CardGroup>
