fix(agent): append tool-policy boundary after the cacheable prompt prefix - #5752
fix(agent): append tool-policy boundary after the cacheable prompt prefix#5752gac0812 wants to merge 2 commits into
Conversation
…efix The session-varying Tool Policy Boundary was prepended to the system prompt, so the first diverging byte sat at offset 0 and the inference backend could not reuse the stable prefix (safety preamble, tool catalogue, workspace). Append it instead, matching DateTimeSection placement. Closes tinyhumansai#5704.
How this change flows2 changed behaviours across 14 relationships. 5 surrounding behaviours are shown (60 graph nodes walked). 39 further behaviours left out to keep the diagram readable. flowchart LR
n0["make_agent_with_builder_and_dispatcher<br/>changed"]:::changed
n1["system_prompt_includes_tool_policy_boundary<br/>changed"]:::changed
n2["vec"]:::impacted
n3["make_agent_with_builder"]:::impacted
n4["openhuman"]:::impacted
n5["AgentConfig"]:::impacted
n6["ContextConfig"]:::impacted
n0 -->|uses| n4
n0 -->|uses| n5
n0 -->|uses| n6
n1 -->|calls| n2
n1 -->|tests| n2
n1 -->|calls| n3
n1 -->|tests| n3
n1 -->|uses| n4
n1 -->|uses| n5
n1 -->|uses| n6
n3 -->|calls| n0
n3 -->|uses| n4
n3 -->|uses| n5
n3 -->|uses| n6
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Green: changed behaviour. Grey: surrounding behaviour. Arrows name the call, use, implementation, or test relationship. Orange: has findings. Red: has a finding that blocks the merge. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe system prompt now appends the rendered tool-policy boundary after stable sections. Tests verify its position and final-section status. Test memory hosts, proxy test isolation, and integration documentation were updated. ChangesTool policy prompt ordering
Runtime proxy test isolation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR moves the session-varying tool-policy block to the end of the system prompt while preserving its contents and restricted-session behavior; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The implementation changes tool-policy boundary placement from prepending to appending, preserving the stable prompt prefix and agent persona at the beginning as required by issue Warning Your free Security trial is over. An organization admin can activate billing to continue. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Feature-Gate Smoke injects HTTP_PROXY into the job. apply_env_overrides() re-overlays ProcessEnv, which can wipe the fixture URL, fail validate(), and force enabled=false before set_runtime_proxy_config. Drive the same commit path from an empty HashMapEnv instead.
|
Thanks for this, @gac0812 — closing in favour of #5821 for #5704, with two pieces here that should come back as their own PRs. Why #5821: it's Please do re-file these two, separately:
Both are real work and neither is in #5821. Bundling them is the only reason this one is being closed rather than merged. |
Summary
## Tool Policy Boundaryblock after the assembled system prompt, instead of prepending it.DateTimeSectionconvention: volatile content belongs at the tail, not at offset 0.Problem
build_system_promptprependedrender_tool_policy_boundary(...)in front of the fully assembled system prompt. That block is session-scoped (agent, channel, entrypoint, allowed tools). Putting it first moves the first diverging byte to offset 0 and defeats prefix caching for everything behind it. It also made every restricted agent open with the same heading instead of its persona.Tracked in #5704. No existing open PR covers this.
Solution
Change the join from
{boundary}\n\n{prompt}to{prompt}\n\n{boundary}. The model still sees the full boundary; only placement changes. The test helpermake_agent_with_builder_and_dispatchernow callsinstall_for_tests()so the existing prompt test can run in isolation (same seam wiring asmake_agent).Submission Checklist
make_agentalready used## Related— N/A: no coverage-matrix feature IDdocs/RELEASE-MANUAL-SMOKE.md) — N/A: prompt assembly onlyCloses #NNNin the## RelatedsectionImpact
Related
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
fix/tool-policy-boundary-prefix-cache268eb8a5113975f8e9f8ad70d80b8592dcfcaa74Validation Run
pnpm --filter openhuman-app format:check— N/A: Rust-only changepnpm typecheck— N/A: Rust-only changecargo test --lib openhuman::agent::harness::session::turn::tests::system_prompt_includes_tool_policy_boundary -- --exact(pass); siblingset_agent_definition_name_refreshes_tool_policy_identity(pass)cargo fmton the touched filesValidation Blocked
command:N/Aerror:N/Aimpact:N/ABehavior Changes
Parity Contract
Nonewhen there are no restrictionsDuplicate / Superseded PR Handling
Summary by CodeRabbit
Improvements
Documentation