Skip to main content

AG-UI to CrewAI AMP FastAPI bridge

Project description

fiqros-ag-ui-crewai

fiqros-ag-ui-crewai is a FastAPI bridge that converts CrewAI AMP REST responses into AG-UI event streams (SSE), so AG-UI clients (including CopilotKit Cloud) can consume Crew runs correctly.

It acts as middleware between:

  • CopilotKit Cloud / AG-UI client (expects AG-UI streaming events)
  • CrewAI AMP deployment (exposes REST endpoints like /kickoff and /status/{id})

Without this bridge, pointing CopilotKit directly to an AMP URL typically fails because AMP does not emit AG-UI terminal events on the wire.

What this package does

The bridge helper (add_crewai_amp_fastapi_endpoint) mounts a FastAPI route that:

  1. Accepts AG-UI RunAgentInput over POST (for example, /agent)
  2. Emits RUN_STARTED
  3. Calls CrewAI AMP POST /kickoff with the latest user message
  4. Polls AMP GET /status/{kickoff_id} until terminal state
  5. On success:
    • emits TEXT_MESSAGE_START
    • emits chunked TEXT_MESSAGE_CONTENT deltas
    • emits TEXT_MESSAGE_END
  6. On failure:
    • emits RUN_ERROR
  7. Always emits RUN_FINISHED (required so AG-UI clients do not hang)

Why this works with AG-UI

AG-UI clients expect a protocol-compliant event stream, including terminal events. This package converts AMP JSON status/result payloads into AG-UI-compatible SSE events, making CrewAI AMP flows consumable by AG-UI runtimes.

Installation

pip install fiqros-ag-ui-crewai

Quick usage

from fastapi import FastAPI
from fiqros_ag_ui_crewai.amp import add_crewai_amp_fastapi_endpoint

app = FastAPI(title="AG-UI <-> CrewAI AMP Bridge")

add_crewai_amp_fastapi_endpoint(
    app,
    deployment_url="https://your-deployment.crewai.com",
    bearer_token="your-crewai-bearer-token",
    path="/agent",
)

Run:

uvicorn your_module:app --host 0.0.0.0 --port 8000

Then register your AG-UI endpoint as:

  • http://localhost:8000/agent (local)
  • https://<your-ngrok-domain>/agent (public tunnel)

Optional packaged app entry

This package includes fiqros_ag_ui_crewai.app with a ready-made app object that reads environment variables:

  • CREWAI_DEPLOYMENT_URL
  • CREWAI_BEARER_TOKEN

Run it directly:

uvicorn fiqros_ag_ui_crewai.app:app --host 0.0.0.0 --port 8000

Environment variables

When using the packaged app module:

CREWAI_DEPLOYMENT_URL=https://your-deployment.crewai.com
CREWAI_BEARER_TOKEN=your-token

Middleware architecture

CopilotKit Cloud / AG-UI client
            |
            |  POST /agent (AG-UI input)
            v
     FastAPI bridge (this package)
            |
            |  POST /kickoff
            |  GET  /status/{kickoff_id} (polling)
            v
      CrewAI AMP deployment
            |
            |  JSON status/result
            v
     Bridge converts JSON -> AG-UI SSE events
            |
            v
CopilotKit Cloud / AG-UI client

Tuning parameters

add_crewai_amp_fastapi_endpoint(...) supports:

  • path (default: /)
  • poll_interval_seconds (default: 2.0)
  • kickoff_timeout_seconds (default: 600.0)
  • chunk_size (default: 64)

These control endpoint mount path, AMP polling cadence, timeout ceiling, and response chunking granularity.

Notes

  • Use path="/agent" to avoid route collisions and to match typical AG-UI agent endpoint conventions.
  • Ensure your client points to /agent (not /) if mounted there.
  • Keep your bearer token server-side only; never expose it in frontend code.

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

fiqros_ag_ui_crewai-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

fiqros_ag_ui_crewai-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file fiqros_ag_ui_crewai-0.1.0.tar.gz.

File metadata

  • Download URL: fiqros_ag_ui_crewai-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-22-generic

File hashes

Hashes for fiqros_ag_ui_crewai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d303a7734de1d76bfb30f8e819b0c7f54a0213a44245cd094a9c9da505a0010
MD5 d1b415ffe2b34fe53b7ce41cb77811bc
BLAKE2b-256 2fc8e295dcc368ed4ce6b0e391c11c8bc9f9148361bdc25124379f032875f465

See more details on using hashes here.

File details

Details for the file fiqros_ag_ui_crewai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fiqros_ag_ui_crewai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-22-generic

File hashes

Hashes for fiqros_ag_ui_crewai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 812ba564e9d8a48f317f2ee7d8ab28e8c30a96377262d198dba4239e80679e1d
MD5 76eca8e2a9238920883f291f388c8aa9
BLAKE2b-256 64563fe15cae46b74f1b1ad536e9a9f7a7812e48efe9ca554ed0a909bf86d982

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