Back to Copilotkit

CopilotRuntime

docs/content/docs/reference/v1/classes/CopilotRuntime.mdx

1.59.22.3 KB
Original Source

{ /*

  • ATTENTION! DO NOT MODIFY THIS FILE!
  • This page is auto-generated. If you want to make any changes to this page, changes must be made at:
  • packages/runtime/src/lib/runtime/copilot-runtime.ts */ } <Callout type="info">

This is the reference for the CopilotRuntime class. For more information and example code snippets, please see Copilot Runtime. </Callout>

Usage

tsx
import { CopilotRuntime } from "@copilotkit/runtime";
 
const copilotKit = new CopilotRuntime();

constructor(params?: CopilotRuntimeConstructorParams<T> & PartialBy<CopilotRuntimeOptions, "agents">)

<PropertyReference name="params" type="CopilotRuntimeConstructorParams<T> & PartialBy<CopilotRuntimeOptions, 'agents'>" > </PropertyReference>

A2UI (Agent-to-UI)

Enable the A2UI middleware to let agents generate rich, interactive UI components at runtime.

a2ui

boolean | object (optional)

Pass true to enable with defaults, false or omit to disable, or an object to customise behaviour.

tsx
// Enable with defaults
const runtime = new CopilotRuntime({
  agents,
  a2ui: true,
});

// Customise
const runtime = new CopilotRuntime({
  agents,
  a2ui: {
    agents: ["my-agent"],
    schema: [
      {
        name: "TodoCard",
        description: "A card displaying a todo item",
        props: { title: { type: "string" }, done: { type: "boolean" } },
      },
    ],
    injectA2UITool: true,
  },
});

When a2ui is configured the runtime reports a2uiEnabled: true from the /info endpoint, which tells the frontend to activate the built-in A2UI renderer automatically.

A2UI Options (object form)

OptionTypeDescription
agentsstring[]Optional. Limit the middleware to these named agents. Applies to all agents if omitted.
schemaA2UIComponentSchema[]Optional. Declares which components are available to agents. Injected as context into RunAgentInput.
injectA2UIToolboolean | stringOptional. true injects a tool named "render_a2ui". A string injects the tool with a custom name. false or omitted means no tool injection.
a2uiToolNamesstring[]Optional. Tool names the middleware recognizes as A2UI rendering tools. Defaults to ["render_a2ui"].