Skip to content

Commit 549cba0

Browse files
committed
Remove not needed context for subagent..
1 parent 357beab commit 549cba0

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

python_agent_harness/prompts.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ def load_context_files(context_dir: "Path | str | None") -> str | None:
151151
def load_task_completion_rules() -> str | None:
152152
"""Load ``prompts/task-completion-rules.txt``, or None if unavailable.
153153
154-
These rules are injected automatically into every agent system
155-
prompt (main agent, sub-agents, and session commands), so the model
156-
never stops before the task is fully completed and verified.
154+
These rules are injected automatically into the main agent and
155+
session-command system prompts, so the model never stops before the
156+
task is fully completed and verified. Sub-agents are intentionally
157+
excluded: they get ONLY their own prompt (subagent.txt) with no
158+
extra context injected.
157159
"""
158160
p = Path(__file__).parent / "prompts" / "task-completion-rules.txt"
159161
try:
@@ -177,8 +179,11 @@ def assemble_agent_prompt(
177179
context piece, immediately before the agent prompt, so they read as
178180
global ground rules rather than part of the task instructions.
179181
180-
``include_context=False`` drops the project context files (used for
181-
sub-agents, which get the rules but not the parent's context).
182+
``include_context=False`` drops the project context files (rules are
183+
still included). This function is NOT used for sub-agents: their
184+
system prompt is their own prompt file (subagent.txt) only, with no
185+
context files and no task-completion rules (see
186+
``cli.make_session`` and ``subagent._subagent_system_prompt``).
182187
``context_path`` overrides the default context directory discovery.
183188
Returns None if every part is empty/missing.
184189
"""

tests/test_context_rules.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""task-completion-rules.txt must be auto-injected into the system prompt:
22
it is the LAST context piece, immediately before the actual agent prompt —
3-
for the main agent, sub-agents, session commands, and the TUI slash path.
3+
for the main agent, session commands, and the TUI slash path. Sub-agents
4+
are excluded by design: their system prompt is subagent.txt ONLY.
45
"""
56

67
import tempfile
@@ -41,6 +42,8 @@ def test_assemble_order_context_rules_agent(self):
4142
self.assertLess(i_rules, i_agent)
4243

4344
def test_assemble_rules_before_agent_without_context(self):
45+
"""include_context=False keeps the rules (this path is NOT used
46+
for sub-agents — they get subagent.txt only)."""
4447
prompt = assemble_agent_prompt("/tmp", "AGENT PROMPT", include_context=False)
4548
self.assertLess(
4649
prompt.index("Task Completion Rules"), prompt.index("AGENT PROMPT")

tests/test_subagent.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ def test_falls_back_to_default_subagent_prompt_when_missing(self):
7474
self.assertEqual(session.client.systems, [default_sub])
7575
self.assertNotIn("MAIN AGENT PROMPT", session.client.systems[0])
7676

77+
def test_subagent_prompt_never_includes_rules_or_context(self):
78+
"""The sub-agent's system prompt is subagent.txt ONLY — no
79+
task-completion rules and no project context, even when the
80+
parent's system prompt carries both."""
81+
parent = (
82+
"Request context:\n\nIn file `/tmp/contexts/general-rules.md`:"
83+
"\n```\nGENERAL CONTEXT\n```\n\n"
84+
"Task Completion Rules\n\nMAIN AGENT PROMPT"
85+
)
86+
session = make_session(parent, None, self._tmp.name)
87+
run_subagent(session, "task", "do something")
88+
system = session.client.systems[0]
89+
self.assertNotIn("Task Completion Rules", system)
90+
self.assertNotIn("Request context:", system)
91+
self.assertNotIn("GENERAL CONTEXT", system)
92+
self.assertNotIn("MAIN AGENT PROMPT", system)
93+
7794
def test_plan_mode_reminder_prepended_but_prompt_still_subagent(self):
7895
session = make_session("MAIN", "SUB", self._tmp.name)
7996
session.plan_mode.set_mode(session.plan_mode.mode.PLAN, {

0 commit comments

Comments
 (0)