Overview
Concrete tool for spawning a worker agent for a single swarm subtask provided by the jcode server.
Description
The run_swarm_task function creates a new session and agent for a single subtask within a swarm. The worker agent inherits the coordinator's provider fork, registry, working directory, model, and auth identity. The worker runs the task prompt, captures output, and returns it to the coordinator. The worker's report_back_to_session_id is set to the coordinator's session, encoding the spawn tree.
Usage
- Spawn a worker: Called for each subtask in the swarm plan.
- Run subtask: The worker agent executes the task prompt and returns results.
Code Reference
Source Location
- Repository: jcode
- File: crates/jcode-app-core/src/server/swarm.rs
Signature
pub async fn run_swarm_task(
agent: Arc<Mutex<Agent>>,
description: &str,
subagent_type: &str,
prompt: &str,
) -> Result<String>
Import
// Internal server function, called during swarm plan execution:
// crates/jcode-app-core/src/server/swarm.rs
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| agent |
Arc<Mutex<Agent>> |
Yes |
The coordinator agent (source of provider, model, auth)
|
| description |
&str |
Yes |
Human-readable task label
|
| subagent_type |
&str |
Yes |
Worker type identifier
|
| prompt |
&str |
Yes |
Task instructions for the worker
|
Outputs
| Name |
Type |
Description
|
| return |
Result<String> |
Worker's output text returned to coordinator
|
| side effects |
session |
New Session and Agent created; SwarmMember registered
|
Usage Examples
Spawn Worker for Subtask
// Called internally for each subtask in the decomposed plan:
let output = run_swarm_task(
coordinator_agent,
"Refactor auth/login.rs",
"rust-dev",
"Refactor the login function to use async/await..."
).await?;
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.