recipe-embedded-app-agent

Embed streaming AI agents into Next.js API routes via SSE.

21|4|Updated Feb 19, 2026
One-click install
npx skills add https://github.com/tylerjrbuell/reactive-agents-ts --skill recipe-embedded-app-agent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: recipe-embedded-app-agent
Source: https://github.com/tylerjrbuell/reactive-agents-ts/tree/main/apps/docs/skills/recipe-embedded-app-agent
Command: npx skills add https://github.com/tylerjrbuell/reactive-agents-ts --skill recipe-embedded-app-agent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This recipe shows how to embed a fully streaming AI agent into a Next.js application, enabling real-time responses, progressive disclosure of reasoning and tool usage, and robust server-side error and cost handling for interactive web clients.

Core Features & Use Cases

  • Server-side streaming API route that builds an agent per-request and emits Server-Sent Events for live client updates.
  • Client-side React hook that consumes the SSE stream, exposes text deltas, tool call events, run/cancel controls, and graceful cancellation.
  • Progressive UI patterns to display reasoning steps and tool traces, plus production considerations like per-session budgeting, agent disposal, and required Node runtime configuration.
  • Use cases include interactive chat widgets with tool integrations, live diagnostics that show tool-call progress, and background one-shot processing when streaming is unnecessary.

Quick Start

Build a Next.js POST API route that constructs an agent, streams AgentStream.toSSE from agent.runStream, and consume it in a client component with useAgentStream to display incremental text and tool events.

Frequently Asked Questions about recipe-embedded-app-agent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream AI agent responses in Next.js using Server-Sent Events?

You stream AI agent responses in Next.js by building a POST API route that constructs an agent per-request and emits Server-Sent Events (SSE) for live client updates. This enables progressive disclosure of reasoning and tool usage to interactive web clients.

Can I display live tool call traces and reasoning steps in a React chat interface?

Yes, you can display live tool call traces in a React chat interface by consuming the SSE stream with a dedicated client-side hook. This hook exposes text deltas and tool call events to render progressive UI patterns for real-time agent reasoning.

How do I handle streaming agent errors and per-session cost budgets in a Next.js app?

Handle streaming agent errors and per-session cost budgets by applying production-grade server-side error handling and per-session budgeting. The API route enforces cost limits and manages agent disposal after each request completes or fails.

Does this streaming agent approach work with Vue or Svelte frontends, or is it React only?

The streaming agent approach works with Vue or Svelte frontends, not just React. The server-side API route streams SSE to any frontend, while the dedicated React hook provides ready-to-use client-side consumption for React applications specifically.

What's the best way to run background one-shot agent processing without streaming?

For background one-shot processing without streaming, use the same server-side agent construction without emitting SSE events. This handles tasks where streaming is unnecessary, while still maintaining per-request agent construction and disposal best practices.

Why do I need to configure the Node.js runtime for streaming API routes in Next.js?

You must configure the Node.js runtime for streaming API routes in Next.js to satisfy requirements for server-side streaming. This runtime configuration ensures proper SSE emission, per-request agent construction, and production-grade budget handling during live responses.