mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
feat(image-gen): actionable setup message when no FAL backend is reachable (#26222)
When the in-tree FAL path has no API key (and no managed gateway), the handler used to return a bare 'FAL_KEY environment variable not set' error. Users had no idea where to get a key, that a managed Nous gateway exists, or that plugin-registered providers are an option. Now `image_generate_tool` returns a structured multi-line message: - signup link (https://fal.ai) - managed-gateway status (if Nous tools are enabled) - pointer to `hermes tools` / `hermes plugins list` for alternate backends, so users on a stale `image_gen.provider` know where to look The schema is untouched — `check_fn` still gates the tool out of the schema when no backend is reachable at startup, consistent with every other conditional tool. This patch fixes the call-time failure modes: managed-gateway 5xx, plugin provider disappearing mid-session, etc. Inspired by #2546 / @Mibayy. The PR was ~5700 commits stale against the new plugin-aware image_gen architecture, so this is a forward port of the actionable-error idea rather than a cherry-pick. Closes #2543 Co-authored-by: Mibayy <mibayy@users.noreply.github.com>
This commit is contained in:
parent
04b1fdaecf
commit
9329e06696
2 changed files with 96 additions and 4 deletions
|
|
@ -698,10 +698,7 @@ def image_generate_tool(
|
|||
raise ValueError("Prompt is required and must be a non-empty string")
|
||||
|
||||
if not (fal_key_is_configured() or _resolve_managed_fal_gateway()):
|
||||
message = "FAL_KEY environment variable not set"
|
||||
if managed_nous_tools_enabled():
|
||||
message += " and managed FAL gateway is unavailable"
|
||||
raise ValueError(message)
|
||||
raise ValueError(_build_no_backend_setup_message())
|
||||
|
||||
aspect_lc = (aspect_ratio or DEFAULT_ASPECT_RATIO).lower().strip()
|
||||
if aspect_lc not in VALID_ASPECT_RATIOS:
|
||||
|
|
@ -811,6 +808,42 @@ def check_fal_api_key() -> bool:
|
|||
return bool(fal_key_is_configured() or _resolve_managed_fal_gateway())
|
||||
|
||||
|
||||
def _build_no_backend_setup_message() -> str:
|
||||
"""Build an actionable error string when no FAL backend is reachable.
|
||||
|
||||
Used by the in-tree FAL path. Mentions:
|
||||
- FAL_KEY signup link
|
||||
- managed-gateway status (if Nous tools are enabled)
|
||||
- plugin alternative pointer (so users on a stale ``image_gen.provider``
|
||||
know the registry exists and how to inspect it)
|
||||
"""
|
||||
lines = ["Image generation is unavailable in this environment.", ""]
|
||||
lines.append("Missing requirements:")
|
||||
if managed_nous_tools_enabled():
|
||||
lines.append(
|
||||
" - FAL_KEY is not set and the managed FAL gateway is unreachable"
|
||||
)
|
||||
else:
|
||||
lines.append(" - FAL_KEY environment variable is not set")
|
||||
lines.append("")
|
||||
lines.append("To enable image generation, do one of:")
|
||||
lines.append(
|
||||
" 1. Get a free API key at https://fal.ai and set "
|
||||
"FAL_KEY=<your-key> (then restart the session)"
|
||||
)
|
||||
if managed_nous_tools_enabled():
|
||||
lines.append(
|
||||
" 2. Sign in to a Nous account that has the managed FAL "
|
||||
"gateway enabled (`hermes setup`)"
|
||||
)
|
||||
lines.append(
|
||||
" 3. Configure a different image_gen provider via `hermes tools` "
|
||||
"→ Image Generation (run `hermes plugins list` to see installed "
|
||||
"backends)"
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def check_image_generation_requirements() -> bool:
|
||||
"""True if any image gen backend is available.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue