- Inngest Client (
/api/inngest/client.ts
): Initializes Inngest with therealtimeMiddleware
. - Realtime Channel (
/api/inngest/realtime.ts
): Defines a typed realtime channel and topic. - Chat Route:
/api/chat/route.ts
: This is a standard Next.js API route. Its only job is to receive a request from the frontend and send an event to Inngest to trigger a function. - Token Route:
/api/realtime/token/route.ts
: This secure endpoint generates a subscription token that the frontend needs to connect to Inngest realtime. - Inngest Route:
/api/inngest/route.ts
: The standard handler that serves all your Inngest functions.
Set up Inngest for streaming
1
Inngest Client - /api/inngest/client.ts
This file configures the Inngest client and enables the realtime middleware, which is essential for streaming.
2
Realtime Channel - /api/inngest/realtime.ts
Here, we define a strongly-typed channel for our agent’s communications. The
agent_stream
topic is where all message chunks will be published fromAgentKit.3
Chat API Route - /api/chat/route.ts
This endpoint is the bridge between your frontend and the Inngest backend. It receives the user’s message and dispatches an event to trigger the agent network.
4
Token API Route
/api/realtime/token/route.ts
This secure endpoint generates a subscription token that the frontend needs to connect to Inngest realtime.5
Inngest Route - /api/inngest/route.ts
This is the standard Next.js route handler for serving all of your Inngest functions.
- Event Matcher: Selects 1-5 event names that we should consider for the query
- Query Writer: Generates a SQL query given a list of events & schemas
- Summarizer: Creates a short summary of the query and adds it to message history
createToolManifest
to create a type which will be used on the client-side to ensure end-to-end type safety.
useAgent
hook, you now have:
- Type Safety: Tool names, inputs, and outputs are fully typed based on your
ToolManifest
- Real-time Streaming: See tools execute in real-time with different states (
input-streaming
,input-available
,executing
,output-available
) - Generative UI: Each tool can have its own custom rendering logic while maintaining type safety
- State Management: The hook automatically manages conversation state, message ordering, and streaming events
- Error Handling: Built-in error states and recovery mechanisms