Skip to main content

Setup

Set OPENAI_API_KEY in your environment. STOPHY_API_KEY is optional for this example.

The Stophy tool

This function calls Google search and returns the results as JSON, limited to 5 so the model’s context stays small. It reads your key from STOPHY_API_KEY, and works without one.
stophy.ts

Use it as a tool

Wrap the search in tool(). stopWhen lets the model search, read the results, and answer, in up to five steps.