Skip to content

Python: prepend_instructions_to_messages inverts instruction order on partial dedup #8352

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions