Description
prepend_instructions_to_messages() in agent_framework/_types.py inverts instruction order when only part of the instruction list is already present as leading messages. The dedup added in #5051 prepends the non-matching remainder in front of the matched instructions, reordering the system prompt silently.
Reproduction
from agent_framework._types import Message, prepend_instructions_to_messages
msgs = [Message(role="system", contents=["First"])]
out = prepend_instructions_to_messages(msgs, ["First", "Second"])
# instruction order in output: ['Second', 'First'] <-- inverted
Expected ['First', 'Second'] — instruction sequence order must be preserved regardless of how much is already present.
Environment
agent-framework python main, Python 3.12
Description
prepend_instructions_to_messages()inagent_framework/_types.pyinverts instruction order when only part of the instruction list is already present as leading messages. The dedup added in #5051 prepends the non-matching remainder in front of the matched instructions, reordering the system prompt silently.Reproduction
Expected
['First', 'Second']— instruction sequence order must be preserved regardless of how much is already present.Environment
agent-framework python main, Python 3.12