Skip to content

Commit d6ea049

Browse files
committed
fix(autonomous-loop): omit the tools kwarg instead of passing None
Pyre flagged the call: Agent.__init__ annotates tools as List[Callable], not Optional, so tools=parent_tools or None is an incompatible parameter type. tools=[] is not an equivalent substitute — exists([]) is true, so an empty list would send every sub-agent response through tool execution. Omitting the keyword leaves the parameter at its own None default, which is what a tool-less sub-agent had before this branch.
1 parent 26675b6 commit d6ea049

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

swarms/structs/autonomous_loop_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,19 +1244,27 @@ def create_sub_agent_tool(
12441244
# strictly less capable than the parent asking the question itself.
12451245
parent_tools = list(getattr(agent, "tools", None) or [])
12461246

1247+
# Omitted rather than passed as [], which is not the same thing:
1248+
# exists([]) is true, so an empty list sends every response
1249+
# through tool execution. Agent.tools is annotated List[Callable],
1250+
# so None is not passable either.
1251+
tool_kwargs = (
1252+
{"tools": parent_tools} if parent_tools else {}
1253+
)
1254+
12471255
# Create sub-agent with the same LLM and tools as parent
12481256
sub_agent = Agent(
12491257
id=agent_id,
12501258
agent_name=agent_name,
12511259
agent_description=agent_description,
12521260
system_prompt=system_prompt, # Use custom system prompt if provided
12531261
model_name=agent.model_name,
1254-
tools=parent_tools or None,
12551262
# Tools need a call-then-read turn. Finite whatever the parent
12561263
# is, so a max_loops="auto" parent cannot recurse into sub-agents.
12571264
max_loops=5 if parent_tools else 1,
12581265
print_on=getattr(agent, "print_on", False),
12591266
verbose=agent.verbose,
1267+
**tool_kwargs,
12601268
)
12611269

12621270
# Cache the sub-agent

0 commit comments

Comments
 (0)