Repository navigation
Description
Bug Description
The CLI crashes immediately on launch with an UnboundLocalError when the agent is not fully initialized before show_banner() runs. This prevents any use of the CLI with custom providers (e.g. Z.AI).
Environment
- Hermes: v0.6.0 (latest via
hermes update, March 31 2026) - OS: Ubuntu 24.04 (N95 Mini PC)
- Provider: Z.AI (custom
base_urlin config.yaml) - Model: glm-5
- Python: 3.11.14
Root Cause
In show_banner() (cli.py ~line 2179), ctx_len is assigned inside an else block:
else:
# ...
ctx_len = None
if hasattr(self, 'agent') and self.agent and hasattr(self.agent, 'context_compressor'):
ctx_len = self.agent.context_compressor.context_lengthBut it's referenced outside the if/else, after both branches (~line 2198):
# Warn about very low context lengths (common with local servers)
if ctx_len and ctx_len <= 8192:When the if branch executes (compact banner, or agent not yet initialized), ctx_len is never set, and the post-branch check crashes with UnboundLocalError.
It also appears on line 2191 where context_length=ctx_len is passed to build_welcome_banner() — same scoping issue.
Steps to Reproduce
-
Configure a custom provider with base_url in ~/.hermes/config.yaml:
model:
default: glm-5
provider: zai
base_url: https://api.z.ai/api/coding/paas/v4 -
Launch the CLI:
hermes -
CLI crashes before reaching the input prompt.
Expected Behavior
CLI launches normally. If context length cannot be detected for a
custom provider, ctx_len should default to None and the low-context
warning should be silently skipped.
Actual Behavior
Banner partially renders (model name, tools, provider line visible),
then crashes with UnboundLocalError: cannot access local variable
'ctx_len' before the input prompt appears. CLI is completely unusable.
Affected Component
CLI (interactive chat)
Messaging Platform (if gateway-related)
N/A (CLI only)
Operating System
Ubuntu 24.04
Python Version
3.11.14
Hermes Version
0.6.0
Relevant Logs / Traceback
Traceback (most recent call last):
File "/home/steve/.local/bin/hermes", line 10, in <module>
sys.exit(main())
File "/home/steve/.hermes/hermes-agent/hermes_cli/main.py", line 5035, in main
cmd_chat(args)
File "/home/steve/.hermes/hermes-agent/hermes_cli/main.py", line 652, in cmd_chat
cli_main(**kwargs)
File "/home/steve/.hermes/hermes-agent/cli.py", line 7898, in main
cli.run()
File "/home/steve/.hermes/hermes-agent/cli.py", line 6343, in run
self.show_banner()
File "/home/steve/.hermes/hermes-agent/cli.py", line 2198, in show_banner
if ctx_len and ctx_len <= 8192:
^^^^^^^^^
UnboundLocalError: cannot access local variable 'ctx_len' where it is not associated with a valueRoot Cause Analysis (optional)
No response
Proposed Fix (optional)
Move ctx_len = None above the if/else so it's always in scope:
ctx_len = None # Initialize before branching
if use_compact:
self.console.print(_build_compact_banner())
self._show_status()
else:
# ...
if hasattr(self, 'agent') and self.agent and hasattr(self.agent, 'context_compressor'):
ctx_len = self.agent.context_compressor.context_lengthOne-line fix. Happy to open a PR if preferred.
Related
- [Bug]: Custom providers lack context length auto-detection when saved via /model command #2513 — context length detection for custom providers (related but different; that's about missing UI feedback, this is a hard crash)
- feat: auto-detect and display context length for custom providers #2513 #2514, fix(cli): auto-detect context length for custom providers when not specified #2522 — open PRs for context length UX (don't address the
UnboundLocalError)
Are you willing to submit a PR for this?
- I'd like to fix this myself and submit a PR
Activity
steve-goldberg commentedon Apr 9, 2026
Fixed