|
16 | 16 | from .. import __version__ |
17 | 17 | from .._run_context import AgentDepsT |
18 | 18 | from ..agent import AbstractAgent, Agent |
| 19 | +from ..builtin_tools import get_builtin_tool_types |
19 | 20 | from ..exceptions import UserError |
20 | 21 | from ..messages import ModelMessage, ModelResponse |
21 | 22 | from ..models import KnownModelName, infer_model |
|
54 | 55 |
|
55 | 56 | PROMPT_HISTORY_FILENAME = 'prompt-history.txt' |
56 | 57 |
|
| 58 | +# CLI-supported tool IDs (excludes deprecated and config-requiring tools) |
| 59 | +_CLI_TOOL_IDS = sorted( |
| 60 | + k.kind |
| 61 | + for k in get_builtin_tool_types() |
| 62 | + if k not in {'mcp_server', 'memory', 'unknown_builtin_tool'} |
| 63 | +) |
| 64 | + |
57 | 65 |
|
58 | 66 | class SimpleCodeBlock(CodeBlock): |
59 | 67 | """Customized code blocks in markdown. |
@@ -174,54 +182,56 @@ def cli( # noqa: C901 |
174 | 182 | parser.add_argument('--no-stream', action='store_true', help='Disable streaming from the model') |
175 | 183 | parser.add_argument('--version', action='store_true', help='Show version and exit') |
176 | 184 |
|
177 | | - if prog_name == 'clai': |
178 | | - subparsers = parser.add_subparsers(dest='command', help='Available commands') |
| 185 | + subparsers = parser.add_subparsers(dest='command', help='Available commands') |
179 | 186 |
|
180 | | - web_parser = subparsers.add_parser( |
181 | | - 'web', |
182 | | - help='Launch web chat UI for an agent', |
183 | | - description='Start a web-based chat interface for the specified agent', |
184 | | - ) |
185 | | - web_parser.add_argument( |
186 | | - '--agent', |
187 | | - '-a', |
188 | | - help='Agent to serve, in format "module:variable" (e.g., "mymodule:agent"). ' |
189 | | - 'If omitted, creates a generic agent with the first specified model as default.', |
190 | | - ) |
191 | | - web_parser.add_argument( |
192 | | - '-m', |
193 | | - '--model', |
194 | | - action='append', |
195 | | - dest='models', |
196 | | - help='Model to make available (can be repeated, e.g., -m openai:gpt-5 -m anthropic:claude-sonnet-4-5). ' |
197 | | - 'Format: "provider:model_name". Prefix-less names (gpt-5, claude-sonnet-4-5, gemini-2.5-pro) ' |
198 | | - 'auto-infer provider. First model is preselected in UI; additional models appear as options.', |
199 | | - ) |
200 | | - web_parser.add_argument( |
201 | | - '-t', |
202 | | - '--tool', |
203 | | - action='append', |
204 | | - dest='tools', |
205 | | - help='Builtin tool to enable (can be repeated, e.g., -t web_search -t code_execution). ' |
206 | | - 'Available: web_search, code_execution, image_generation, web_fetch.', |
207 | | - ) |
208 | | - web_parser.add_argument( |
209 | | - '-i', |
210 | | - '--instructions', |
211 | | - help='System instructions for the agent. Only applies when --agent is not specified (generic agent mode).', |
212 | | - ) |
213 | | - web_parser.add_argument('--host', default='127.0.0.1', help='Host to bind server (default: 127.0.0.1)') |
214 | | - web_parser.add_argument('--port', type=int, default=7932, help='Port to bind server (default: 7932)') |
215 | | - web_parser.add_argument( |
216 | | - '--mcp', |
217 | | - help='Path to JSON file with MCP server configurations. ' |
218 | | - 'Format: {"mcpServers": {"id": {"url": "...", "authorizationToken": "..."}}}', |
219 | | - ) |
| 187 | + web_parser = subparsers.add_parser( |
| 188 | + 'web', |
| 189 | + help='Launch web chat UI for an agent', |
| 190 | + description='Start a web-based chat interface for the specified agent', |
| 191 | + ) |
| 192 | + web_parser.add_argument( |
| 193 | + '--agent', |
| 194 | + '-a', |
| 195 | + help='Agent to serve, in format "module:variable" (e.g., "mymodule:agent"). ' |
| 196 | + 'If omitted, creates a generic agent with the first specified model as default.', |
| 197 | + ) |
| 198 | + web_parser.add_argument( |
| 199 | + '-m', |
| 200 | + '--model', |
| 201 | + choices=KnownModelName.__value__.__args__, |
| 202 | + action='append', |
| 203 | + dest='models', |
| 204 | + help='Model to make available (can be repeated, e.g., -m openai:gpt-5 -m anthropic:claude-sonnet-4-5). ' |
| 205 | + 'Format: "provider:model_name". First model is preselected in UI; additional models appear as options.', |
| 206 | + ) |
| 207 | + web_parser.add_argument( |
| 208 | + '-t', |
| 209 | + '--tool', |
| 210 | + choices=_CLI_TOOL_IDS, |
| 211 | + action='append', |
| 212 | + dest='tools', |
| 213 | + help=f'Builtin tool to enable (can be repeated, e.g., -t web_search -t code_execution). ' |
| 214 | + f'Available: {", ".join(_CLI_TOOL_IDS)}.', |
| 215 | + ) |
| 216 | + |
| 217 | + web_parser.add_argument( |
| 218 | + '-i', |
| 219 | + '--instructions', |
| 220 | + help='System instructions for the agent. In generic mode (no --agent), these are the agent instructions. ' |
| 221 | + 'With --agent, these are passed as extra instructions to each run.', |
| 222 | + ) |
| 223 | + web_parser.add_argument('--host', default='127.0.0.1', help='Host to bind server (default: 127.0.0.1)') |
| 224 | + web_parser.add_argument('--port', type=int, default=7932, help='Port to bind server (default: 7932)') |
| 225 | + web_parser.add_argument( |
| 226 | + '--mcp', |
| 227 | + help='Path to JSON file with MCP server configurations. ' |
| 228 | + 'Format: {"mcpServers": {"id": {"url": "...", "headers": {...}}}}', |
| 229 | + ) |
220 | 230 |
|
221 | 231 | argcomplete.autocomplete(parser) |
222 | 232 | args = parser.parse_args(args_list) |
223 | 233 |
|
224 | | - if prog_name == 'clai' and getattr(args, 'command', None) == 'web': |
| 234 | + if args.command == 'web': |
225 | 235 | from .web import run_web_command |
226 | 236 |
|
227 | 237 | return run_web_command( |
|
0 commit comments