Execute a single plan step. 1. Resolve the MCP server assigned to this step. 2. If no tool is specified, return expected_output directly. 3. Call the LLM to generate tool arguments from the task and prior results. 4. Call the tool and return its result.
(
self,
step: PlanStep,
context: dict[int, StepResult],
question: str,
tool_schema: str = "",
)
| 125 | return results |
| 126 | |
| 127 | async def execute_step( |
| 128 | self, |
| 129 | step: PlanStep, |
| 130 | context: dict[int, StepResult], |
| 131 | question: str, |
| 132 | tool_schema: str = "", |
| 133 | ) -> StepResult: |
| 134 | """Execute a single plan step. |
| 135 | |
| 136 | 1. Resolve the MCP server assigned to this step. |
| 137 | 2. If no tool is specified, return expected_output directly. |
| 138 | 3. Call the LLM to generate tool arguments from the task and prior results. |
| 139 | 4. Call the tool and return its result. |
| 140 | """ |
| 141 | server_path = self._server_paths.get(step.server) |
| 142 | if server_path is None: |
| 143 | return StepResult( |
| 144 | step_number=step.step_number, |
| 145 | task=step.task, |
| 146 | server=step.server, |
| 147 | response="", |
| 148 | error=( |
| 149 | f"Unknown server '{step.server}'. " |
| 150 | f"Registered servers: {list(self._server_paths)}" |
| 151 | ), |
| 152 | ) |
| 153 | |
| 154 | if not step.tool or step.tool.lower() in ("none", "null"): |
| 155 | return StepResult( |
| 156 | step_number=step.step_number, |
| 157 | task=step.task, |
| 158 | server=step.server, |
| 159 | response=step.expected_output, |
| 160 | tool=step.tool, |
| 161 | tool_args=step.tool_args, |
| 162 | ) |
| 163 | |
| 164 | try: |
| 165 | _log.info("Step %d: calling LLM to resolve args.", step.step_number) |
| 166 | resolved_args = await _resolve_args_with_llm( |
| 167 | question, step.task, step.tool, tool_schema, context, self._llm |
| 168 | ) |
| 169 | |
| 170 | response = await _call_tool(server_path, step.tool, resolved_args) |
| 171 | return StepResult( |
| 172 | step_number=step.step_number, |
| 173 | task=step.task, |
| 174 | server=step.server, |
| 175 | response=response, |
| 176 | tool=step.tool, |
| 177 | tool_args=resolved_args, |
| 178 | ) |
| 179 | except Exception as exc: # noqa: BLE001 |
| 180 | return StepResult( |
| 181 | step_number=step.step_number, |
| 182 | task=step.task, |
| 183 | server=step.server, |
| 184 | response="", |