Skip to content

The agent that grows with you

fix(agent): scope kanban guidance to worker tasks

KoNit-K1d5024bbe80f
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 5454570e120..9eab1eb5e3d 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1077,10 +1077,13 @@ def _load_tools(agent, enabled_toolsets, disabled_toolsets):
)
agent.valid_tool_names = {tool["function"]["name"] for tool in agent.tools} if agent.tools else set()
- # Kanban guidance is session-static (kanban_show iff HERMES_KANBAN_TASK); resolve once.
+ # Kanban guidance is session-static for dispatcher workers only. Profiles may
+ # expose kanban_show interactively without owning a task.
from agent.prompt_builder import KANBAN_GUIDANCE
agent._kanban_worker_guidance = (
- KANBAN_GUIDANCE if "kanban_show" in agent.valid_tool_names else ""
+ KANBAN_GUIDANCE
+ if os.environ.get("HERMES_KANBAN_TASK") and "kanban_show" in agent.valid_tool_names
+ else ""
)
if agent.quiet_mode:
return
diff --git a/agent/system_prompt.py b/agent/system_prompt.py
index f660e3b7de1..2f4cf7b7519 100644
--- a/agent/system_prompt.py
+++ b/agent/system_prompt.py
@@ -283,9 +283,9 @@ def _tool_guidance_block(agent: Any) -> Optional[str]:
skill_manage_available="skill_manage" in names,
)
# Kanban lifecycle: resolved once at __init__ (_kanban_worker_guidance);
- # the kanban_show fallback covers code paths that bypass agent_init.
+ # fallback paths must also limit task protocol guidance to dispatcher workers.
_kanban_guidance = getattr(agent, "_kanban_worker_guidance", None)
- if _kanban_guidance is None and "kanban_show" in names:
+ if _kanban_guidance is None and os.environ.get("HERMES_KANBAN_TASK") and "kanban_show" in names:
_kanban_guidance = KANBAN_GUIDANCE
tool_guidance = [
memory_guidance,
diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py
index 0618ddf1cad..3322eef0149 100644
--- a/tests/agent/test_system_prompt.py
+++ b/tests/agent/test_system_prompt.py
@@ -57,6 +57,46 @@ def _captured_context_cwd(agent):
return captured["cwd"]
[email protected]("task_id, expected", [(None, False), ("t_worker", True)])
+def test_kanban_guidance_requires_worker_task_at_agent_init(monkeypatch, task_id, expected):
+ """A profile can expose kanban tools without making the session a worker."""
+ from agent.agent_init import _load_tools
+ from agent.prompt_builder import KANBAN_GUIDANCE
+ import model_tools
+
+ if task_id is None:
+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
+ else:
+ monkeypatch.setenv("HERMES_KANBAN_TASK", task_id)
+ monkeypatch.setattr("hermes_cli.plugins.discover_plugins", lambda: None)
+ monkeypatch.setattr(
+ model_tools,
+ "get_tool_definitions",
+ lambda **_kwargs: [{"function": {"name": "kanban_show"}}],
+ )
+ agent = SimpleNamespace(quiet_mode=True)
+
+ _load_tools(agent, enabled_toolsets=["kanban"], disabled_toolsets=None)
+
+ assert (agent._kanban_worker_guidance == KANBAN_GUIDANCE) is expected
+
+
[email protected]("task_id, expected", [(None, False), ("t_worker", True)])
+def test_kanban_guidance_fallback_requires_worker_task(monkeypatch, task_id, expected):
+ """Prompt fallback preserves the worker boundary when init was bypassed."""
+ from agent.prompt_builder import KANBAN_GUIDANCE
+ from agent.system_prompt import _tool_guidance_block
+
+ if task_id is None:
+ monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)
+ else:
+ monkeypatch.setenv("HERMES_KANBAN_TASK", task_id)
+ agent = _make_agent(valid_tool_names={"kanban_show"})
+ delattr(agent, "_kanban_worker_guidance")
+
+ assert (_tool_guidance_block(agent) == KANBAN_GUIDANCE) is expected
+
+
@pytest.mark.parametrize("stores", [(True, True), (False, True), (True, False), (False, False)])
@pytest.mark.parametrize("names", [
set(), {"memory"}, {"memory", "skill_view", "skills_list"},
@@ -834,4 +874,3 @@ class TestConversationStartedTwoLine:
vol = self._volatile(agent)
assert "Conversation started:" not in vol
assert "as of the last context rebuild" not in vol
-