mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Adds support for enterprise LLM gateways through TOML configuration files,
enabling OpenHands CLI usage in corporate environments with custom API
management solutions.
Features:
- Load gateway configuration from TOML file via --gateway-config flag
- Support for environment variable OPENHANDS_GATEWAY_CONFIG
- Environment variable expansion in config values (${ENV:VAR_NAME})
- Comprehensive example configuration file with documentation
- Clean separation from interactive setup flow
Implementation:
- Added gateway_config.py module for loading and parsing TOML configs
- Thread gateway config through CLI entry to agent initialization
- Apply gateway settings when creating LLM instance
- Update tests to handle new gateway_config_path parameter
- Remove interactive gateway setup to keep UI simple
This enables enterprise customers to configure:
- OAuth2/token authentication with identity providers
- Custom headers for routing and authorization
- Request body parameters for compliance/monitoring
- All without impacting the standard user experience
Note: Requires openhands-sdk>=1.0.0a6 once the SDK PR is merged.
Currently set to >=1.0.0a4 for compatibility.
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""Main argument parser for OpenHands CLI."""
|
|
|
|
import argparse
|
|
import os
|
|
|
|
|
|
def create_main_parser() -> argparse.ArgumentParser:
|
|
"""Create the main argument parser with CLI as default and serve as subcommand.
|
|
|
|
Returns:
|
|
The configured argument parser
|
|
"""
|
|
parser = argparse.ArgumentParser(
|
|
description='OpenHands CLI - Terminal User Interface for OpenHands AI Agent',
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
By default, OpenHands runs in CLI mode (terminal interface).
|
|
Use 'serve' subcommand to launch the GUI server instead.
|
|
|
|
Examples:
|
|
openhands # Start CLI mode
|
|
openhands --resume conversation-id # Resume a conversation in CLI mode
|
|
openhands serve # Launch GUI server
|
|
openhands serve --gpu # Launch GUI server with GPU support
|
|
"""
|
|
)
|
|
|
|
# CLI arguments at top level (default mode)
|
|
parser.add_argument(
|
|
'--resume',
|
|
type=str,
|
|
help='Conversation ID to resume'
|
|
)
|
|
|
|
parser.add_argument(
|
|
'--gateway-config',
|
|
type=str,
|
|
default=os.environ.get('OPENHANDS_GATEWAY_CONFIG'),
|
|
help='Path to enterprise gateway configuration (JSON file). Can also be set via OPENHANDS_GATEWAY_CONFIG environment variable.',
|
|
metavar='PATH'
|
|
)
|
|
|
|
# Only serve as subcommand
|
|
subparsers = parser.add_subparsers(
|
|
dest='command',
|
|
help='Additional commands'
|
|
)
|
|
|
|
# Add serve subcommand
|
|
serve_parser = subparsers.add_parser(
|
|
'serve',
|
|
help='Launch the OpenHands GUI server using Docker (web interface)'
|
|
)
|
|
serve_parser.add_argument(
|
|
'--mount-cwd',
|
|
action='store_true',
|
|
help='Mount the current working directory in the Docker container'
|
|
)
|
|
serve_parser.add_argument(
|
|
'--gpu',
|
|
action='store_true',
|
|
help='Enable GPU support in the Docker container'
|
|
)
|
|
|
|
return parser |