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.
Returns
Section titled “Returns”object
Object with middleware to install and result to inspect captures
middleware
Section titled “middleware”middleware:
Middleware
result
Section titled “result”result:
CaptureResult
Example
Section titled “Example”const { middleware, result } = capture()const agent = new Agent({ name: "test", model, instructions: "test", defaults: false }) .use(middleware)
await agent.run("Hello").resultconsole.log(result.turns[0].input) // messages sent to modelconsole.log(result.turns[0].response) // model response