Skip to main content

LlamaIndex Protocols AG UI Integration

pip install llama-index-protocols-ag-ui

The llama-index-protocols-ag-ui package provides a factory function for creating a FastAPI router that communicates using the AG UI Protocol.

Using this package, you can quickly create a FastAPI app that can be used to communicate with AG-UI compatible frameworks like CopilotKit.

AG-UI 1.0 content migration

This integration requires ag-ui-protocol>=1.0.0,<2 and llama-index-core>=0.14.1,<0.15. Run-start events declare the SDK's PROTOCOL_VERSION in the wire protocolVersion field.

User messages accept strings or AG-UI ContentPart arrays. Use TextPart, ImagePart, AudioPart, VideoPart, and DocumentPart with DataSource or UrlSource for media. The deprecated BinaryInputContent converter has been removed. Before sending older persisted messages to this endpoint, migrate each type: "binary" part to its media type (image, audio, video, or document) and move its url or base64 data into a source, for example:

{
  "type": "image",
  "source": {
    "type": "data",
    "value": "<base64 image bytes>",
    "mimeType": "image/png"
  }
}

Opaque provider handles use FileSource (type: "file"). The generic LlamaIndex media blocks used here cannot forward these handles, so such parts are skipped with a warning. Handles are never fetched or interpreted as URLs; use a supported data or URL source when the model needs the media.

Tool messages accept strings or ContentPart arrays. This adapter's tool-result path is text-only: text fragments are concatenated in order without trimming or inserting separators, and media parts are skipped with a warning. Empty or media-only results become an empty string. Message and tool-call IDs are preserved, and snapshots emit the resulting text. User-message media conversion and the state markers used to restore existing LlamaIndex sessions are unchanged.

Usage

The get_ag_ui_workflow_router function is a factory function that creates a FastAPI router that can be used to communicate with AG-UI compatible frameworks like CopilotKit.

The router is configured with the following parameters:

  • llm: The LLM to use for the agent.
  • frontend_tools: Tools that are available to execute on the frontend.
  • backend_tools: Tools that are available to execute on the backend.
  • system_prompt: The system prompt to use for the agent.
  • initial_state: The initial state to use for the agent. Typically the state is then interacted with by the frontend.
import uvicorn
from fastapi import FastAPI

from llama_index.llms.openai import OpenAI
from llama_index.protocols.ag_ui.server import get_ag_ui_workflow_router
from typing import Annotated


# This tool has a client-side version that is actually called to change the background
def change_background(
    background: Annotated[str, "The background. Prefer gradients."],
) -> str:
    """Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc."""
    return f"Changing background to {background}"


agentic_chat_router = get_ag_ui_workflow_router(
    llm=OpenAI(model="gpt-4.1"),
    frontend_tools=[change_background],
    backend_tools=[],
    system_prompt="You are a helpful assistant that can change the background color of the chat.",
    initial_state=None,  # Unused in this example
)


app = FastAPI(title="AG-UI Llama-Index Endpoint")

app.include_router(agentic_chat_router, prefix="/agentic_chat")


if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=9000)

Then on the frontend, you might have setup a CopilotKit app like this:

"use client";
import React, { useState } from "react";
import "@copilotkit/react-ui/styles.css";
import "./style.css";
import { useCopilotAction } from "@copilotkit/react-core";
import { CopilotChat } from "@copilotkit/react-ui";

interface AgenticChatProps {
  params: Promise<{
    integrationId: string;
  }>;
}

const Chat = () => {
  const [background, setBackground] = useState<string>("--copilot-kit-background-color");

  useCopilotAction({
    name: "change_background",
    description:
      "Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.",
    parameters: [
      {
        name: "background",
        type: "string",
        description: "The background. Prefer gradients.",
      },
    ],
    handler: ({ background }) => {
      setBackground(background);
    },
  });

  return (
    <div className="flex justify-center items-center h-full w-full" style={{ background }}>
      <div className="w-8/10 h-8/10 rounded-lg">
        <CopilotChat
          className="h-full rounded-2xl"
          labels={{ initial: "Hi, I'm an agent. Want to chat?" }}
        />
      </div>
    </div>
  );
};

Check out the CopilotKit Documentation for more details on using AG-UI with CopilotKit+LlamaIndex.

Metadata

Release files for llama-index-protocols-ag-ui 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-protocols-ag-ui 0.7.0
File Size Uploaded Provenance Actions
llama_index_protocols_ag_ui-0.7.0.tar.gz 13.9 kB Without provenance Details for llama_index_protocols_ag_ui-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-protocols-ag-ui 0.7.0
File Interpreter ABI Platform Actions
llama_index_protocols_ag_ui-0.7.0-py3-none-any.whl Python 3 none any Details for llama_index_protocols_ag_ui-0.7.0-py3-none-any.whl

Total release size: 29.5 kB

Release files / llama_index_protocols_ag_ui-0.7.0.tar.gz

Download URL llama_index_protocols_ag_ui-0.7.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
25a38a3fc62ac071b994c95fb2104873252823419f07e2cc49bd05af439b73ae
BLAKE2b-256 checksum
How to use checksums
a17c16b891871c8732d454eaa465c66f876ed12e1c1708921c9319d54a15fe2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_protocols_ag_ui-0.7.0-py3-none-any.whl

Download URL llama_index_protocols_ag_ui-0.7.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b007a3fad478d1b585ebb37f16e92218163d53d26c0e4afea7550b5e309eee3
BLAKE2b-256 checksum
How to use checksums
fd1c500f8a01e3ff2f0daf4c73a94c56c96461cab283c429ba4198b4b7cabd34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-protocols-ag-ui 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page