mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-26 01:01:40 +00:00
feat: unify hermes tools and hermes setup tools into single flow
Both 'hermes tools' and 'hermes setup tools' now use the same unified flow in tools_config.py: 1. Select platform (CLI, Telegram, Discord, etc.) 2. Toggle all 18 toolsets on/off in checklist 3. Newly enabled tools that need API keys → provider-aware config (e.g., TTS shows Edge/OpenAI/ElevenLabs picker) 4. Already-configured tools that stay enabled → silent, no prompts 5. Menu option: 'Reconfigure an existing tool' for updating providers or API keys on tools that are already set up Key changes: - Move TOOL_CATEGORIES, provider config, and post-setup hooks from setup.py to tools_config.py - Replace flat _check_and_prompt_requirements() with provider-aware _configure_toolset() that uses TOOL_CATEGORIES - Add _reconfigure_tool() flow for updating existing configs - setup.py's setup_tools() now delegates to tools_command() - tools_command() menu adds 'Reconfigure' option alongside platforms - Only prompt for API keys on tools that are NEWLY toggled on AND don't already have keys configured No breaking changes. All 2013 tests pass.
This commit is contained in:
parent
93dd869eab
commit
fea3a5bdcf
2 changed files with 558 additions and 437 deletions
|
|
@ -460,191 +460,9 @@ def _prompt_container_resources(config: dict):
|
|||
pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Tool Categories — category-first UX for tool configuration
|
||||
# =============================================================================
|
||||
# Each category represents a tool type. Within each category, users choose
|
||||
# a provider. This avoids showing "OpenAI Voice" and "ElevenLabs" as separate
|
||||
# tools — instead they see "Text-to-Speech" then pick a provider.
|
||||
|
||||
TOOL_CATEGORIES = [
|
||||
{
|
||||
"name": "Text-to-Speech",
|
||||
"icon": "🎤",
|
||||
"description": "Convert text to voice messages",
|
||||
"providers": [
|
||||
{
|
||||
"name": "Microsoft Edge TTS",
|
||||
"tag": "Free - no API key needed",
|
||||
"env_vars": [],
|
||||
"tts_provider": "edge",
|
||||
},
|
||||
{
|
||||
"name": "OpenAI TTS",
|
||||
"tag": "Premium - high quality voices",
|
||||
"env_vars": [
|
||||
{"key": "VOICE_TOOLS_OPENAI_KEY", "prompt": "OpenAI API key", "url": "https://platform.openai.com/api-keys"},
|
||||
],
|
||||
"tts_provider": "openai",
|
||||
},
|
||||
{
|
||||
"name": "ElevenLabs",
|
||||
"tag": "Premium - most natural voices",
|
||||
"env_vars": [
|
||||
{"key": "ELEVENLABS_API_KEY", "prompt": "ElevenLabs API key", "url": "https://elevenlabs.io/app/settings/api-keys"},
|
||||
],
|
||||
"tts_provider": "elevenlabs",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Web Search & Extract",
|
||||
"icon": "🔍",
|
||||
"description": "Search the web and extract content from URLs",
|
||||
"providers": [
|
||||
{
|
||||
"name": "Firecrawl Cloud",
|
||||
"tag": "Recommended - hosted service",
|
||||
"env_vars": [
|
||||
{"key": "FIRECRAWL_API_KEY", "prompt": "Firecrawl API key", "url": "https://firecrawl.dev"},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Firecrawl Self-Hosted",
|
||||
"tag": "Free - run your own instance",
|
||||
"env_vars": [
|
||||
{"key": "FIRECRAWL_API_URL", "prompt": "Your Firecrawl instance URL (e.g., http://localhost:3002)"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Image Generation",
|
||||
"icon": "🎨",
|
||||
"description": "Generate images from text prompts (FLUX 2 Pro + upscaling)",
|
||||
"providers": [
|
||||
{
|
||||
"name": "FAL.ai",
|
||||
"tag": "FLUX 2 Pro with auto-upscaling",
|
||||
"env_vars": [
|
||||
{"key": "FAL_KEY", "prompt": "FAL API key", "url": "https://fal.ai/dashboard/keys"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Browser Automation",
|
||||
"icon": "🌐",
|
||||
"description": "Control a cloud browser for web interactions",
|
||||
"providers": [
|
||||
{
|
||||
"name": "Browserbase",
|
||||
"tag": "Cloud browser with stealth mode",
|
||||
"env_vars": [
|
||||
{"key": "BROWSERBASE_API_KEY", "prompt": "Browserbase API key", "url": "https://browserbase.com"},
|
||||
{"key": "BROWSERBASE_PROJECT_ID", "prompt": "Browserbase project ID"},
|
||||
],
|
||||
"post_setup": "browserbase",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Smart Home",
|
||||
"icon": "🏠",
|
||||
"description": "Control Home Assistant lights, switches, and devices",
|
||||
"providers": [
|
||||
{
|
||||
"name": "Home Assistant",
|
||||
"tag": "REST API integration",
|
||||
"env_vars": [
|
||||
{"key": "HASS_TOKEN", "prompt": "Home Assistant Long-Lived Access Token"},
|
||||
{"key": "HASS_URL", "prompt": "Home Assistant URL", "default": "http://homeassistant.local:8123"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "RL Training",
|
||||
"icon": "🧪",
|
||||
"description": "Run reinforcement learning training jobs",
|
||||
"requires_python": (3, 11),
|
||||
"providers": [
|
||||
{
|
||||
"name": "Tinker / Atropos",
|
||||
"tag": "RL training platform",
|
||||
"env_vars": [
|
||||
{"key": "TINKER_API_KEY", "prompt": "Tinker API key", "url": "https://tinker-console.thinkingmachines.ai/keys"},
|
||||
{"key": "WANDB_API_KEY", "prompt": "WandB API key", "url": "https://wandb.ai/authorize"},
|
||||
],
|
||||
"post_setup": "rl_training",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "GitHub Integration",
|
||||
"icon": "🔧",
|
||||
"description": "Higher rate limits for Skills Hub + PR publishing",
|
||||
"providers": [
|
||||
{
|
||||
"name": "GitHub Personal Access Token",
|
||||
"tag": "For skill search, install, and publishing",
|
||||
"env_vars": [
|
||||
{"key": "GITHUB_TOKEN", "prompt": "GitHub Token (ghp_...)", "url": "https://github.com/settings/tokens"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _run_post_setup(post_setup_key: str):
|
||||
"""Run post-setup hooks for tools that need extra installation steps."""
|
||||
if post_setup_key == "browserbase":
|
||||
import shutil
|
||||
node_modules = PROJECT_ROOT / "node_modules" / "agent-browser"
|
||||
if not node_modules.exists() and shutil.which("npm"):
|
||||
print_info(" Installing Node.js dependencies for browser tools...")
|
||||
import subprocess
|
||||
result = subprocess.run(
|
||||
["npm", "install", "--silent"],
|
||||
capture_output=True, text=True, cwd=str(PROJECT_ROOT)
|
||||
)
|
||||
if result.returncode == 0:
|
||||
print_success(" Node.js dependencies installed")
|
||||
else:
|
||||
print_warning(" npm install failed — run manually: cd ~/.hermes/hermes-agent && npm install")
|
||||
elif not node_modules.exists():
|
||||
print_warning(" Node.js not found — browser tools require: npm install (in the hermes-agent directory)")
|
||||
|
||||
elif post_setup_key == "rl_training":
|
||||
try:
|
||||
__import__("tinker_atropos")
|
||||
except ImportError:
|
||||
tinker_dir = PROJECT_ROOT / "tinker-atropos"
|
||||
if tinker_dir.exists() and (tinker_dir / "pyproject.toml").exists():
|
||||
print_info(" Installing tinker-atropos submodule...")
|
||||
import subprocess
|
||||
import shutil
|
||||
uv_bin = shutil.which("uv")
|
||||
if uv_bin:
|
||||
result = subprocess.run(
|
||||
[uv_bin, "pip", "install", "-e", str(tinker_dir)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
else:
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "pip", "install", "-e", str(tinker_dir)],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
print_success(" tinker-atropos installed")
|
||||
else:
|
||||
print_warning(" tinker-atropos install failed — run manually:")
|
||||
print_info(' uv pip install -e "./tinker-atropos"')
|
||||
else:
|
||||
print_warning(" tinker-atropos submodule not found — run:")
|
||||
print_info(" git submodule update --init --recursive")
|
||||
print_info(' uv pip install -e "./tinker-atropos"')
|
||||
# Tool categories and provider config are now in tools_config.py (shared
|
||||
# between `hermes tools` and `hermes setup tools`).
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
|
@ -1623,187 +1441,17 @@ def setup_gateway(config: dict):
|
|||
|
||||
|
||||
# =============================================================================
|
||||
# Section 5: Tool Configuration (Category-First UX)
|
||||
# Section 5: Tool Configuration (delegates to unified tools_config.py)
|
||||
# =============================================================================
|
||||
|
||||
def setup_tools(config: dict):
|
||||
"""Configure tools with a category-first UX.
|
||||
"""Configure tools — delegates to the unified tools_command() in tools_config.py.
|
||||
|
||||
Instead of showing flat list of API keys, this shows tool categories
|
||||
(TTS, Web Search, Image Gen, etc.) and lets users pick a provider
|
||||
within each category.
|
||||
Both `hermes setup tools` and `hermes tools` use the same flow:
|
||||
platform selection → toolset toggles → provider/API key configuration.
|
||||
"""
|
||||
print_header("Tool Configuration")
|
||||
print_info("Select which tools you'd like to enable.")
|
||||
print_info("For tools with multiple providers, you'll choose one next.")
|
||||
print_info("You can always reconfigure later with 'hermes setup tools'.")
|
||||
print()
|
||||
|
||||
# Build checklist from TOOL_CATEGORIES
|
||||
# NOTE: Do NOT use color() / ANSI codes in menu labels —
|
||||
# simple_term_menu miscalculates widths and causes garbled redraws.
|
||||
checklist_labels = []
|
||||
for cat in TOOL_CATEGORIES:
|
||||
icon = cat.get("icon", "")
|
||||
name = cat["name"]
|
||||
desc = cat.get("description", "")
|
||||
|
||||
# Check if already configured — plain text only (no ANSI codes)
|
||||
configured = _is_tool_configured(cat)
|
||||
status = " [configured]" if configured else ""
|
||||
|
||||
checklist_labels.append(f"{icon} {name} - {desc}{status}")
|
||||
|
||||
# Pre-select tools that are already configured
|
||||
pre_selected = [i for i, cat in enumerate(TOOL_CATEGORIES) if _is_tool_configured(cat)]
|
||||
|
||||
selected_indices = prompt_checklist(
|
||||
"Which tools would you like to enable?",
|
||||
checklist_labels,
|
||||
pre_selected=pre_selected,
|
||||
)
|
||||
|
||||
# For each selected tool, configure its provider
|
||||
for idx in selected_indices:
|
||||
cat = TOOL_CATEGORIES[idx]
|
||||
_configure_tool_category(cat, config)
|
||||
|
||||
save_config(config)
|
||||
print()
|
||||
print_success("Tool configuration complete!")
|
||||
|
||||
|
||||
def _is_tool_configured(cat: dict) -> bool:
|
||||
"""Check if a tool category has at least one provider configured."""
|
||||
for provider in cat["providers"]:
|
||||
env_vars = provider.get("env_vars", [])
|
||||
if not env_vars:
|
||||
# No env vars needed (e.g., Edge TTS) — check if it's the active provider
|
||||
if provider.get("tts_provider"):
|
||||
from hermes_cli.config import load_config as _lc
|
||||
cfg = _lc()
|
||||
if cfg.get("tts", {}).get("provider") == provider["tts_provider"]:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
elif all(get_env_value(v["key"]) for v in env_vars):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _configure_tool_category(cat: dict, config: dict):
|
||||
"""Configure a single tool category — pick provider and enter API keys."""
|
||||
icon = cat.get("icon", "")
|
||||
name = cat["name"]
|
||||
providers = cat["providers"]
|
||||
|
||||
# Check Python version requirement
|
||||
if cat.get("requires_python"):
|
||||
req = cat["requires_python"]
|
||||
if sys.version_info < req:
|
||||
print()
|
||||
print(color(f" ─── {icon} {name} ───", Colors.CYAN))
|
||||
print_error(f" Requires Python {req[0]}.{req[1]}+ (current: {sys.version_info.major}.{sys.version_info.minor})")
|
||||
print_info(" Upgrade Python and reinstall to enable this tool.")
|
||||
return
|
||||
|
||||
if len(providers) == 1:
|
||||
# Single provider — just configure it directly
|
||||
provider = providers[0]
|
||||
print()
|
||||
print(color(f" ─── {icon} {name} ({provider['name']}) ───", Colors.CYAN))
|
||||
if provider.get("tag"):
|
||||
print_info(f" {provider['tag']}")
|
||||
_configure_provider(provider, config, cat)
|
||||
else:
|
||||
# Multiple providers — let user choose
|
||||
print()
|
||||
print(color(f" ─── {icon} {name} — Choose a provider ───", Colors.CYAN))
|
||||
print()
|
||||
|
||||
# NOTE: Do NOT use color() / ANSI codes in menu labels —
|
||||
# simple_term_menu miscalculates widths and causes garbled redraws.
|
||||
provider_choices = []
|
||||
for p in providers:
|
||||
tag = f" ({p['tag']})" if p.get("tag") else ""
|
||||
configured = ""
|
||||
env_vars = p.get("env_vars", [])
|
||||
if not env_vars or all(get_env_value(v["key"]) for v in env_vars):
|
||||
# Check TTS provider match for edge
|
||||
if p.get("tts_provider"):
|
||||
if config.get("tts", {}).get("provider") == p["tts_provider"]:
|
||||
configured = " [active]"
|
||||
elif not env_vars:
|
||||
configured = " [active]"
|
||||
else:
|
||||
configured = " [configured]"
|
||||
provider_choices.append(f"{p['name']}{tag}{configured}")
|
||||
|
||||
# Detect current provider as default
|
||||
default_provider_idx = 0
|
||||
for i, p in enumerate(providers):
|
||||
if p.get("tts_provider") and config.get("tts", {}).get("provider") == p["tts_provider"]:
|
||||
default_provider_idx = i
|
||||
break
|
||||
env_vars = p.get("env_vars", [])
|
||||
if env_vars and all(get_env_value(v["key"]) for v in env_vars):
|
||||
default_provider_idx = i
|
||||
break
|
||||
|
||||
provider_idx = prompt_choice("Select provider:", provider_choices, default_provider_idx)
|
||||
provider = providers[provider_idx]
|
||||
|
||||
_configure_provider(provider, config, cat)
|
||||
|
||||
|
||||
def _configure_provider(provider: dict, config: dict, cat: dict):
|
||||
"""Configure a single provider — prompt for API keys and set config values."""
|
||||
env_vars = provider.get("env_vars", [])
|
||||
|
||||
# Set TTS provider in config if applicable
|
||||
if provider.get("tts_provider"):
|
||||
config.setdefault("tts", {})["provider"] = provider["tts_provider"]
|
||||
|
||||
if not env_vars:
|
||||
# No API keys needed (e.g., Edge TTS)
|
||||
print_success(f" {provider['name']} — no configuration needed!")
|
||||
return
|
||||
|
||||
# Prompt for each required env var
|
||||
all_configured = True
|
||||
for var in env_vars:
|
||||
existing = get_env_value(var["key"])
|
||||
if existing:
|
||||
print_success(f" {var['key']}: already configured")
|
||||
if prompt_yes_no(f" Update {var.get('prompt', var['key'])}?", False):
|
||||
value = prompt(f" {var.get('prompt', var['key'])}", password=True)
|
||||
if value:
|
||||
save_env_value(var["key"], value)
|
||||
print_success(" Updated")
|
||||
else:
|
||||
url = var.get("url", "")
|
||||
if url:
|
||||
print_info(f" Get yours at: {url}")
|
||||
|
||||
default_val = var.get("default", "")
|
||||
if default_val:
|
||||
value = prompt(f" {var.get('prompt', var['key'])}", default_val)
|
||||
else:
|
||||
value = prompt(f" {var.get('prompt', var['key'])}", password=True)
|
||||
|
||||
if value:
|
||||
save_env_value(var["key"], value)
|
||||
print_success(f" ✓ Saved")
|
||||
else:
|
||||
print_warning(f" Skipped")
|
||||
all_configured = False
|
||||
|
||||
# Run post-setup hooks if needed
|
||||
if provider.get("post_setup") and all_configured:
|
||||
_run_post_setup(provider["post_setup"])
|
||||
|
||||
if all_configured:
|
||||
print_success(f" {provider['name']} configured!")
|
||||
from hermes_cli.tools_config import tools_command
|
||||
tools_command()
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue