feat(skills): support SystemContentBlock[] in system prompt injection#2127
Open
agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
Open
feat(skills): support SystemContentBlock[] in system prompt injection#2127agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
Conversation
The AgentSkills plugin's _on_before_invocation hook previously only handled
string system prompts. When the system prompt was set as a list of
SystemContentBlock (e.g. with cache points), the plugin would:
1. Read agent.system_prompt (which returns a concatenated string)
2. Do string manipulation to append/replace skills XML
3. Set agent.system_prompt = new_string, destroying the content block structure
This meant cache points and other non-text blocks were silently lost on
every invocation.
Changes:
- Add system_prompt_content property to Agent (public getter for
_system_prompt_content) so plugins can read the content block
representation
- Update _on_before_invocation with two codepaths:
- Content block path: when non-text blocks (cache points) are present,
filter out old skills text block and append new one, preserving
the list structure
- String path: existing behavior for simple string prompts
This matches the TypeScript SDK's implementation which already handles
SystemContentBlock[] via a two-branch design in _injectSkillsXml.
Testing:
- 3 new agent property tests (string, list, None)
- 8 new skills plugin tests covering cache point preservation,
idempotency, skills swap, string regression, all-text-blocks,
warning on missing XML, and None fallback
- 133/133 skills tests passing, 0 regressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
AgentSkillsplugin's_on_before_invocationhook only handles string system prompts. When the system prompt is set aslist[SystemContentBlock](e.g. with cache points for prompt caching), the plugin:agent.system_prompt→ gets concatenated string (cache points invisible)agent.system_prompt = new_string→ destroys content block structureThis silently drops cache points and other non-text blocks on every invocation.
Fix
Two changes, no new helper methods:
1.
Agent.system_prompt_contentproperty (agent.py)Public getter for
_system_prompt_contentso plugins can read the content block representation:2. Content block branch in
_on_before_invocation(agent_skills.py)One method, two clear codepaths:
Parity with TypeScript SDK
This matches the TypeScript implementation which already handles
SystemContentBlock[]via a two-branch design in_injectSkillsXml.Testing
system_prompt_contentproperty for string, list, and None inputs@mkmeral