Suppress empty multi-agent mode messages (#33862)

## What changed

- Treat an empty custom `multi_agent_mode_hint_text` as having no instructions to emit.
- Avoid adding an empty multi-agent mode message both on the initial turn and when the configured hint changes after resuming a session.

## Testing

- Update the empty-hint integration test to assert that no mode message is sent.
- Add resume coverage that verifies changing a custom hint to an empty string emits no update.

GitOrigin-RevId: 8033292115936fac2cf22f85141278595804ee61
This commit is contained in:
Shijie Rao
2026-07-17 16:10:50 +00:00
committed by copyberry
parent e0ac6d0ec9
commit 20465d30ae
4 changed files with 74 additions and 10 deletions
@@ -12,8 +12,15 @@ pub(crate) struct MultiAgentModeInstructions {
}
impl MultiAgentModeInstructions {
pub(crate) fn new(multi_agent_mode: MultiAgentMode) -> Self {
Self { multi_agent_mode }
pub(crate) fn from_mode(multi_agent_mode: MultiAgentMode) -> Option<Self> {
if matches!(
&multi_agent_mode,
MultiAgentMode::Custom(hint_text) if hint_text.is_empty()
) {
return None;
}
Some(Self { multi_agent_mode })
}
}
+4 -2
View File
@@ -95,9 +95,11 @@ fn build_multi_agent_mode_update_item(
}
match effective_multi_agent_mode {
Some(multi_agent_mode) => Some(MultiAgentModeInstructions::new(multi_agent_mode).render()),
Some(multi_agent_mode) => MultiAgentModeInstructions::from_mode(multi_agent_mode)
.map(|instructions| instructions.render()),
None if previous.multi_agent_mode == Some(MultiAgentMode::Proactive) => {
Some(MultiAgentModeInstructions::new(MultiAgentMode::ExplicitRequestOnly).render())
MultiAgentModeInstructions::from_mode(MultiAgentMode::ExplicitRequestOnly)
.map(|instructions| instructions.render())
}
None => None,
}
+4 -4
View File
@@ -3471,10 +3471,10 @@ impl Session {
{
items.push(usage_hint_message);
}
if let Some(multi_agent_mode) = multi_agents::effective_multi_agent_mode(turn_context) {
items.push(ContextualUserFragment::into(
MultiAgentModeInstructions::new(multi_agent_mode),
));
if let Some(multi_agent_mode) = multi_agents::effective_multi_agent_mode(turn_context)
&& let Some(instructions) = MultiAgentModeInstructions::from_mode(multi_agent_mode)
{
items.push(ContextualUserFragment::into(instructions));
}
if let Some(contextual_user_message) =
crate::context_manager::updates::build_contextual_user_message(contextual_user_sections)