Execute a task through multiple rounds of planning and tool calls. This is the main entry point for task execution. It manages the multi-round execution loop, calling tools as needed and accumulating information until the task is complete. Args:
(self, task: str)
| 67 | self.total_tokens = 0 |
| 68 | |
| 69 | async def execute(self, task: str) -> Dict[str, Any]: |
| 70 | """Execute a task through multiple rounds of planning and tool calls. |
| 71 | |
| 72 | This is the main entry point for task execution. It manages the multi-round |
| 73 | execution loop, calling tools as needed and accumulating information until |
| 74 | the task is complete. |
| 75 | |
| 76 | Args: |
| 77 | task: Natural language description of the task to execute |
| 78 | |
| 79 | Returns: |
| 80 | Dictionary containing: |
| 81 | - solution: Final synthesized solution |
| 82 | - total_rounds: Number of execution rounds |
| 83 | - execution_results: List of all tool execution results |
| 84 | - planning_json_compliance: Ratio of valid to total planned tools |
| 85 | - accumulated_information: All gathered information |
| 86 | |
| 87 | Raises: |
| 88 | RuntimeError: If execution fails after maximum rounds |
| 89 | """ |
| 90 | logger.info(f"Starting multi-server execution for task: \"{task}\"") |
| 91 | |
| 92 | # Log token consumption statistics for tool descriptions and input schemas |
| 93 | self._log_tools_token_stats() |
| 94 | |
| 95 | |
| 96 | self._last_planning_info = { |
| 97 | 'mode': 'multi-round', |
| 98 | 'rounds': [] |
| 99 | } |
| 100 | |
| 101 | max_rounds = config_loader.get_max_execution_rounds() |
| 102 | for round_num in range(1, max_rounds + 1): |
| 103 | logger.info(f"--- Starting Round {round_num}/{max_rounds} ---") |
| 104 | |
| 105 | should_continue, reasoning, round_executions = await self._plan_next_actions(task, round_num) |
| 106 | |
| 107 | round_planning_info = { |
| 108 | 'round_number': round_num, |
| 109 | 'should_continue': should_continue, |
| 110 | 'reasoning': reasoning |
| 111 | } |
| 112 | self._last_planning_info['rounds'].append(round_planning_info) |
| 113 | |
| 114 | logger.info(f"Decision: {'CONTINUE' if should_continue else 'STOP'}. Reasoning: {reasoning}") |
| 115 | |
| 116 | if not should_continue: |
| 117 | logger.info(f"Stopping execution after {round_num-1} rounds.") |
| 118 | break |
| 119 | |
| 120 | if not round_executions: |
| 121 | logger.info(f"No tool executions planned for round {round_num}. Stopping.") |
| 122 | break |
| 123 | |
| 124 | round_results = await self._execute_planned_tools(round_executions, round_num) |
| 125 | await self._update_state(round_results, round_num) |
| 126 |
no test coverage detected