Skip to content

Commit d94a7e5

Browse files
committed
update after comment of enyst
1 parent 50cd6fb commit d94a7e5

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

openhands-sdk/openhands/sdk/subagent/registry.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _factory(llm: "LLM") -> "Agent":
146146
from openhands.sdk.tool.spec import Tool
147147

148148
# Load LLM profile if agent_def.model is different from
149-
# 'inherit' and it was given
149+
# 'inherit' and empty string
150150
if agent_def.model and agent_def.model != "inherit":
151151
store = _get_profile_store()
152152
available_profiles = [name.removesuffix(".json") for name in store.list()]
@@ -159,12 +159,6 @@ def _factory(llm: "LLM") -> "Agent":
159159
profile_name = agent_def.model
160160
llm = store.load(profile_name)
161161

162-
# Ensure sub-agent LLM always has streaming disabled and
163-
# reset metrics such that the sub-agent has its own
164-
# Metrics object
165-
llm = llm.model_copy(update={"stream": False})
166-
llm.reset_metrics()
167-
168162
# the system prompt of the subagent is added as a suffix of the
169163
# main system prompt
170164
agent_context = (

openhands-tools/openhands/tools/delegate/impl.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,20 @@ def _spawn_agents(self, action: "DelegateAction") -> DelegateObservation:
122122
]
123123

124124
for agent_id, agent_type in zip(action.ids, resolved_agent_types):
125+
sub_agent_llm = parent_llm.model_copy()
126+
# resetting metrics such that the sub-agent has its own
127+
# Metrics object
128+
sub_agent_llm.reset_metrics()
129+
125130
factory = get_agent_factory(name=agent_type)
126-
worker_agent = factory.factory_func(parent_llm)
131+
worker_agent = factory.factory_func(sub_agent_llm)
132+
133+
# ensuring that the sub-agent LLM has stream deactivated
134+
worker_agent = worker_agent.model_copy(
135+
update={
136+
"llm": worker_agent.llm.model_copy(update={"stream": False})
137+
}
138+
)
127139

128140
# Use parent visualizer's create_sub_visualizer method if available
129141
# This allows custom visualizers (e.g., TUI-based) to create

openhands-tools/openhands/tools/task/manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,19 @@ def _get_sub_agent(self, subagent_type: str) -> Agent:
238238
"""
239239
parent = self.parent_conversation
240240
parent_llm = parent.agent.llm
241+
sub_agent_llm = parent_llm.model_copy()
242+
# Reset metrics such that the sub-agent has its own
243+
# Metrics object
244+
sub_agent_llm.reset_metrics()
241245

242246
factory = get_agent_factory(subagent_type)
243-
return factory.factory_func(parent_llm)
247+
sub_agent = factory.factory_func(sub_agent_llm)
248+
249+
# ensuring that the sub-agent LLM has stream deactivated
250+
sub_agent = sub_agent.model_copy(
251+
update={"llm": sub_agent.llm.model_copy(update={"stream": False})}
252+
)
253+
return sub_agent
244254

245255
def _run_task(self, task: Task, prompt: str) -> Task:
246256
"""Run a task synchronously."""

0 commit comments

Comments
 (0)