diff --git a/agent/context_injector.py b/agent/context_injector.py index c01c021..42a07bb 100644 --- a/agent/context_injector.py +++ b/agent/context_injector.py @@ -91,15 +91,25 @@ class ContextInjector: # Debug: Log result type and structure print(f"[DEBUG ContextInjector] Trade result type: {type(result)}") print(f"[DEBUG ContextInjector] Trade result: {result}") - print(f"[DEBUG ContextInjector] isinstance(result, dict): {isinstance(result, dict)}") - # Check if result is a valid position dict (not an error) - if isinstance(result, dict) and "error" not in result and "CASH" in result: + # Extract position dict from MCP result + # MCP tools return CallToolResult objects with structuredContent field + position_dict = None + if hasattr(result, 'structuredContent') and result.structuredContent: + position_dict = result.structuredContent + print(f"[DEBUG ContextInjector] Extracted from structuredContent: {position_dict}") + elif isinstance(result, dict): + position_dict = result + print(f"[DEBUG ContextInjector] Using result as dict: {position_dict}") + + # Check if position dict is valid (not an error) and update state + if position_dict and "error" not in position_dict and "CASH" in position_dict: # Update our tracked position with the new state - self._current_position = result.copy() + self._current_position = position_dict.copy() print(f"[DEBUG ContextInjector] Updated _current_position: {self._current_position}") else: print(f"[DEBUG ContextInjector] Did NOT update _current_position - check failed") + print(f"[DEBUG ContextInjector] position_dict: {position_dict}") print(f"[DEBUG ContextInjector] _current_position remains: {self._current_position}") return result