Next-generation shell tool. LocalShellTool will be deprecated in favor of this.
| 1214 | |
| 1215 | @dataclass |
| 1216 | class ShellTool: |
| 1217 | """Next-generation shell tool. LocalShellTool will be deprecated in favor of this.""" |
| 1218 | |
| 1219 | executor: ShellExecutor | None = None |
| 1220 | name: str = "shell" |
| 1221 | needs_approval: bool | ShellApprovalFunction = False |
| 1222 | """Whether the shell tool needs approval before execution. If True, the run will be interrupted |
| 1223 | and the tool call will need to be approved using RunState.approve() or rejected using |
| 1224 | RunState.reject() before continuing. Can be a bool (always/never needs approval) or a |
| 1225 | function that takes (run_context, action, call_id) and returns whether this specific call |
| 1226 | needs approval. |
| 1227 | """ |
| 1228 | on_approval: ShellOnApprovalFunction | None = None |
| 1229 | """Optional handler to auto-approve or reject when approval is required. |
| 1230 | If provided, it will be invoked immediately when an approval is needed. |
| 1231 | """ |
| 1232 | environment: ShellToolEnvironment | None = None |
| 1233 | """Execution environment for shell commands. |
| 1234 | |
| 1235 | If omitted, local mode is used. |
| 1236 | """ |
| 1237 | |
| 1238 | def __post_init__(self) -> None: |
| 1239 | """Validate shell tool configuration and normalize environment fields.""" |
| 1240 | normalized_environment = _normalize_shell_tool_environment(self.environment) |
| 1241 | self.environment = normalized_environment |
| 1242 | |
| 1243 | environment_type = normalized_environment["type"] |
| 1244 | if environment_type == "local": |
| 1245 | if self.executor is None: |
| 1246 | raise UserError("ShellTool with local environment requires an executor.") |
| 1247 | return |
| 1248 | |
| 1249 | if self.executor is not None: |
| 1250 | raise UserError("ShellTool with hosted environment does not accept an executor.") |
| 1251 | if self.needs_approval is not False or self.on_approval is not None: |
| 1252 | raise UserError( |
| 1253 | "ShellTool with hosted environment does not support needs_approval or on_approval." |
| 1254 | ) |
| 1255 | self.needs_approval = False |
| 1256 | self.on_approval = None |
| 1257 | |
| 1258 | @property |
| 1259 | def type(self) -> str: |
| 1260 | return "shell" |
| 1261 | |
| 1262 | |
| 1263 | @dataclass |
no outgoing calls