Repository navigation
fix(context): send a custom agent's prompt once on kas - #31875
Conversation
A KAS session is handed a custom agent's own prompt on its wire definition, and the runtime records that text in the session's native documents. The session-start [AGENT SYSTEM PROMPT] block repeated it, so the persona reached the model twice. The block is now withheld when it would repeat that recorded text word for word; any other text, and the turn after a compaction, keep it. The record is written only where KAS is known to apply the prompt: a relay kiro-cli at or above the release floor. Crew's bundled engine and an older or unreadable release record nothing, so the block stays. Part of #13305
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the dedup applies only on a relay KAS at the measured Notes
[DESIGN-REVIEWED] 6e5ea64 Description read[DESCRIPTION-READ] 9d94517a40daf329a82e1b7071cc96ee808bfcec8289c0acd1e6fff77a19d7f0 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The block is dropped only when the text matches word for word, and only on a KAS release that is known to apply the prompt. Every other case falls back to today's duplicate, never to a missing persona. What this change shipsInventory (6 items) — 4 justifiedIntent: a custom agent's persona should reach the model once per KAS session instead of twice, so tokens stop being wasted. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 6e5ea64 Description read[DESCRIPTION-READ] b5d4890e7e31138723d99b7c16b059db3ce466b80b0c7cb52892e7302fca80b4 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on 6e5ea64, no conflict, no open change request.
A KAS session is handed a custom agent's own prompt on its wire definition, and the runtime records that text in the session's native documents. The session-start [AGENT SYSTEM PROMPT] block repeated it, so the persona reached the model twice. The block is now withheld when it would repeat that recorded text word for word; any other text, and the turn after a compaction, keep it. The record is written only where KAS is known to apply the prompt: a relay kiro-cli at or above the release floor. Crew's bundled engine and an older or unreadable release record nothing, so the block stays. Part of #13305 (cherry picked from commit 568b039) Release backport: docs/architecture/context-management.md conflicted in one table row; resolved by keeping release's text and adding this change's clause. Code and tests applied unchanged. Original author: Bolin Chen (#31875).
Problem / Motivation
Goal: On KAS through kiro-cli 2.33.1 or later, a custom agent's own prompt reaches the model once at session start instead of twice.
A custom agent that sets its own persona (inline, or a
file://naming its own file) runs on KAS with that prompt on its wire definition, and Crew also opens the first turn with the same text as its[AGENT SYSTEM PROMPT]block. The model gets the persona twice.Why it matters
Every such KAS session carries a second copy of its persona for its whole life before the first compaction: context space and input tokens spent on every turn for nothing.
Not a goal
set_mode, plus a check that its sandbox can read afile://target; fix(context): send a custom agent's prompt once on kiro-cli and KAS #17172 carries that design. On kiro-cli the persona still arrives twice.{bot_name},{{MAX_SUBAGENTS}}) or a remote-workspace session's added notice. They keep the block.What changed (motivation → approach → change)
A custom agent's persona on KAS now reaches the model once instead of twice: Crew drops its own session-start copy (the
[AGENT SYSTEM PROMPT]block) when KAS already holds the identical text. The runtime already recorded the prompt it sent KAS; the prompt builder never checked that record before adding its own copy.context_assembly/turn_message.pytemplate://<agent>#promptnative document word for wordacp/runtime_session_create.pykas_agent_prompt_appliedis setacp/harness/kas.py,acp/session_handle_class.pyagent_prompt_applied: true only on a relay kiro-cli at or aboveKAS_AGENT_PROMPT_MIN_KIRO_CLI; false below it, when the release cannot be read, and on Crew's bundled enginesrc/kiro_crew/docs/agent-spec-fields.md,docs/architecture/context-management.md,docs/system-specs/modules/providers.mdCrew drops its copy only where KAS is known to apply the prompt. A KAS below kiro-cli 2.33.1 throws the prompt away, so there Crew's copy is the only one and it stays; the same goes for an unreadable release and Crew's bundled engine, which nothing has measured. The worst case is a repeat, as on main today, never a missing persona. The same record also feeds a private crewmate's essentials, so on those releases the essentials keep the persona body too.
Backwards compatibility
Compatible: every session whose harness is not known to hold the identical text still gets the block exactly as before.
Reader: src/kiro_crew/context_assembly/member.py:build_v2_essentials -- chat -- the prompt record it compares against is now absent on a KAS not known to apply the prompt, so the essentials keep the persona body there | test_the_prompt_is_recorded_as_held_only_where_kas_applies_it
Reader: src/kiro_crew/context_assembly/turn_message.py:build_message -- chat -- the block is left out only on an exact match with that record | test_the_block_stays_unless_the_harness_holds_its_exact_text
Tests
test/test_context_native_prompt_once.py: a KAS session that holds the agent's exact prompt (inline andfile://, each with a control showing the prompt resolves) gets no block and no second copy; with nothing recorded, a record for another agent, or a{bot_name}prompt, the block stays; the turn after a compaction still restores it.test/test_kas_mode_binding.py::test_the_prompt_is_recorded_as_held_only_where_kas_applies_it: through a stub KAS process, kiro-cli 2.32.0 and an unreadable release record nothing, 2.33.1 records the prompt.test/test_kas_agent_prompt_floor.py::test_only_a_relay_at_the_floor_is_taken_to_apply_the_prompt: a relay at 2.33.1 is taken to apply the prompt, and a respawn onto Crew's bundled engine clears that.-n0and 10 at-n 4 --dist loadgroup --max-worker-restart=2with sibling files, and a shuffled order (seed 15747), all green.Proof: PROVEN test/test_context_native_prompt_once.py::test_a_kas_session_handed_the_prompt_gets_no_second_copy[inline], test/test_context_native_prompt_once.py::test_a_kas_session_handed_the_prompt_gets_no_second_copy[file], test/test_kas_mode_binding.py::TestModeBinding::test_the_prompt_is_recorded_as_held_only_where_kas_applies_it[dropping-release], test/test_kas_mode_binding.py::TestModeBinding::test_the_prompt_is_recorded_as_held_only_where_kas_applies_it[unknown-release] (head 6e5ea64)
Manual verification
Not run against a live KAS. The behaviour this relies on, which KAS releases apply a custom agent's prompt, is the measured floor
KAS_AGENT_PROMPT_MIN_KIRO_CLIalready on main; the change only reads it.Screenshots / video
N/A: no user-facing surface changes.
Related Issues
Part of #13305
Builds on #17172 by @ianlenora.
Sibling sweep
Swept: git grep -n "template://" -- src/
Sibling: src/kiro_crew/context_assembly/member.py:776 -- not affected -- it reads the same record, which is now written only where KAS applies the prompt
Sibling: src/kiro_crew/context_assembly/turn.py:90 -- tracked in #13305
Sibling: src/kiro_crew/acp/harness/kiro.py:139 -- tracked in #13305
Pattern harvest
Rule candidate: review-prompt
Pattern: a dedup that withholds the only other copy must key on evidence the other channel applied it, not on a record of what was sent
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.