Skip to content

@apeira/plugin-ag-ui

Bridges Apeira lifecycle and model events to @ag-ui/core format, enabling AG-UI compatible frontends (such as CopilotKit) to render agent conversations.

Install

sh
pnpm add @apeira/plugin-ag-ui

Usage

ts
import { createAgent } from '@apeira/core'
import { responses } from '@apeira/core/responses'
import { agui } from '@apeira/plugin-ag-ui'

const agent = createAgent({
  instructions: 'You are a helpful assistant.',
  plugins: [agui({ threadId: 'thread-1' })],
  runner: responses({
    apiKey: process.env.OPENAI_API_KEY,
    baseURL: 'https://api.openai.com/v1/',
    model: 'gpt-5.5',
  }),
})

API

agui(options)

Creates an Apeira plugin that maps agent events to @ag-ui/core AGUIEvent types:

Apeira eventAG-UI event
turn.startRUN_STARTED
turn.doneRUN_FINISHED
turn.failedRUN_ERROR
turn.abortedRUN_FINISHED (aborted)
text.start / text.delta / text.doneTEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END
reasoning.start / reasoning.delta / reasoning.doneREASONING_START / REASONING_MESSAGE_CONTENT / REASONING_END
tool-call.start / tool-call.delta / tool-call.doneTOOL_CALL_START / TOOL_CALL_ARGS / TOOL_CALL_END
tool-result.doneTOOL_CALL_RESULT
step.start / step.doneSTEP_STARTED / STEP_FINISHED

Options

ts
interface AGUIPluginOptions {
  threadId: string
}

Events are emitted on the 'ag-ui' channel via agent.emit(). Use agent.subscribe('ag-ui', event => ...) to receive typed AG-UI events — the package augments AgentCustomEvent so event is automatically inferred as AGUIEvent.