diff --git a/openhands/agenthub/codeact_agent/function_calling.py b/openhands/agenthub/codeact_agent/function_calling.py index d3abf0494843..be39a1624ab5 100644 --- a/openhands/agenthub/codeact_agent/function_calling.py +++ b/openhands/agenthub/codeact_agent/function_calling.py @@ -16,7 +16,6 @@ FunctionCallNotExistsError, FunctionCallValidationError, ) -from openhands.core.logger import openhands_logger as logger from openhands.events.action import ( Action, AgentDelegateAction, @@ -541,26 +540,27 @@ def response_to_actions(response: ModelResponse) -> list[Action]: raise FunctionCallValidationError( f'Missing required argument "path" in tool call {tool_call.function.name}' ) + path = arguments['path'] + command = arguments['command'] + other_kwargs = { + k: v for k, v in arguments.items() if k not in ['command', 'path'] + } - # We implement this in agent_skills, which can be used via Jupyter - # convert tool_call.function.arguments to kwargs that can be passed to file_editor - code = f'print(file_editor(**{arguments}))' - logger.debug( - f'TOOL CALL: str_replace_editor -> file_editor with code: {code}' - ) - - if arguments['command'] == 'view': + if command == 'view': action = FileReadAction( - path=arguments['path'], - translated_ipython_code=code, + path=path, impl_source=FileReadSource.OH_ACI, + view_range=other_kwargs.get('view_range', None), ) else: + if 'view_range' in other_kwargs: + # Remove view_range from other_kwargs since it is not needed for FileEditAction + other_kwargs.pop('view_range') action = FileEditAction( - path=arguments['path'], - content='', # dummy value -- we don't need it - translated_ipython_code=code, + path=path, + command=command, impl_source=FileEditSource.OH_ACI, + **other_kwargs, ) elif tool_call.function.name == 'browser': if 'code' not in arguments: @@ -590,12 +590,6 @@ def response_to_actions(response: ModelResponse) -> list[Action]: total_calls_in_response=len(assistant_msg.tool_calls), ) actions.append(action) - - # Add logging for each created action - for action in actions: - accumulated_cost = action.llm_metrics.accumulated_cost if action.llm_metrics else None - logger.info(f"Action created - Accumulated Cost: {accumulated_cost}") - logger.info(f"Action type: {type(action)}") else: actions.append( MessageAction(content=assistant_msg.content, wait_for_response=True) diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py index d7be45680c07..1e338810198a 100644 --- a/openhands/controller/agent_controller.py +++ b/openhands/controller/agent_controller.py @@ -203,10 +203,6 @@ def update_state_before_step(self): async def update_state_after_step(self): # update metrics especially for cost. Use deepcopy to avoid it being modified by agent._reset() self.state.local_metrics = copy.deepcopy(self.agent.llm.metrics) - - # Add logging for metrics update - accumulated_cost = self.state.local_metrics.accumulated_cost if self.state.local_metrics else None - logger.info(f"After update_state_after_step - State Local Metrics Accumulated Cost: {accumulated_cost}") async def _react_to_exception( self, diff --git a/openhands/events/stream.py b/openhands/events/stream.py index 66dc02cd61e7..938269822a7a 100644 --- a/openhands/events/stream.py +++ b/openhands/events/stream.py @@ -262,10 +262,6 @@ def unsubscribe(self, subscriber_id: EventStreamSubscriber, callback_id: str): self._clean_up_subscriber(subscriber_id, callback_id) def add_event(self, event: Event, source: EventSource): - # Add logs for accumulated cost debugging. - accumulated_cost = event.llm_metrics.accumulated_cost if event.llm_metrics else None - logger.info(f"Adding event to stream - Accumulated Cost: {accumulated_cost}") - if hasattr(event, '_id') and event.id is not None: raise ValueError( f'Event already has an ID:{event.id}. It was probably added back to the EventStream from inside a handler, triggering a loop.'