Skip to content

capture

capture(): object

Creates a message capture middleware that records model inputs and outputs.

The middleware installs a model hook that snapshots ctx.messages before each LLM call and records the response after. All captures are accumulated in result.turns.

object

Object with middleware to install and result to inspect captures

middleware: Middleware

result: CaptureResult

const { middleware, result } = capture()
const agent = new Agent({ name: "test", model, instructions: "test", defaults: false })
.use(middleware)
await agent.run("Hello").result
console.log(result.turns[0].input) // messages sent to model
console.log(result.turns[0].response) // model response