mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix: remove redundant key normalization and defensive getattr in channel_prompts
- Remove double str() normalization in _resolve_channel_prompt since config bridging already handles numeric YAML key conversion - Remove dead prompts.get(str(key)) fallback that could never match after keys were already normalized to strings - Replace getattr(event, "channel_prompt", None) with direct attribute access since channel_prompt is a declared dataclass field - Update test to verify normalization responsibility lives in config bridging
This commit is contained in:
parent
2fbdc2c8fa
commit
90a6336145
3 changed files with 15 additions and 9 deletions
|
|
@ -2122,14 +2122,11 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||
prompts = self.config.extra.get("channel_prompts") or {}
|
||||
if not isinstance(prompts, dict):
|
||||
return None
|
||||
prompts = {str(k): v for k, v in prompts.items()}
|
||||
|
||||
for key in (channel_id, parent_id):
|
||||
if not key:
|
||||
continue
|
||||
prompt = prompts.get(key)
|
||||
if prompt is None:
|
||||
prompt = prompts.get(str(key))
|
||||
if prompt is None:
|
||||
continue
|
||||
prompt = str(prompt).strip()
|
||||
|
|
|
|||
|
|
@ -2891,7 +2891,7 @@ class GatewayRunner:
|
|||
message_type=_MT.TEXT,
|
||||
source=event.source,
|
||||
message_id=event.message_id,
|
||||
channel_prompt=getattr(event, "channel_prompt", None),
|
||||
channel_prompt=event.channel_prompt,
|
||||
)
|
||||
adapter._pending_messages[_quick_key] = queued_event
|
||||
return "Queued for the next turn."
|
||||
|
|
@ -3869,7 +3869,7 @@ class GatewayRunner:
|
|||
session_id=session_entry.session_id,
|
||||
session_key=session_key,
|
||||
event_message_id=event.message_id,
|
||||
channel_prompt=getattr(event, "channel_prompt", None),
|
||||
channel_prompt=event.channel_prompt,
|
||||
)
|
||||
|
||||
# Stop persistent typing indicator now that the agent is done
|
||||
|
|
@ -5091,7 +5091,7 @@ class GatewayRunner:
|
|||
message_type=MessageType.TEXT,
|
||||
source=source,
|
||||
raw_message=event.raw_message,
|
||||
channel_prompt=getattr(event, "channel_prompt", None),
|
||||
channel_prompt=event.channel_prompt,
|
||||
)
|
||||
|
||||
# Let the normal message handler process it
|
||||
|
|
@ -9384,7 +9384,7 @@ class GatewayRunner:
|
|||
session_key=session_key,
|
||||
_interrupt_depth=_interrupt_depth + 1,
|
||||
event_message_id=next_message_id,
|
||||
channel_prompt=getattr(pending_event, "channel_prompt", None),
|
||||
channel_prompt=pending_event.channel_prompt,
|
||||
)
|
||||
finally:
|
||||
# Stop progress sender, interrupt monitor, and notification task
|
||||
|
|
|
|||
|
|
@ -91,10 +91,19 @@ class TestResolveChannelPrompts:
|
|||
adapter.config.extra = {"channel_prompts": {"100": "Research mode"}}
|
||||
assert adapter._resolve_channel_prompt("100") == "Research mode"
|
||||
|
||||
def test_match_by_numeric_channel_id_key(self):
|
||||
def test_numeric_yaml_keys_normalized_at_config_load(self):
|
||||
"""Numeric YAML keys are normalized to strings by config bridging.
|
||||
|
||||
The resolver itself expects string keys (config.py handles normalization),
|
||||
so raw numeric keys will not match — this is intentional.
|
||||
"""
|
||||
adapter = _make_adapter()
|
||||
adapter.config.extra = {"channel_prompts": {100: "Research mode"}}
|
||||
# Simulates post-bridging state: keys are already strings
|
||||
adapter.config.extra = {"channel_prompts": {"100": "Research mode"}}
|
||||
assert adapter._resolve_channel_prompt("100") == "Research mode"
|
||||
# Pre-bridging numeric key would not match (bridging is responsible)
|
||||
adapter.config.extra = {"channel_prompts": {100: "Research mode"}}
|
||||
assert adapter._resolve_channel_prompt("100") is None
|
||||
|
||||
def test_match_by_parent_id(self):
|
||||
adapter = _make_adapter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue