Skip to content
Closed
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
13 changes: 10 additions & 3 deletions src/deepagents/sub_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from langchain.chat_models import init_chat_model
from typing import Annotated, NotRequired, Any, Union, Optional, Callable
from langgraph.types import Command
from langchain_core.runnables import Runnable
from langchain_core.runnables import Runnable, RunnableConfig

from langgraph.prebuilt import InjectedState

Expand Down Expand Up @@ -106,14 +106,20 @@ def _create_task_tool(
async def task(
description: str,
subagent_type: str,
special_config_param: RunnableConfig,
state: Annotated[DeepAgentState, InjectedState],
tool_call_id: Annotated[str, InjectedToolCallId],
):
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]
state["messages"] = [{"role": "user", "content": description}]
result = await sub_agent.ainvoke(state)
if special_config_param.get('configurable').get("stream_mode") == "stream":
result = None
async for chunk in sub_agent.astream(input=state, config=special_config_param):
result = chunk
else:
result = await sub_agent.ainvoke(input=state, config=special_config_param)
return Command(
update={
"files": result.get("files", {}),
Expand Down Expand Up @@ -148,14 +154,15 @@ def _create_sync_task_tool(
def task(
description: str,
subagent_type: str,
special_config_param: RunnableConfig,
state: Annotated[DeepAgentState, InjectedState],
tool_call_id: Annotated[str, InjectedToolCallId],
):
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]
state["messages"] = [{"role": "user", "content": description}]
result = sub_agent.invoke(state)
result = sub_agent.invoke(input=state, config=special_config_param)
return Command(
update={
"files": result.get("files", {}),
Expand Down