fix: extract agent markdown body as system instruction #31
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
When loading agent
.mdfiles via_load_agent_file_metadata(), the markdown body after frontmatter was being discarded (assigned to_bodyand ignored). This body contains the agent's behavioral instructions that should be injected as the system prompt when the agent is spawned via the task tool.Fixes: microsoft/amplifier#174
Root Cause
Two issues combined to cause this bug:
_load_agent_file_metadata()discarded the body: The markdown content after frontmatter was parsed but assigned to_body(unused variable) and never stored.load_agent_metadata()was never called: The method existed butBundle.prepare()never invoked it before generating the mount plan.Impact
Agents like
smoke-testerthat rely on their markdown instructions to guide behavior (e.g., "run this exact recipe path") would receive no system prompt and fall back to generic exploration behavior, causing unpredictable results.Solution
_load_agent_file_metadata()to capture the body and store it assystem.instructionself.load_agent_metadata()inBundle.prepare()beforeto_mount_plan()Changes
amplifier_foundation/bundle.py:prepare(): Added call toself.load_agent_metadata()beforeto_mount_plan()_load_agent_file_metadata(): Changed_bodytobody, added logic to store asresult["system"] = {"instruction": body.strip()}Tests
Added 3 tests in
TestAgentMetadataLoading:test_load_agent_metadata_extracts_system_instruction- verifies body becomessystem.instructiontest_load_agent_metadata_preserves_existing_system- verifies explicit inline instructions aren't overwrittentest_load_agent_metadata_empty_body_no_system- verifies empty body doesn't create spurious instructionAll 21 tests pass.
🤖 Generated with Amplifier
Co-Authored-By: Amplifier 240397093+microsoft-amplifier@users.noreply.github.com