PatternsSDK API

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

    Install from the preview toolbar

    Shadcn Icon

    Copy the install command above and run it in your project — Pro patterns include a short-lived token.

  2. 2

    Add environment variables to .env.local

    OPENAI_API_KEY

  3. 3

    Point client fetches at your API routes

    Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.

  5. 5

    Run your dev server and open the pattern route

    Install dependencies if needed, then start the app 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