Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/deepagents/sub_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ def _create_task_tool(
state_schema,
post_model_hook: Optional[Callable] = None,
):
agents = _get_agents(
tools, instructions, subagents, model, state_schema, post_model_hook
)
other_agents_string = _get_subagent_description(subagents)

@tool(
Expand All @@ -109,6 +106,10 @@ async def task(
state: Annotated[DeepAgentState, InjectedState],
tool_call_id: Annotated[str, InjectedToolCallId],
):
agents = _get_agents(
tools, instructions, subagents, model, state_schema, post_model_hook
)

if subagent_type not in agents:
return f"Error: invoked agent of type {subagent_type}, the only allowed types are {[f'`{k}`' for k in agents]}"
sub_agent = agents[subagent_type]
Expand Down Expand Up @@ -136,9 +137,6 @@ def _create_sync_task_tool(
state_schema,
post_model_hook: Optional[Callable] = None,
):
agents = _get_agents(
tools, instructions, subagents, model, state_schema, post_model_hook
)
other_agents_string = _get_subagent_description(subagents)

@tool(
Expand All @@ -150,6 +148,10 @@ def task(
state: Annotated[DeepAgentState, InjectedState],
tool_call_id: Annotated[str, InjectedToolCallId],
):
agents = _get_agents(
tools, instructions, subagents, model, state_schema, post_model_hook
)

if subagent_type not in agents:
return f"Error: invoked agent of type {subagent_type}, the only allowed types are {[f'`{k}`' for k in agents]}"
sub_agent = agents[subagent_type]
Expand Down