Skip to main content

llama-index protocols AG-UI integration

Project description

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_protocols_ag_ui-0.3.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_protocols_ag_ui-0.3.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_protocols_ag_ui-0.3.1.tar.gz.

File metadata

  • Download URL: llama_index_protocols_ag_ui-0.3.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_protocols_ag_ui-0.3.1.tar.gz
Algorithm Hash digest
SHA256 afe4d145dea2742600ce9fb9be18e42f41f54a8f2fbe61a7d717ee2be4b0767e
MD5 9263ab01e4b1b6fba4a14ec09763f7e5
BLAKE2b-256 3aadc8646b72485502588936f257bcb5c932d5a0a26f8b1531bf8569e57f7d1f

See more details on using hashes here.

File details

Details for the file llama_index_protocols_ag_ui-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: llama_index_protocols_ag_ui-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_protocols_ag_ui-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2953919f50eb77eca33772a730786896b0304bb2209e5c3495206493f25d7d86
MD5 b3cfa16729340e3684da711a4228fa45
BLAKE2b-256 56dee11f6e95be22452b3b7c89736f9eeebfc4839d7de9a061ae7b9502c1b181

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page