diff --git a/swarm_framework/SKILL.md b/swarm_framework/SKILL.md index 19377b1..13049d8 100644 --- a/swarm_framework/SKILL.md +++ b/swarm_framework/SKILL.md @@ -126,6 +126,7 @@ 1. **Master Agent** cannot be triggered via file request. Results or prompts meant for Master must be saved to `comms/master_notifications.json`. 2. **Sub-agents** can trigger **Sub-agents** and **Orchestrator Agent**. 3. **Master Agent** can trigger **Orchestrator Agent** ONLY. +4. **Do not print blocking prompts or clarification requests to the console.** All agents (except Master when interacting with user) MUST raise prompts in their `output/` folder or log to `master_notifications.json` to inform upstream. Console output is not visible to users. Ensure all request files populate the `"sender"` field! diff --git a/swarm_framework/agents/orchestrator/SKILL.md b/swarm_framework/agents/orchestrator/SKILL.md index 9bd984b..2d6a5bb 100644 --- a/swarm_framework/agents/orchestrator/SKILL.md +++ b/swarm_framework/agents/orchestrator/SKILL.md @@ -6,6 +6,9 @@ ## Communication Protocol You communicate by watching the Orchestrator pane (`grid.0`) for notifications and using terminal commands to interact with sub-agents. +### Reading Sub-Agent Files +When a sub-agent sends a response or request to you, it will be placed in your `incoming/` folder and IMMEDIATELY moved to `processing/` folder by the system. You will be notified to read it from `processing/`. When done, move it to `archive/` folder. + ### Handling Sub-Agent Prompts When a sub-agent hits a prompt (e.g., "Do you want to proceed?"), the bridge code will notify you in your pane (`grid.0`) with a message like: `[System] Sub-agent grid.N needs approval.` @@ -22,5 +25,8 @@ **Example:** To select option 1 for Agent 1: `tmux send-keys -t jetski_swarm:grid.1 "1" C-m` +## Console Output & Blocking Rules +**Do not print blocking prompts or clarification requests to the console.** If you are blocked or need clarification, raise a prompt in your `output/` folder or log to `master_notifications.json` to inform upstream. Orchestrator console output is not visible to users; communication must be routed via files. + ## Completion Rule When you are done or need to notify the Master Agent about results, you MUST write a response file to your `output/` directory (following the Atomicity Rule) or log to `master_notifications.json` if it is a prompt. diff --git a/swarm_framework/bootstrap.sh b/swarm_framework/bootstrap.sh index 1798779..7d1a195 100755 --- a/swarm_framework/bootstrap.sh +++ b/swarm_framework/bootstrap.sh @@ -40,10 +40,10 @@ # Create session with Master Agent window mkdir -p "$SCRIPT_DIR/agents/master" -mkdir -p "$SCRIPT_DIR/agents/master/incoming" "$SCRIPT_DIR/agents/master/output" "$SCRIPT_DIR/agents/master/archive" +mkdir -p "$SCRIPT_DIR/agents/master/incoming" "$SCRIPT_DIR/agents/master/output" "$SCRIPT_DIR/agents/master/archive" "$SCRIPT_DIR/agents/master/processing" tmux new-session -d -s $SESSION_NAME -n master -c "$SCRIPT_DIR/agents/master" -tmux send-keys -t $SESSION_NAME:master "$CLI_PATH -cli=true" C-m +tmux send-keys -t $SESSION_NAME:master "$CLI_PATH -cli=true -dangerously-skip-permissions=true" C-m # Wait a few seconds for Master Agent to initialize, then inject skill instruction sleep 5 @@ -55,7 +55,7 @@ # Create Grid window for all agents (Orchestrator + Sub-agents) mkdir -p "$SCRIPT_DIR/agents/orchestrator" -mkdir -p "$SCRIPT_DIR/agents/orchestrator/incoming" "$SCRIPT_DIR/agents/orchestrator/output" "$SCRIPT_DIR/agents/orchestrator/archive" +mkdir -p "$SCRIPT_DIR/agents/orchestrator/incoming" "$SCRIPT_DIR/agents/orchestrator/output" "$SCRIPT_DIR/agents/orchestrator/archive" "$SCRIPT_DIR/agents/orchestrator/processing" cp "$SCRIPT_DIR/orchestrator_SKILL.md" "$SCRIPT_DIR/agents/orchestrator/SKILL.md" tmux new-window -t $SESSION_NAME -n grid -c "$SCRIPT_DIR/agents/orchestrator" @@ -66,20 +66,20 @@ # Pane 0: Orchestrator Brain tmux select-pane -t $SESSION_NAME:grid.0 -T "Orchestrator Brain" -tmux send-keys -t $SESSION_NAME:grid.0 "$CLI_PATH -cli=true" C-m +tmux send-keys -t $SESSION_NAME:grid.0 "$CLI_PATH -cli=true -dangerously-skip-permissions=true" C-m sleep 5 tmux send-keys -t $SESSION_NAME:grid.0 "Please read the file 'SKILL.md' in your current directory to understand your role." C-m # Add sub-agents to Grid window as panes for i in $(seq 1 $N); do mkdir -p "$SCRIPT_DIR/agents/agent_$i" - mkdir -p "$SCRIPT_DIR/agents/agent_$i/incoming" "$SCRIPT_DIR/agents/agent_$i/output" "$SCRIPT_DIR/agents/agent_$i/archive" + mkdir -p "$SCRIPT_DIR/agents/agent_$i/incoming" "$SCRIPT_DIR/agents/agent_$i/output" "$SCRIPT_DIR/agents/agent_$i/archive" "$SCRIPT_DIR/agents/agent_$i/processing" cp "$SCRIPT_DIR/sub_agent_SKILL.md" "$SCRIPT_DIR/agents/agent_$i/SKILL.md" tmux split-window -t $SESSION_NAME:grid -c "$SCRIPT_DIR/agents/agent_$i" tmux select-layout -t $SESSION_NAME:grid tiled tmux select-pane -t $SESSION_NAME:grid.$i -T "Sub Agent $i" - tmux send-keys -t $SESSION_NAME:grid.$i "$CLI_PATH -cli=true" C-m + tmux send-keys -t $SESSION_NAME:grid.$i "$CLI_PATH -cli=true -dangerously-skip-permissions=true" C-m sleep 5 tmux send-keys -t $SESSION_NAME:grid.$i "Please read the file 'SKILL.md' in your current directory to understand the communication protocol." C-m done diff --git a/swarm_framework/orchestrator.py b/swarm_framework/orchestrator.py index 629d9ee..3d5ef34 100644 --- a/swarm_framework/orchestrator.py +++ b/swarm_framework/orchestrator.py @@ -421,6 +421,7 @@ dir_name = get_agent_dir_name(agent) agent_dir = os.path.join(BASE_DIR, "agents", dir_name) incoming_dir = os.path.join(agent_dir, "incoming") + processing_dir = os.path.join(agent_dir, "processing") output_dir = os.path.join(agent_dir, "output") archive_dir = os.path.join(agent_dir, "archive") @@ -450,6 +451,23 @@ if os.path.exists(target_inc_dir): src_path = os.path.join(output_dir, f) + + # Append rules to prompt if sending to a sub-agent + if target.startswith("agent_"): + try: + with open(src_path, 'r') as file_in: + msg_data = json.load(file_in) + + if "prompt" in msg_data: + rules = "\n\n=== REMINDER: SWARM COMMUNICATION RULES ===\n1. DO NOT print blocking prompts or clarification requests to console. You MUST raise prompts via file communication in your 'output/' folder to inform upstream.\n2. You MUST write a response file to your 'output/' folder when you complete a task or need upper layer attention.\n3. Wrap your final answer in ===RESULT=== and ===END_RESULT=== markers.\n==========================================" + msg_data["prompt"] += rules + + with open(src_path, 'w') as file_out: + json.dump(msg_data, file_out, indent=2) + + except Exception as e: + print(f"Error appending rules: {e}") + dst_path = os.path.join(target_inc_dir, f"from_{agent}_{msg_id}.json") try: shutil.move(src_path, dst_path) @@ -459,7 +477,25 @@ else: print(f"Target dir not found for {target_dir_name}") else: - print(f"Ignored file not matching pattern: {f}") + # Fallback for Orchestrator Brain results + if dir_name == "orchestrator" and f.startswith("res_") and f.endswith(".json"): + target = "master" + msg_id = f[4:-5] + target_dir_name = "master" + target_inc_dir = os.path.join(BASE_DIR, "agents", target_dir_name, "incoming") + + if os.path.exists(target_inc_dir): + src_path = os.path.join(output_dir, f) + dst_path = os.path.join(target_inc_dir, f"from_{agent}_{msg_id}.json") + try: + shutil.move(src_path, dst_path) + print(f"Moved {f} from {agent}/output to {target_dir_name}/incoming (fallback)") + except Exception as e: + print(f"Error moving file: {e}") + else: + print(f"Target dir not found for {target_dir_name}") + else: + print(f"Ignored file not matching pattern: {f}") # 2. Watch Incoming if os.path.exists(incoming_dir): @@ -467,12 +503,12 @@ for f in files: if f.endswith(".json"): src_path = os.path.join(incoming_dir, f) - dst_path = os.path.join(archive_dir, f) + dst_path = os.path.join(processing_dir, f) try: shutil.move(src_path, dst_path) - print(f"Moved {f} to {dir_name}/archive") + print(f"Moved {f} to {dir_name}/processing") # Notify agent pane - cmd = f"tmux send-keys -t {SESSION_NAME}:{agent} \"Read file agents/{dir_name}/archive/{f}\" C-m" + cmd = f"tmux send-keys -t {SESSION_NAME}:{agent} \"Read file agents/{dir_name}/processing/{f}\" C-m" subprocess.run(cmd, shell=True, check=True) except Exception as e: print(f"Error processing incoming file: {e}") diff --git a/swarm_framework/orchestrator_SKILL.md b/swarm_framework/orchestrator_SKILL.md index 9bd984b..2d6a5bb 100644 --- a/swarm_framework/orchestrator_SKILL.md +++ b/swarm_framework/orchestrator_SKILL.md @@ -6,6 +6,9 @@ ## Communication Protocol You communicate by watching the Orchestrator pane (`grid.0`) for notifications and using terminal commands to interact with sub-agents. +### Reading Sub-Agent Files +When a sub-agent sends a response or request to you, it will be placed in your `incoming/` folder and IMMEDIATELY moved to `processing/` folder by the system. You will be notified to read it from `processing/`. When done, move it to `archive/` folder. + ### Handling Sub-Agent Prompts When a sub-agent hits a prompt (e.g., "Do you want to proceed?"), the bridge code will notify you in your pane (`grid.0`) with a message like: `[System] Sub-agent grid.N needs approval.` @@ -22,5 +25,8 @@ **Example:** To select option 1 for Agent 1: `tmux send-keys -t jetski_swarm:grid.1 "1" C-m` +## Console Output & Blocking Rules +**Do not print blocking prompts or clarification requests to the console.** If you are blocked or need clarification, raise a prompt in your `output/` folder or log to `master_notifications.json` to inform upstream. Orchestrator console output is not visible to users; communication must be routed via files. + ## Completion Rule When you are done or need to notify the Master Agent about results, you MUST write a response file to your `output/` directory (following the Atomicity Rule) or log to `master_notifications.json` if it is a prompt. diff --git a/swarm_framework/sub_agent_SKILL.md b/swarm_framework/sub_agent_SKILL.md index e512eb2..95ff850 100644 --- a/swarm_framework/sub_agent_SKILL.md +++ b/swarm_framework/sub_agent_SKILL.md @@ -30,15 +30,16 @@ * `prompt`: The text message or command you want the agent to execute. ### 2. Reading a Response -The background Orchestrator will pick up your request, route it to the target, and the response from the target will be placed in your `incoming/` folder as `from_[target]_[original_name].json`. -You should wait for the notification or poll your `incoming/` folder. +The background Orchestrator will pick up your request, route it to the target's `incoming/` folder. The system will then move it to your `processing/` folder and notify you. You should read it from `processing/`. +You should wait for the notification or poll your `processing/` folder. ## Communication Boundaries Rules 1. **Do not target the Master Agent directly** via file communication. All notifications for Master must be handled by the Orchestrator. 2. **You can communicate with any other sub-agent or the Orchestrator.** +3. **Do not print blocking prompts or clarification requests to the console.** If you are blocked or need clarification, raise a prompt in your `output/` folder to inform upstream (Orchestrator). Sub-agent console output is not visible to users; communication must be routed via files. ## Payload Content Rules When sending a response or request, ensure the `prompt` or `output` field contains ONLY the relevant information. You MUST wrap your final answer in `===RESULT===` and `===END_RESULT===` markers (e.g., in the `output` field or terminal output). The system will extract content between these markers to remove UI garbage. ## Completion Rule -When you complete an assigned task or require upper layer attention, you MUST write a response file to your `output/` directory (following the Atomicity Rule) to inform the upper layer. Failure to do so will leave the system waiting indefinitely! +When you complete an assigned task or require upper layer attention, you MUST write a response file to your `output/` directory (following the Atomicity Rule) to inform the upper layer. Also, you SHOULD move the read file from `processing/` to `archive/` folder. Failure to do so will leave the system waiting indefinitely!