# LangGraph SDK

> Use the CopilotKit LangGraph SDK for Python to build and run LangGraph workflows 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/langgraph.py
  */
}
## copilotkit_customize_config [#copilotkit_customize_config]

Customize the LangGraph configuration for use in CopilotKit.

    To install the CopilotKit SDK, run:

    ```bash
    pip install copilotkit
    ```

    ### Examples [#examples]

    Disable emitting messages and tool calls:

    ```python
    from copilotkit.langgraph import copilotkit_customize_config

    config = copilotkit_customize_config(
        config,
        emit_messages=False,
        emit_tool_calls=False
    )
    ```

    To emit a tool call as streaming LangGraph 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.langgraph import copilotkit_customize_config

    config = copilotkit_customize_config(
        config,
        emit_intermediate_state=[
           {
                "state_key": "steps",
                "tool": "SearchTool",
                "tool_argument": "steps"
            },
        ]
    )
    ```

### Parameters [#parameters]

<PropertyReference name="base_config" type="Optional[RunnableConfig]" > 
The LangChain/LangGraph configuration to customize. Pass None to make a new configuration.
</PropertyReference>

<PropertyReference name="emit_messages" type="Optional[bool]" > 
Configure how messages are emitted. By default, all messages are emitted. Pass False to disable emitting messages.
</PropertyReference>

<PropertyReference name="emit_tool_calls" type="Optional[Union[bool, str, List[str]]]" > 
Configure how tool calls are emitted. By default, all tool calls are emitted. Pass False to disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.
</PropertyReference>

<PropertyReference name="emit_intermediate_state" type="Optional[List[IntermediateStateConfig]]" > 
Lets you emit tool calls as streaming LangGraph state.
</PropertyReference>

### Returns [#returns]

<PropertyReference name="returns" type="RunnableConfig">
The customized LangGraph configuration.
</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.langgraph import copilotkit_exit

    async def my_node(state: Any, config: RunnableConfig):
        await copilotkit_exit(config)
        return state
    ```

### Parameters [#parameters-1]

<PropertyReference name="config" type="RunnableConfig" required> 
The LangGraph configuration.
</PropertyReference>

### Returns [#returns-1]

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

## 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.

    ### Examples [#examples-2]

    ```python
    from copilotkit.langgraph import copilotkit_emit_state

    for i in range(10):
        await some_long_running_operation(i)
        await copilotkit_emit_state(config, {"progress": i})
    ```

### Parameters [#parameters-2]

<PropertyReference name="config" type="RunnableConfig" required> 
The LangGraph configuration.
</PropertyReference>

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

### 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-3]

    ```python
    from copilotkit.langgraph import copilotkit_emit_message

    message = "Step 1 of 10 complete"
    await copilotkit_emit_message(config, message)

    # Return the message from the node
    return {
        "messages": [AIMessage(content=message)]
    }
    ```

### Parameters [#parameters-3]

<PropertyReference name="config" type="RunnableConfig" required> 
The LangGraph configuration.
</PropertyReference>

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

### Returns [#returns-3]

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

## copilotkit_emit_tool_call [#copilotkit_emit_tool_call]

Manually emits a tool call to CopilotKit.

    ```python
    from copilotkit.langgraph import copilotkit_emit_tool_call

    auto_id = await copilotkit_emit_tool_call(config, name="SearchTool", args={"steps": 10})

    # With a custom ID for correlation/idempotency:
    custom_id = await copilotkit_emit_tool_call(config, name="SearchTool", args={"steps": 10}, tool_call_id="my-custom-id")
    ```

### Parameters [#parameters-4]

<PropertyReference name="config" type="RunnableConfig" required> 
The LangGraph configuration.
</PropertyReference>

<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 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_interrupt [#copilotkit_interrupt]

Interrupts the graph to ask the user through CopilotKit, and returns the answer.

### Parameters [#parameters-5]

<PropertyReference name="message" type="Optional[str]" > 
A message to show the user. Pass either `message` or `action`.
</PropertyReference>

<PropertyReference name="action" type="Optional[str]" > 
The name of a frontend action to call.
</PropertyReference>

<PropertyReference name="args" type="Optional[Dict[str, Any]]" > 
The arguments for `action`.
</PropertyReference>

### Returns [#returns-5]

<PropertyReference name="returns" type="Tuple[str, Any]">
The answer as a string, and the raw response.
</PropertyReference>

## CopilotKitState [#copilotkitstate]

LangGraph state with a `copilotkit` key that holds the frontend actions and
    context from CopilotKit.
