Skip to content

πŸ™Œ OpenHands: AI-Driven Development

bugfix for #8187 (infinite loop when delegating) (#8189)

Chasede175dcc8757
diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py
index c13c348731..f057567a24 100644
--- a/openhands/controller/agent_controller.py
+++ b/openhands/controller/agent_controller.py
@@ -741,10 +741,6 @@ class AgentController:
content = (
f'{self.delegate.agent.name} finishes task with {formatted_output}'
)
-
- # emit the delegate result observation
- obs = AgentDelegateObservation(outputs=delegate_outputs, content=content)
- self.event_stream.add_event(obs, EventSource.AGENT)
else:
# delegate state is ERROR
# emit AgentDelegateObservation with error content
@@ -755,13 +751,22 @@ class AgentController:
f'{self.delegate.agent.name} encountered an error during execution.'
)
- # emit the delegate result observation
- obs = AgentDelegateObservation(outputs=delegate_outputs, content=content)
- self.event_stream.add_event(obs, EventSource.AGENT)
+ content = f'Delegated agent finished with result:\n\n{content}'
+
+ # emit the delegate result observation
+ obs = AgentDelegateObservation(outputs=delegate_outputs, content=content)
+
+ # associate the delegate action with the initiating tool call
+ for event in reversed(self.state.history):
+ if isinstance(event, AgentDelegateAction):
+ delegate_action = event
+ obs.tool_call_metadata = delegate_action.tool_call_metadata
+ break
+
+ self.event_stream.add_event(obs, EventSource.AGENT)
# unset delegate so parent can resume normal handling
self.delegate = None
- self.delegateAction = None
async def _step(self) -> None:
"""Executes a single step of the parent or delegate agent. Detects stuck agents and limits on the number of iterations and the task budget."""
diff --git a/openhands/memory/conversation_memory.py b/openhands/memory/conversation_memory.py
index 46d43a416a..d8f1c87cde 100644
--- a/openhands/memory/conversation_memory.py
+++ b/openhands/memory/conversation_memory.py
@@ -412,7 +412,7 @@ class ConversationMemory:
logger.debug('Vision disabled for browsing, showing text')
elif isinstance(obs, AgentDelegateObservation):
text = truncate_content(
- obs.outputs['content'] if 'content' in obs.outputs else '',
+ obs.outputs.get('content', obs.content),
max_message_chars,
)
message = Message(role='user', content=[TextContent(text=text)])