Allow agent roles on full-history forks (#37252)

## Why

Multi-agent v2 rejected `agent_type` when `fork_turns` was `all`, forcing callers to choose between a configured role and the parent's full conversation context.

## What changed

- Apply an explicitly selected role to full-history forks, including its model and developer instructions.
- Preserve the parent's developer instructions when the selected role does not define its own.
- Keep the inherited conversation history and model-switch context intact.
- Update the `spawn_agent` schema to clarify that roles apply independently of history inheritance.

## Testing

- Cover full-history role overrides and developer-instruction precedence in multi-agent v2 tests.

GitOrigin-RevId: cd4f35e31d75f56289760f245bff38dd0233abe6
This commit is contained in:
jif authored and copyberry committed 2026-08-06 10:27:33 +00:00
1 parent 74b8f8db93
commit 82b17bc724
5 files changed
+50 -28

No files matched your search

+4 -2
View File
@@ -625,7 +625,9 @@ impl AgentControl {
.subagent_developer_instructions
.as_ref(),
) {
(MultiAgentVersion::V2, Some(_)) => {
(MultiAgentVersion::V2, override_instructions)
if override_instructions.is_some() || session_source.get_agent_role().is_some() =>
{
let parent_developer_instructions = match parent_thread
.session
.new_default_turn()
@@ -642,7 +644,7 @@ impl AgentControl {
)
}
(MultiAgentVersion::Disabled | MultiAgentVersion::V1, _)
| (MultiAgentVersion::V2, None) => (None, None),
| (MultiAgentVersion::V2, _) => (None, None),
};
let parent_history_mode = parent_thread.config_snapshot().await.history_mode;
// `record_conversation_items` only queues persistence writes asynchronously.