A2UI Launched: Full CopilotKit support at launch!

A2UI Launched: CopilotKit has partnered with Google to deliver full support in both CopilotKit and AG-UI!

Check it out
LogoLogo
  • Overview
  • Integrations
  • API Reference
  • Copilot Cloud
Slanted end borderSlanted end border
Slanted start borderSlanted start border
  • API Reference
  • UI Components
  • CopilotTextarea
  • CopilotKit
  • Hooks
  • useAgent
  • useDefaultTool
  • useFrontendTool
  • useRenderToolCall
  • useHumanInTheLoop
  • useCopilotReadable
  • useCopilotAdditionalInstructions
  • useCopilotChat
  • useCopilotChatHeadless_c
  • useCopilotChatSuggestions
  • useCoAgent
  • useCoAgentStateRender
  • useLangGraphInterrupt
  • useCopilotAction
  • Classes
  • CopilotRuntime
  • CopilotTask
  • SDKs
Python

LangGraph SDK

The CopilotKit LangGraph SDK for Python allows you to build and run LangGraph workflows with CopilotKit.

copilotkit_customize_config

Customize the LangGraph configuration for use in CopilotKit.

To install the CopilotKit SDK, run:

pip install copilotkit

Examples

Disable emitting messages and tool calls:

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

from copilotkit.langgraph import copilotkit_customize_config

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

Parameters

base_configOptional[RunnableConfig]

The LangChain/LangGraph configuration to customize. Pass None to make a new configuration.

emit_messagesOptional[bool]

Configure how messages are emitted. By default, all messages are emitted. Pass False to disable emitting messages.

emit_tool_callsOptional[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.

emit_intermediate_stateOptional[List[IntermediateStateConfig]]

Lets you emit tool calls as streaming LangGraph state.

Returns

returnsRunnableConfig

The customized LangGraph configuration.

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.langgraph import copilotkit_exit

def my_node(state: Any):
    await copilotkit_exit(config)
    return state

Parameters

configRunnableConfigrequired

The LangGraph configuration.

Returns

returnsAwaitable[bool]

Always return True.

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

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

configRunnableConfigrequired

The LangGraph configuration.

stateAnyrequired

The state to emit (Must be JSON serializable).

Returns

returnsAwaitable[bool]

Always return True.

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

configRunnableConfigrequired

The LangGraph configuration.

messagestrrequired

The message to emit.

Returns

returnsAwaitable[bool]

Always return True.

copilotkit_emit_tool_call

Manually emits a tool call to CopilotKit.

from copilotkit.langgraph import copilotkit_emit_tool_call

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

Parameters

configRunnableConfigrequired

The LangGraph configuration.

namestrrequired

The name of the tool to emit.

argsDict[str, Any]required

The arguments to emit.

Returns

returnsAwaitable[bool]

Always return True.

PREV
LangGraphAgent
Slanted end borderSlanted end border
Slanted start borderSlanted start border
NEXT
CrewAIAgent

On this page

copilotkit_customize_config
Examples
Parameters
Returns
copilotkit_exit
Examples
Parameters
Returns
copilotkit_emit_state
Examples
Parameters
Returns
copilotkit_emit_message
Examples
Parameters
Returns
copilotkit_emit_tool_call
Parameters
Returns