pull/709/head
harshalmore31 7 months ago
parent f23321487f
commit 9904c45630

@ -75,7 +75,7 @@ def load_prompts_from_json() -> Dict[str, str]:
if not isinstance(details, dict) or "system_prompt" not in details: if not isinstance(details, dict) or "system_prompt" not in details:
continue continue
prompts[f"agent.{agent_name}"] = details["system_prompt"] prompts[f"agent-{agent_name}"] = details["system_prompt"]
if not prompts: if not prompts:
# Load default prompts # Load default prompts
@ -504,7 +504,10 @@ def create_app():
) )
async def run_task_wrapper(task, max_loops, dynamic_temp, swarm_type, agent_prompt_selector, flow_text): async def run_task_wrapper(task, max_loops, dynamic_temp, swarm_type, agent_prompt_selector, flow_text):
"""Execute the task and update the UI with progress.""" """
Execute the task and update the UI with progress, saving the raw AgentRearrange response
and parsing it for display.
"""
try: try:
if not task: if not task:
yield "Please provide a task description.", "Error: Missing task" yield "Please provide a task description.", "Error: Missing task"
@ -514,7 +517,6 @@ def create_app():
yield "Please select at least one agent.", "Error: No agents selected" yield "Please select at least one agent.", "Error: No agents selected"
return return
# Update status # Update status
yield "Processing...", "Running task..." yield "Processing...", "Running task..."
@ -526,7 +528,7 @@ def create_app():
return return
flow = flow_text flow = flow_text
# Execute task # Execute the task
result, router, error = await execute_task( result, router, error = await execute_task(
task=task, task=task,
max_loops=max_loops, max_loops=max_loops,
@ -540,33 +542,73 @@ def create_app():
yield f"Error: {error}", "Error occurred" yield f"Error: {error}", "Error occurred"
return return
# Format output based on swarm type # Process result based on swarm type
output_lines = []
if swarm_type == "SpreadSheetSwarm":
output_lines.append(f"### Spreadsheet Output ###\n{result}\n{'=' * 50}\n")
elif isinstance(result, dict): # checking if result is dict or string.
if swarm_type == "AgentRearrange": if swarm_type == "AgentRearrange":
for key, value in result.items(): # Store raw response in a temporary JSON file
output_lines.append(f"### Step {key} ###\n{value}\n{'=' * 50}\n") temp_json_path = "temp_agent_rearrange.json"
elif swarm_type == "MixtureOfAgents": with open(temp_json_path, "w", encoding="utf-8") as temp_file:
# Add individual agent outputs json.dump(result, temp_file, indent=4)
for key, value in result.items():
if key != "Aggregated Summary": # Read from the temporary JSON file
output_lines.append(f"### {key} ###\n{value}\n") with open(temp_json_path, "r", encoding="utf-8") as temp_file:
# Add aggregated summary at the end temp_json = json.load(temp_file)
if "Aggregated Summary" in result:
output_lines.append(f"\n### Aggregated Summary ###\n{result['Aggregated Summary']}\n{'=' * 50}\n") # Parse and format the JSON output
else: # SequentialWorkflow, ConcurrentWorkflow, Auto formatted_output = parse_agent_rearrange_output(temp_json)
yield formatted_output, "Completed"
return
# Generic processing for other swarm types
output_lines = []
if isinstance(result, dict): # For JSON-like outputs
for key, value in result.items(): for key, value in result.items():
output_lines.append(f"### {key} ###\n{value}\n{'=' * 50}\n") output_lines.append(f"### {key} ###\n{value}\n{'=' * 50}\n")
elif isinstance(result, str): elif isinstance(result, str):
output_lines.append(str(result)) output_lines.append(result)
yield "\n".join(output_lines), "Completed" yield "\n".join(output_lines), "Completed"
except Exception as e: except Exception as e:
yield f"Error: {str(e)}", "Error occurred" yield f"Error: {str(e)}", "Error occurred"
def parse_agent_rearrange_output(raw_json: dict) -> str:
"""
Parse the AgentRearrange JSON output and format it for display.
"""
output_lines = []
# Input Section
input_data = raw_json.get("input", {})
swarm_id = input_data.get("swarm_id", "N/A")
swarm_name = input_data.get("name", "N/A")
flow = input_data.get("flow", "N/A")
output_lines.append(f"### Swarm ID: {swarm_id} ###")
output_lines.append(f"### Swarm Name: {swarm_name} ###")
output_lines.append(f"### Flow: {flow} ###")
# Outputs Section
outputs = raw_json.get("outputs", [])
for i, agent_output in enumerate(outputs, start=1):
agent_name = agent_output.get("agent_name", "N/A")
task = agent_output.get("task", "N/A")
output_lines.append(f"\n#### Agent: {agent_name} (Step {i}) ####")
output_lines.append(f"Task: {task}")
# Steps Section
steps = agent_output.get("steps", [])
for step_idx, step in enumerate(steps, start=1):
role = step.get("role", "N/A")
content = step.get("content", "N/A")
output_lines.append(f" - **Loop 1: Role:** {role} **Content:** {content}")
output_lines.append(f"{'=' * 30}\n")
return "\n".join(output_lines)
# Connect the update functions # Connect the update functions
agent_selector.change( agent_selector.change(
fn=update_ui_for_swarm_type, fn=update_ui_for_swarm_type,

Loading…
Cancel
Save