1
1
from typing import Literal , Optional , Union , cast , get_args , get_origin
2
+ from warnings import warn
2
3
4
+ from langgraph ._internal ._typing import DeprecatedKwargs
3
5
from langgraph .graph import START , MessagesState , StateGraph
4
6
from langgraph .pregel import Pregel
5
- from typing_extensions import Any , TypeVar
7
+ from typing_extensions import Any , TypeVar , Unpack
6
8
7
9
from langgraph_swarm .handoff import get_handoff_destinations
8
10
@@ -143,12 +145,13 @@ def route_to_active_agent(state: dict) -> str:
143
145
return builder
144
146
145
147
146
- def create_swarm (
148
+ def create_swarm ( # noqa: D417
147
149
agents : list [Pregel ],
148
150
* ,
149
151
default_active_agent : str ,
150
152
state_schema : StateSchemaType = SwarmState ,
151
- config_schema : type [Any ] | None = None ,
153
+ context_schema : type [Any ] | None = None ,
154
+ ** deprecated_kwargs : Unpack [DeprecatedKwargs ],
152
155
) -> StateGraph :
153
156
"""Create a multi-agent swarm.
154
157
@@ -159,8 +162,7 @@ def create_swarm(
159
162
or any other [Pregel](https://langchain-ai.github.io/langgraph/reference/pregel/#langgraph.pregel.Pregel) object.
160
163
default_active_agent: Name of the agent to route to by default (if no agents are currently active).
161
164
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.
164
166
165
167
Returns:
166
168
A multi-agent swarm StateGraph.
@@ -208,14 +210,22 @@ def add(a: int, b: int) -> int:
208
210
```
209
211
210
212
"""
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
+
211
221
active_agent_annotation = state_schema .__annotations__ .get ("active_agent" )
212
222
if active_agent_annotation is None :
213
223
msg = "Missing required key 'active_agent' in state_schema"
214
224
raise ValueError (msg )
215
225
216
226
agent_names = [agent .name for agent in agents ]
217
227
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 )
219
229
add_active_agent_router (
220
230
builder ,
221
231
route_to = agent_names ,
0 commit comments