Skip to main content

ag-ui-crewai

Implementation of the AG-UI protocol for CrewAI.

Provides a complete Python integration for CrewAI flows and crews with the AG-UI protocol, including FastAPI endpoint creation and comprehensive event streaming.

Installation

pip install ag-ui-crewai

Usage

from crewai.flow.flow import Flow, start
from litellm import acompletion
from ag_ui_crewai import (
    add_crewai_flow_fastapi_endpoint,
    copilotkit_stream,
    CopilotKitState
)
from fastapi import FastAPI

class MyFlow(Flow[CopilotKitState]):
    @start()
    async def chat(self):
        response = await copilotkit_stream(
            await acompletion(
                model="openai/gpt-4o",
                messages=[
                    {"role": "system", "content": "You are a helpful assistant."},
                    *self.state.messages
                ],
                tools=self.state.copilotkit.actions,
                stream=True
            )
        )
        self.state.messages.append(response.choices[0].message)

# Add to FastAPI
app = FastAPI()
add_crewai_flow_fastapi_endpoint(app, MyFlow(), "/flow")

Features

  • Native CrewAI integration – Direct support for CrewAI flows, crews, and multi-agent systems
  • FastAPI endpoint creation – Automatic HTTP endpoint generation with proper event streaming
  • Predictive state updates – Real-time state synchronization between backend and frontend
  • Streaming tool calls – Live streaming of LLM responses and tool execution to the UI

Tuning knobs

The CrewAI integration exposes three environment variables for tuning timeouts and teardown behaviour. Sensible defaults ship with the package; override these only if your deployment has specific needs (long-running crews, disconnect-heavy workloads, flaky LLM providers).

AGUI_CREWAI_LLM_TIMEOUT_SECONDS

Per-read timeout forwarded to litellm.acompletion in ChatWithCrewFlow.chat. It applies to all three completion sites: the initial call, the post-crew-run follow-up (tool-choice="none") that lets the assistant speak about the crew result, and the post-crew_exit (tool-choice="none") call.

Limitation — no tool chaining after a crew run. The post-crew-run follow-up uses tool_choice="none", so the assistant summarizes the crew result as text but cannot call a frontend action in the same turn. A flow like "run the crew, then update the UI" is not reachable on this path today; allowing bounded tool re-entry there is future work.

  • Default: 120 seconds.
  • Non-positive (e.g. 0, -1): disables the per-read timeout — the underlying HTTP client's default applies instead.
  • Non-finite (nan, inf): falls back to the default.
  • Note: LiteLLM forwards this as a per-read timeout to the underlying HTTP client, not a session-level ceiling. A trickle-feeding server can keep the coroutine alive indefinitely at this layer; use AGUI_CREWAI_FLOW_TIMEOUT_SECONDS for the session-level cap.

AGUI_CREWAI_FLOW_TIMEOUT_SECONDS

Hard wall-clock ceiling on a single flow run. Guards against a runaway flow (hung LiteLLM stream, infinite loop in a user task) pinning the process indefinitely.

  • Default: 600 seconds (10 minutes).
  • Non-positive: disables the ceiling. Only use this for deployments with legitimately long-running crews where the wall-clock ceiling is handled at a higher layer.
  • Non-finite (nan, inf): falls back to the default.
  • When the ceiling fires, the stream yields a RUN_ERROR event with code AGUI_CREWAI_FLOW_TIMEOUT and a message carrying the configured ceiling plus thread/run correlation IDs.

AGUI_CREWAI_CANCEL_JOIN_TIMEOUT_SECONDS

Teardown ceiling: the total wall-clock budget for _cancel_and_join to unwind the kickoff task after a client disconnect, timeout, or error. Covers the grace window, force-cancel join, AND outer-cancel recovery — one shared monotonic deadline, not three.

  • Default: 10 seconds.
  • Non-positive or non-finite: falls back to the default (deliberately not disable-able — a cancel that cannot be bounded is a resource leak).
  • Tune upward if your deployment sees disconnect-heavy load and a consistently-stuck cancel warning is logged.

To run the dojo examples

cd integrations/crew-ai/python
uv sync
uv run dev

Download files

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

Source Distribution

ag_ui_crewai-0.2.1.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

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

ag_ui_crewai-0.2.1-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file ag_ui_crewai-0.2.1.tar.gz.

File metadata

  • Download URL: ag_ui_crewai-0.2.1.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","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 ag_ui_crewai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 01a7be5c5f04ecba1b7ec6b13bb9ee94bc9a29dc48fb0b62c1e69612a2486498
MD5 bcfc2bffe904b4a77f11a5cca16de3a6
BLAKE2b-256 194334e0b284413c562b00acb9b0285b38059569151db9594412fa2b0f3231d3

See more details on using hashes here.

File details

Details for the file ag_ui_crewai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ag_ui_crewai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 40.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","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 ag_ui_crewai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1cfbe30e8d573cddc4ef27d2b6f234fdda5856ce77ec99b20ac2e0ce2528ad7
MD5 8837740368819a674383e78e98e9fc7f
BLAKE2b-256 cc94cb5c90438c43551d5fb9d6f086e84881156099dfbad5db0c3ea2598ab564

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 Sentry Error logging StatusPage Status page