Skip to content

Commit 2a1766e

Browse files
committed
fix(orchestration): remove UserInteractionAgent routing from HITL prompts
Domain agents now call request_user_clarification tool directly. The framework pauses via function_approval_request events and resumes when the user answers — no intermediary agent routing needed. - Rewrite clarification_policy to describe tool-based pause/resume - Remove QUESTION RELAY RULE and relay-based RE-INVOCATION RULE - Add explicit 'do NOT select UserInteractionAgent' warnings - Update stale comment in agent_factory.py
1 parent 456b310 commit 2a1766e

2 files changed

Lines changed: 36 additions & 45 deletions

File tree

src/backend/agents/agent_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class UnsupportedModelError(Exception):
2525

2626
# ---------------------------------------------------------------------------
2727
# Universal prompt segment for agents whose team config has user_responses=true.
28-
# Directs them to request clarification from the chat manager (who routes to
29-
# UserInteractionAgent) rather than calling ask_user directly.
28+
# Directs them to call request_user_clarification tool when they need user info.
29+
# The framework pauses automatically and resumes with the user's answer.
3030
# ---------------------------------------------------------------------------
3131

3232
_UNIVERSAL_USER_INTERACTION_PROMPT = """

src/backend/orchestration/plan_review_helpers.py

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
4545
"""
4646
if has_user_responses:
4747
clarification_policy = """
48-
USER CLARIFICATION POLICY (UserInteractionAgent is a participant):
49-
- Do NOT put UserInteractionAgent at the start of the plan to gather info.
50-
Domain agents have MCP tools that tell them EXACTLY what information they need
48+
USER CLARIFICATION POLICY (tool-based — no separate interaction agent):
49+
- Domain agents have MCP tools that tell them EXACTLY what information they need
5150
(via workflow blueprints). They know better than you what to ask.
5251
- PLAN STRUCTURE: Always start with domain agents. They will call their blueprint
53-
tools, discover what info is missing, and then REQUEST user clarification.
54-
- When a domain agent's response says it needs user information (e.g. "I need the
55-
following from the user: ..."), set is_progress_being_made=true and select
56-
**UserInteractionAgent** as next_speaker. Pass the agent's EXACT question list
57-
to UserInteractionAgent — do NOT rephrase, add to, or remove from it.
58-
- After UserInteractionAgent returns the answers, re-invoke the domain agent that
59-
requested the info so it can continue its workflow.
52+
tools, discover what info is missing, and call their request_user_clarification
53+
tool directly. The framework pauses automatically when they do this.
54+
- There is NO UserInteractionAgent. Do NOT select any agent named
55+
UserInteractionAgent — it does not exist as a participant.
56+
- When a domain agent needs user info, it calls its request_user_clarification
57+
tool. The framework handles the pause/resume cycle automatically. You do NOT
58+
need to route to any intermediary agent.
59+
- After the framework resumes (user answered), the domain agent receives the
60+
answer as the tool's return value and continues execution on its own.
6061
- Do NOT fabricate, assume, or hallucinate missing user-specific details.
61-
- Do NOT invent your own list of questions. Only relay what domain agents request.
62-
- NEVER call ask_user yourself — only UserInteractionAgent has that tool.
63-
- MagenticManager NEVER asks questions directly — it only routes between agents.
62+
- MagenticManager NEVER asks questions directly — it only routes tasks to agents.
6463
"""
6564
else:
6665
clarification_policy = """
@@ -87,9 +86,10 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
8786
Use exact agent names from the team list above. Output ONLY the JSON array — no
8887
markdown fences, no commentary before or after.
8988
90-
IMPORTANT: Do NOT include UserInteractionAgent in the initial plan. Domain agents
91-
will request user clarification during execution if they need it — the manager
92-
will then route to UserInteractionAgent at that point dynamically.
89+
IMPORTANT: There is NO UserInteractionAgent. Do NOT include any user-interaction
90+
agent in the plan. Domain agents gather user info themselves via their
91+
request_user_clarification tool — the framework pauses automatically when they
92+
call it and resumes when the user answers.
9393
9494
Example plan:
9595
[
@@ -98,7 +98,6 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
9898
{{"agent": "MagenticManager", "action": "compile a final onboarding summary for the user"}}
9999
]
100100
101-
Note: UserInteractionAgent is the ONLY agent that communicates with the user.
102101
MagenticManager NEVER asks the user questions directly. MagenticManager NEVER
103102
lists missing information or asks clarifying questions — it ONLY routes tasks.
104103
@@ -147,34 +146,26 @@ def get_magentic_prompt_kwargs(*, has_user_responses: bool = False) -> dict:
147146
- When selecting next_speaker, prefer a work agent that has NOT yet been invoked.
148147
- MagenticManager MUST NOT generate answers, ask questions, or list missing info.
149148
It only routes tasks to the appropriate agent.
150-
- If a domain agent's response indicates it needs user clarification (e.g. it says
151-
"I need the following information from the user" or "I need the user to provide X"),
152-
this IS progress — set is_progress_being_made to true and select
153-
**UserInteractionAgent** as next_speaker with a message describing what is needed.
154-
155-
RE-INVOCATION RULE (CRITICAL — PREVENTS QUESTION LOOPS):
156-
- After UserInteractionAgent returns the user's answers, you MUST re-invoke the
157-
original domain agent. Your message to that agent MUST begin with:
158-
"USER ANSWERS RECEIVED — PROCEED TO EXECUTION. Do NOT ask questions again.
159-
Here are the user's answers:"
160-
followed by the COMPLETE verbatim text of the user's answers.
161-
- This tells the domain agent to skip its question phase and go straight to
162-
calling its tools with the provided answers.
163-
- NEVER re-invoke a domain agent with a vague message like "continue" or
164-
"proceed with provisioning". Always include the full user answers.
165-
166-
QUESTION RELAY RULE (CRITICAL — DO NOT SUMMARIZE OR FILTER):
167-
- When routing to UserInteractionAgent, you MUST include the COMPLETE list of
168-
questions from the domain agent — copy them ALL verbatim.
169-
- Do NOT pick a subset. Do NOT summarize. Do NOT rephrase.
170-
- Do NOT split questions across multiple turns — send them ALL in one message.
171-
- The domain agent's question list is carefully derived from its workflow blueprint.
172-
Every item matters. Dropping questions will cause the workflow to fail.
149+
- There is NO UserInteractionAgent. Do NOT select it as next_speaker.
150+
- Domain agents that need user info will call their request_user_clarification
151+
tool. The framework handles the pause/resume automatically via
152+
function_approval_request events. You do NOT need to route to any special agent.
153+
- If a domain agent's TEXT response says it needs user information but did NOT call
154+
its tool, re-invoke the same agent with the message:
155+
"You MUST call the request_user_clarification tool with your questions.
156+
Do NOT just list them in text. Call the tool now."
157+
158+
RE-INVOCATION RULE (AFTER USER ANSWERS):
159+
- After the framework resumes from a function_approval_request (the user answered),
160+
the domain agent receives the answer automatically as the tool's return value.
161+
You do NOT need to manually relay answers. Just let the workflow continue.
162+
- If for any reason an agent needs to be re-invoked after clarification, prefix
163+
your message with: "USER ANSWERS RECEIVED — PROCEED TO EXECUTION."
173164
174165
STALL DETECTION OVERRIDE:
175-
- An agent requesting user clarification is NOT stalling. It is a valid step in
176-
the workflow. Set is_progress_being_made=true and is_in_loop=false when this
177-
happens.
166+
- An agent calling request_user_clarification is NOT stalling. The framework
167+
pauses automatically. Set is_progress_being_made=true and is_in_loop=false.
168+
- Do NOT treat a framework pause as a stall or loop.
178169
179170
COMPLETION CHECK (CRITICAL):
180171
Before setting is_request_satisfied to true, you MUST verify:

0 commit comments

Comments
 (0)