# CrewAI SDK

> Use the CopilotKit CrewAI SDK for Python to build and run CrewAI agents with CopilotKit.

## v1 SDK deprecated. Use v2 instead

> This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead.
> For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
> **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](/migrate/v2) and [use the complete export map](/reference/v1/export-map).

{
 /*
  * ATTENTION! DO NOT MODIFY THIS FILE!
  * This page is auto-generated. If you want to make any changes to this page, changes must be made at:
  * sdk-python/copilotkit/crewai/crewai_sdk.py
  */
}
## copilotkit_emit_state [#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:

    ```bash
    pip install copilotkit[crewai]
    ```

    ### Examples [#examples]

    ```python
    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 [#parameters]

<PropertyReference name="state" type="Any" required> 
The state to emit (Must be JSON serializable).
</PropertyReference>

### Returns [#returns]

<PropertyReference name="returns" type="Awaitable[bool]">
Always return True.
</PropertyReference>

## copilotkit_predict_state [#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.)

    ```python
    from copilotkit.crewai import copilotkit_predict_state

    await copilotkit_predict_state(
        {
            "steps": {
                "tool_name": "SearchTool",
                "tool_argument": "steps",
            },
        }
    )
    ```

### Parameters [#parameters-1]

<PropertyReference name="config" type="Dict[str, PredictStateConfig]" required> 
Maps a state key to a `PredictStateConfig` with a `tool_name` and an optional `tool_argument`.
</PropertyReference>

### Returns [#returns-1]

<PropertyReference name="returns" type="Awaitable[bool]">
Always return True.
</PropertyReference>

## copilotkit_exit [#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 [#examples-1]

    ```python
    from copilotkit.crewai import copilotkit_exit

    async def my_function(state):
        await copilotkit_exit()
        return state
    ```

### Returns [#returns-2]

<PropertyReference name="returns" type="Awaitable[bool]">
Always return True.
</PropertyReference>

## copilotkit_emit_message [#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 [#examples-2]

    ```python
    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 [#parameters-2]

<PropertyReference name="message" type="str" required> 
The message to emit.
</PropertyReference>

### Returns [#returns-3]

<PropertyReference name="returns" type="str">
The id of the emitted message.
</PropertyReference>

## copilotkit_emit_tool_call [#copilotkit_emit_tool_call]

Manually emits a tool call to CopilotKit.

    ```python
    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 [#parameters-3]

<PropertyReference name="name" type="str" required> 
The name of the tool to emit.
</PropertyReference>

<PropertyReference name="args" type="Dict[str, Any]" required> 
The arguments to emit.
</PropertyReference>

<PropertyReference name="tool_call_id" type="Optional[str]" > 
Optional tool call ID. If not provided, a random UUID is generated. When provided, this ID is used as both the toolCallId and parentMessageId in AG-UI protocol events. The caller is responsible for ensuring uniqueness.
</PropertyReference>

### Returns [#returns-4]

<PropertyReference name="returns" type="str">
The tool call ID used for the emitted tool call.
</PropertyReference>

## copilotkit_stream [#copilotkit_stream]

Stream litellm responses token by token to CopilotKit.

    ```python
    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
        )
    )
    ```
