Implementation of the AG-UI protocol for CrewAI
Project description
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 (both the initial call and the post-crew_exit
tool-choice="none" call).
- Default:
120seconds. - 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_SECONDSfor 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:
600seconds (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_ERRORevent with codeAGUI_CREWAI_FLOW_TIMEOUTand 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:
10seconds. - 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 python/ag_ui_crewai
poetry install
poetry run dev
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ag_ui_crewai-0.2.0.tar.gz.
File metadata
- Download URL: ag_ui_crewai-0.2.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
090ce4d2b88689947510aa631c6d0177543ac0a79a94300ad7c0983d363f408b
|
|
| MD5 |
e6923489f659919e393a04f270348dab
|
|
| BLAKE2b-256 |
52a603df3ce106e387b82257ba9151e4a0819884c484c3949a5d030ae6e16e56
|
File details
Details for the file ag_ui_crewai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ag_ui_crewai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0e856d9d4022a6492a88ef193da86905a9e620d8a2d59a2e50f310fefd1c4b1
|
|
| MD5 |
2c1a72d9e877d49e4db25ac3050302ad
|
|
| BLAKE2b-256 |
efd6d2c566d16384f7f3a520e6d1a2bdbbcf220366c88ef22e83979655f020e8
|