11from typing import Literal , Optional , Union , cast , get_args , get_origin
2+ from warnings import warn
23
4+ from langgraph ._internal ._typing import DeprecatedKwargs
35from langgraph .graph import START , MessagesState , StateGraph
46from langgraph .pregel import Pregel
5- from typing_extensions import Any , TypeVar
7+ from typing_extensions import Any , TypeVar , Unpack
68
79from langgraph_swarm .handoff import get_handoff_destinations
810
@@ -143,12 +145,13 @@ def route_to_active_agent(state: dict) -> str:
143145 return builder
144146
145147
146- def create_swarm (
148+ def create_swarm ( # noqa: D417
147149 agents : list [Pregel ],
148150 * ,
149151 default_active_agent : str ,
150152 state_schema : StateSchemaType = SwarmState ,
151- config_schema : type [Any ] | None = None ,
153+ context_schema : type [Any ] | None = None ,
154+ ** deprecated_kwargs : Unpack [DeprecatedKwargs ],
152155) -> StateGraph :
153156 """Create a multi-agent swarm.
154157
@@ -159,8 +162,7 @@ def create_swarm(
159162 or any other [Pregel](https://langchain-ai.github.io/langgraph/reference/pregel/#langgraph.pregel.Pregel) object.
160163 default_active_agent: Name of the agent to route to by default (if no agents are currently active).
161164 state_schema: State schema to use for the multi-agent graph.
162- config_schema: An optional schema for configuration.
163- Use this to expose configurable parameters via `swarm.config_specs`.
165+ context_schema: Specifies the schema for the context object that will be passed to the workflow.
164166
165167 Returns:
166168 A multi-agent swarm StateGraph.
@@ -208,14 +210,22 @@ def add(a: int, b: int) -> int:
208210 ```
209211
210212 """
213+ if (config_schema := deprecated_kwargs .get ("config_schema" )) is not None :
214+ warn (
215+ "`config_schema` is deprecated. Please use `context_schema` instead." ,
216+ DeprecationWarning ,
217+ stacklevel = 2 ,
218+ )
219+ context_schema = config_schema # type: ignore[assignment]
220+
211221 active_agent_annotation = state_schema .__annotations__ .get ("active_agent" )
212222 if active_agent_annotation is None :
213223 msg = "Missing required key 'active_agent' in state_schema"
214224 raise ValueError (msg )
215225
216226 agent_names = [agent .name for agent in agents ]
217227 state_schema = _update_state_schema_agent_names (state_schema , agent_names )
218- builder = StateGraph (state_schema , config_schema )
228+ builder = StateGraph (state_schema , context_schema )
219229 add_active_agent_router (
220230 builder ,
221231 route_to = agent_names ,
0 commit comments