fix: preserve system message during multi-function registration in AgentBuilder#7326
Open
roli-lpci wants to merge 1 commit intomicrosoft:0.2from
Open
Conversation
…ration (microsoft#5037) AgentBuilder._build_agents() reads the system message from the static agent_configs dict on each loop iteration. Because agent_configs never mutates (it holds the raw LLM-generated config), each iteration overwrites the live agent's system message with only the latest function — destroying all previously registered function descriptions and the GROUP_CHAT_DESCRIPTION wrapper (including TERMINATE instructions). The fix reads from the live agent's .system_message property instead, which reflects all prior update_system_message() calls. This preserves: - All function descriptions across iterations - GROUP_CHAT_DESCRIPTION wrapper (TERMINATE, group chat context) - CODING_AND_TASK_SKILL_INSTRUCTION block Also extracts a local variable to eliminate 3 repeated dict lookups. Includes a regression test that exercises the actual _build_agents() code path with 3 functions assigned to one agent, verifying all descriptions and TERMINATE instruction survive. Runs without API keys. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5037.
When
AgentBuilder._build_agents()registers multiple functions to a single agent, the system message is overwritten on each iteration rather than accumulated. The loop reads from the staticagent_configsdict (which holds the raw LLM-generated config and never mutates) instead of the live agent's.system_messageproperty (which reflects priorupdate_system_message()calls).Result: After registering N functions, the agent's system message contains only the last function's description. All prior function descriptions are lost, and the
GROUP_CHAT_DESCRIPTIONwrapper — includingTERMINATEinstructions — is destroyed.Root cause
What the fix preserves
GROUP_CHAT_DESCRIPTIONwrapper (TERMINATE instruction, group chat context, member list)CODING_AND_TASK_SKILL_INSTRUCTIONblockAlso extracts
preferred_agentas a local variable, eliminating 3 repeatedself.agent_procs_assign[perferred_agent_name][0]lookups.Test plan
test_multi_function_system_message_preserved()— exercises actual_build_agents()with 3 functions assigned to one agent. 9 assertions verify all function names, descriptions, TERMINATE instruction, and GROUP_CHAT_DESCRIPTION structure are preserved. Runs without API keys (mocksconfig_list_from_jsonandbuilder_model.create).1 passed, 7 skipped(skipped tests are OpenAI-gated integration tests)🤖 Generated with Claude Code