Skip to content

Python: preserve roles in Claude prompt history - #1

Closed
jpalvarezl wants to merge 3 commits into
mainfrom
jpalvarezl/fix/7894_claude_flatten_turn
Closed

Python: preserve roles in Claude prompt history#1
jpalvarezl wants to merge 3 commits into
mainfrom
jpalvarezl/fix/7894_claude_flatten_turn

Conversation

@jpalvarezl

@jpalvarezl jpalvarezl commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Motivation & Context

ClaudeAgent currently flattens incoming messages into a single prompt without preserving their roles. In multi-agent workflows, this makes user input and previous agents' responses indistinguishable. This change retains role information and explicitly frames the supplied transcript as conversation history for the receiving agent's assigned task.

Description & Review Guide

  • What are the major changes? Update _format_prompt() to prepend a conversation-history explanation and label each message with its role, while leaving a single user message unchanged. Add regression coverage for mixed-role history, messages from named and unnamed agents, and a single assistant message. Add a documented SequentialBuilder sample that passes a grammar inspector's output to a second Claude agent. Broaden the function_invocation_kwargs and client_kwargs annotations from dict to Mapping in the run() signatures.
  • What is the impact of these changes? Claude receives explicit role boundaries instead of undifferentiated text. The transcript is still sent as one SDK user message; this does not introduce native multi-role history replay or shared Claude sessions. Labels preserve message roles, not individual agent names. Existing single-user-message behavior remains unchanged.
  • What do you want reviewers to focus on? Whether the transcript framing clearly distinguishes supplied history from the receiving agent's instructions, whether the formatting coverage captures agent-to-agent handoff scenarios, and whether the sequential sample demonstrates the intended behavior.

Related Issue

Fixes microsoft#7894

This overlaps with microsoft#7895, which also introduces role labels. This PR additionally provides explicit conversation-history framing, broader formatting coverage, a sequential-agent sample, and the Mapping annotation updates.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue, and the overlapping open PR and differences are explained in Related Issue above.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

@jpalvarezl
jpalvarezl marked this pull request as ready for review September 7, 2026 12:38
@jpalvarezl jpalvarezl changed the title Python: preserve authors in Claude prompts Python: preserve roles in Claude prompt history Sep 7, 2026
@jpalvarezl jpalvarezl closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: ClaudeAgent flattens multi-agent conversation history into one undifferentiated user turn

1 participant