-
Notifications
You must be signed in to change notification settings - Fork 135
Description
Problem
The example examples/01_standalone_sdk/30_tom_agent.py fails in CI with:
RuntimeError: Agent not initialized; call initialize() before use
Root Cause
Line 73 accesses conversation.agent.tools_map before the agent is initialized:
sleeptime_compute_tool = conversation.agent.tools_map.get("sleeptime_compute")The tools_map property in agent/base.py (line 505) requires the agent to be initialized first:
@property
def tools_map(self) -> dict[str, ToolDefinition]:
if not self._initialized:
raise RuntimeError("Agent not initialized; call initialize() before use")
return self._toolsThe agent is only initialized when conversation.run() is called (via init_state() -> _initialize()), but the example tries to access tools_map before calling run().
Possible Fixes
-
Move the sleeptime_compute invocation after conversation.run() - This would require restructuring the example flow
-
Call init_state() manually - Add explicit initialization before accessing tools_map:
# Manually initialize agent to access tools from openhands.sdk.conversation import ConversationState state = ConversationState(...) conversation.agent.init_state(state, lambda x: None) sleeptime_compute_tool = conversation.agent.tools_map.get("sleeptime_compute")
-
Remove the pre-run tool invocation - Since the code block is meant to be optional (it checks if tool exists), simply remove it and only run sleeptime_compute as part of the conversation
-
Add a public method to access tools before initialization - Expose a method that returns tool definitions without requiring full initialization
Related
- Discovered in PR #1827 workflow run
- Related fix PR: Fix: Add EXAMPLE_COST marker to critic example #1830