TemplatesTools & Utilities

Tool Input Lifecycle Hooks

Loading pattern preview

Problems solved

Technical challenges this implementation handles out of the box.
  • Observe tool input generation with onInputStart
  • Stream partial tool arguments via onInputDelta
  • React when full tool input becomes available with onInputAvailable

Use cases

Products and workflows this pattern is designed to support.
  • Debugging streaming tool argument construction
  • UI spinners tied to tool input lifecycle events
  • Teaching AI SDK tool input hooks
  • Monitoring long tool-argument generation

Setup

Requirements, wiring steps, and what this pattern adds to your project.

Getting started

Pick how you want to pull this pattern in. Then wire env vars and routes the same way.

  1. 1

    Download → Next.js app

    Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).

  2. 2

    Extract the zip and install dependencies

    Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.

  3. 3

    Fill .env.local

    The download includes .env.local placeholders when needed. Add real values for: OPENAI_API_KEY.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions in the generated project for your product.

  5. 5

    Run the app and open the pattern route

    Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route and verify responses.

Environment variables

Capabilities

AI SDK APIs

streamTextconvertToModelMessagestooluseChatonInputStartonInputDeltaonInputAvailable

Providers

OpenAI

Files added

6 files
  • app/page.tsx
  • app/layout.tsx
  • app/api/tool-input-lifecycle/route.ts
  • components/input-lifecycle-demo.tsx
  • tools/weather.ts
  • tools/weather-ui.tsx

Dependencies

14 total

npm packages

7
AISDKshadcn/uilucide-reactNext.jsReactstreamdownZod

Shadcn IconRegistry components

7
alertemptyinput-groupseparatormessage-scrollermessagebubble

Critical files

  • tools/weather.ts

    Weather tool demonstrating all three tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. Core pattern for monitoring tool input generation.

Requirements

Complexity
Beginner
Setup time
~5 minutes
Node
24+
Memory
512MB