CrewAI SDK
Use the CopilotKit CrewAI SDK for Python to build and run CrewAI agents with CopilotKit.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
copilotkit_emit_state
Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to update the user with the current state of the node.
To install the CopilotKit SDK, run:
pip install copilotkit[crewai]Examples
from copilotkit.crewai import copilotkit_emit_state
for i in range(10):
await some_long_running_operation(i)
await copilotkit_emit_state({"progress": i})Parameters
Prop
Type
Returns
Prop
Type
copilotkit_predict_state
Stream tool calls as state to CopilotKit.
To emit a tool call as streaming CrewAI state, pass the destination key in state, the tool name and optionally the tool argument. (If you don't pass the argument name, all arguments are emitted under the state key.)
from copilotkit.crewai import copilotkit_predict_state
await copilotkit_predict_state(
{
"steps": {
"tool_name": "SearchTool",
"tool_argument": "steps",
},
}
)Parameters
Prop
Type
Returns
Prop
Type
copilotkit_exit
Exits the current agent after the run completes. Calling copilotkit_exit() will not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after the run completes.
Examples
from copilotkit.crewai import copilotkit_exit
async def my_function(state):
await copilotkit_exit()
return stateReturns
Prop
Type
copilotkit_emit_message
Manually emits a message to CopilotKit. Useful in longer running nodes to update the user. Important: You still need to return the messages from the node.
Examples
from copilotkit.crewai import copilotkit_emit_message
message = "Step 1 of 10 complete"
await copilotkit_emit_message(message)
# Return the message from the node
return {
"messages": [AIMessage(content=message)]
}Parameters
Prop
Type
Returns
Prop
Type
copilotkit_emit_tool_call
Manually emits a tool call to CopilotKit.
from copilotkit.crewai import copilotkit_emit_tool_call
auto_id = await copilotkit_emit_tool_call(name="SearchTool", args={"steps": 10})
# With a custom ID for correlation/idempotency:
custom_id = await copilotkit_emit_tool_call(name="SearchTool", args={"steps": 10}, tool_call_id="my-custom-id")Parameters
Prop
Type
Returns
Prop
Type
copilotkit_stream
Stream litellm responses token by token to CopilotKit.
from litellm import completion
from copilotkit.crewai import copilotkit_stream
response = await copilotkit_stream(
completion(
model="openai/gpt-6-luna",
reasoning_effort="none",
allowed_openai_params=["reasoning_effort"],
messages=messages,
tools=tools,
stream=True # this must be set to True for streaming
)
)How is this guide?