# CrewAIAgent

> CrewAIAgent lets you define your agent for use 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_agent.py
  */
}
## CrewAIAgent [#crewaiagent]

CrewAIAgent lets you define your agent for use with CopilotKit.

    To install, run:

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

    Every agent must have the `name` and either `crew` or `flow` properties defined. An optional
    `description` can also be provided. This is used when CopilotKit is dynamically routing requests
    to the agent.

    ## Serving a Crew based agent [#serving-a-crew-based-agent]

    To serve a Crew based agent, pass in a `Crew` object to the `crew` parameter.

    Note:
    You need to make sure to have a `chat_llm` set on the `Crew` object.
    See [the CrewAI docs](https://docs.crewai.com/concepts/cli#9-chat) for more information.

    ```python
    from copilotkit.crewai import CrewAIAgent


    CrewAIAgent(
        name="email_agent_crew",
        description="This crew based agent sends emails",
        crew=SendEmailCrew(),
    )
    ```

    ## Serving a Flow based agent [#serving-a-flow-based-agent]

    To serve a Flow based agent, pass in a `Flow` object to the `flow` parameter.

    ```python
    CrewAIAgent(
        name="email_agent_flow",
        description="This flow based agent sends emails",
        flow=SendEmailFlow(),
    )
    ```

    Note:
    Either a `crew` or `flow` must be provided to CrewAIAgent.

### Parameters [#parameters]

<PropertyReference name="name" type="str" required> 
The name of the agent.
</PropertyReference>

<PropertyReference name="crew" type="Optional[Crew]" > 
When using a Crew based agent, pass in a `Crew` object to the `crew` parameter. Pass exactly one of `crew` or `flow`.
</PropertyReference>

<PropertyReference name="flow" type="Optional[Flow]" > 
When using a Flow based agent, pass in a `Flow` object to the `flow` parameter. Pass exactly one of `crew` or `flow`.
</PropertyReference>

<PropertyReference name="description" type="Optional[str]" > 
The description of the agent.
</PropertyReference>

<PropertyReference name="copilotkit_config" type="Optional[CopilotKitConfig]" > 
The CopilotKit config to use with the agent.
</PropertyReference>

## CopilotKitConfig [#copilotkitconfig]

CopilotKit config for CrewAIAgent

    This is used for advanced cases where you want to customize how CopilotKit interacts with
    CrewAI.

    ```python
    # Function signatures:
    def merge_state(
        *,
        state: dict,
        messages: List[Any],
        actions: List[Any],
        agent_name: str,
        flow: Flow,
    ):
        # ...implementation...

    ```

    merge_state runs only for flow-based agents.

### Parameters [#parameters-1]

<PropertyReference name="merge_state" type="Optional[Callable]" > 
This function lets you customize how CopilotKit merges the agent state. Defaults to the built-in merge.
</PropertyReference>
