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 { agui } from '@apeira/plugin-ag-ui'

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

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 {
  onEvent?: (event: AGUIEvent) => void // Direct callback for AG-UI events
}

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