3131# Prompt kwargs builder
3232# ---------------------------------------------------------------------------
3333
34- def get_magentic_prompt_kwargs (* , has_user_responses : bool = False ) -> dict :
34+ def get_magentic_prompt_kwargs (
35+ * ,
36+ has_user_responses : bool = False ,
37+ participant_names : Optional [list [str ]] = None ,
38+ ) -> dict :
3539 """Build the prompt-override kwargs dict for ``MagenticBuilder``.
3640
3741 Args:
3842 has_user_responses: Whether any agent has ``user_responses: true``,
3943 giving it access to the ``ask_user`` tool for user clarification.
4044 When True, prompts allow agents to gather info via their tools;
4145 when False, agents must use defaults only.
46+ participant_names: Names of the team's participant agents. When provided,
47+ the orchestrator plan prompt is augmented with a MANDATORY AGENTS
48+ clause requiring every one of these agents to appear as a plan step,
49+ so coordinator-like agents (e.g. TriageAgent) and final-validation
50+ agents (e.g. ComplianceAgent) are not silently dropped.
4251
4352 Returns:
4453 A dict suitable for unpacking into ``MagenticBuilder(**kwargs)``.
@@ -70,12 +79,26 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
7079- Ask EXACTLY 0 questions. Always proceed with sensible defaults.
7180"""
7281
82+ mandatory_block = ""
83+ if participant_names :
84+ agent_lines = "\n " .join (f"- { name } " for name in participant_names )
85+ mandatory_block = (
86+ "\n \n MANDATORY AGENTS (CRITICAL — NON-NEGOTIABLE):\n "
87+ "Every plan you generate MUST include EVERY ONE of the following agents,\n "
88+ "each as its own distinct step, each invoked at least once:\n "
89+ + agent_lines
90+ + "\n Do NOT omit any of these agents, even if a step seems optional,\n "
91+ "redundant, already covered by another agent, or something you "
92+ "(MagenticManager)\n could do yourself. A plan missing any listed agent "
93+ "is INVALID — regenerate it\n until every listed agent appears as a step.\n "
94+ )
95+
7396 plan_append = """
7497
7598PLAN RULES:
7699- Steps are HIGH-LEVEL task assignments — one step per agent. Do NOT prescribe
77100 sub-tasks, parameters, or data retrieval. Agents discover their own processes.
78- """ + clarification_policy + """
101+ """ + mandatory_block + clarification_policy + """
79102OUTPUT FORMAT (CRITICAL — use EXACTLY this JSON structure, nothing else):
80103```json
81104[
@@ -86,11 +109,14 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
86109Use exact agent names from the team list above. Output ONLY the JSON array — no
87110markdown fences, no commentary before or after.
88111
89- IMPORTANT: There is NO UserInteractionAgent. Do NOT include any user-interaction
112+ """ + ( """ IMPORTANT: There is NO UserInteractionAgent. Do NOT include any user-interaction
90113agent in the plan. Domain agents gather user info themselves via their
91114request_user_clarification tool — the framework pauses automatically when they
92115call it and resumes when the user answers.
93-
116+ """ if has_user_responses else """IMPORTANT: There is NO UserInteractionAgent. Do NOT include any user-interaction
117+ agent in the plan. Agents apply sensible defaults for missing details and proceed
118+ without asking the user any questions.
119+ """ ) + """
94120Example plan:
95121[
96122 {{"agent": "HRHelperAgent", "action": "execute the onboarding process for the new employee"}},
@@ -143,12 +169,42 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
143169 ORCHESTRATOR_TASK_LEDGER_FACTS_PROMPT + facts_append
144170 )
145171
146- progress_append = """
172+ # Completion-enforcement progress-ledger rules. Applied ALWAYS (not only when
173+ # has_user_responses) so that EVERY plan-step agent — e.g. TriageAgent and
174+ # ComplianceAgent in the content_gen team, whose agents all have
175+ # user_responses=false — must actually run before the request can be marked
176+ # satisfied, and the orchestrator re-selects any uninvoked plan-step agent
177+ # instead of silently finishing early.
178+ progress_append = """
147179
148180EXECUTION RULES:
149181- When selecting next_speaker, prefer a work agent that has NOT yet been invoked.
150- - MagenticManager MUST NOT generate answers, ask questions, or list missing info.
151- It only routes tasks to the appropriate agent.
182+ - MagenticManager MUST NOT generate answers or fabricate content on behalf of
183+ work agents. It only routes tasks and compiles the final output.
184+
185+ COMPLETION CHECK (CRITICAL):
186+ Before setting is_request_satisfied to true, you MUST verify:
187+ 1. Review the conversation history and list every agent that has actually produced
188+ a substantive response (meaningful output — calling tools and returning results
189+ where the agent has tools, or producing a substantive text response otherwise).
190+ 2. Compare that list against the plan steps. If ANY plan-step agent has NOT been
191+ invoked and produced a substantive response, set is_request_satisfied to false
192+ and select the next uninvoked agent as next_speaker.
193+ 3. is_request_satisfied = true ONLY when ALL plan-step agents have completed
194+ their work (produced a substantive response — tool results, or meaningful text
195+ output for agents that have no tools).
196+ - Each agent handles a DISTINCT domain. One agent's output does NOT satisfy
197+ another agent's step.
198+ - Do NOT re-invoke an agent that already completed its step successfully.
199+ - IGNORE agent-level completion language (e.g. "all steps are complete",
200+ "onboarding is done"). An individual agent only knows about its own domain.
201+ The workflow is NOT complete until every plan-step agent has been invoked."""
202+
203+ if has_user_responses :
204+ progress_append += """
205+
206+ USER-CLARIFICATION EXECUTION RULES:
207+ - MagenticManager MUST NOT ask questions or list missing info — it only routes.
152208- There is NO UserInteractionAgent. Do NOT select it as next_speaker.
153209- Domain agents that need user info will call their request_user_clarification
154210 tool. The framework handles the pause/resume automatically via
@@ -168,26 +224,11 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
168224STALL DETECTION OVERRIDE:
169225- An agent calling request_user_clarification is NOT stalling. The framework
170226 pauses automatically. Set is_progress_being_made=true and is_in_loop=false.
171- - Do NOT treat a framework pause as a stall or loop.
227+ - Do NOT treat a framework pause as a stall or loop."""
172228
173- COMPLETION CHECK (CRITICAL):
174- Before setting is_request_satisfied to true, you MUST verify:
175- 1. Review the conversation history and list every agent that has actually produced
176- a substantive response (called tools and returned results).
177- 2. Compare that list against the plan steps. If ANY plan-step agent has NOT been
178- invoked and produced a substantive response, set is_request_satisfied to false
179- and select the next uninvoked agent as next_speaker.
180- 3. is_request_satisfied = true ONLY when ALL plan-step agents have completed
181- their work successfully (called their tools, returned results).
182- - Each agent handles a DISTINCT domain. One agent's output does NOT satisfy
183- another agent's step.
184- - Do NOT re-invoke an agent that already completed its step successfully.
185- - IGNORE agent-level completion language (e.g. "all steps are complete",
186- "onboarding is done"). An individual agent only knows about its own domain.
187- The workflow is NOT complete until every plan-step agent has been invoked."""
188- kwargs ["progress_ledger_prompt" ] = (
189- ORCHESTRATOR_PROGRESS_LEDGER_PROMPT + progress_append
190- )
229+ kwargs ["progress_ledger_prompt" ] = (
230+ ORCHESTRATOR_PROGRESS_LEDGER_PROMPT + progress_append
231+ )
191232
192233 return kwargs
193234
0 commit comments