DocsRuntimeagent-runtimeCreateAgentHandler
Package: @hexos/runtime

Creates a Next.js App Router handler for streaming agent conversations.

Returns an object with a POST method compatible with Next.js route handlers. On each request, it parses the RuntimeInput from the request body, initializes MCP servers on first use (lazy), and streams RuntimeEvents back as Server-Sent Events (SSE).

The stream follows the SSE format: each event is a data: \{json\}\n\n line, terminated by data: [DONE]\n\n. Errors during streaming are emitted as error events before closing.

Related: AgentRuntime.stream() produces the events, SSETransport consumes them on the frontend, createApprovalHandler handles tool approval decisions.

function createAgentHandler(runtime: AgentRuntime): void

Parameters

runtime