Welcome to the third chapter of the Shared project tutorial!
In the previous chapter, Agent Spawning Orchestrator, we acted as the "Hiring Manager," gathering all the necessary paperwork, permissions, and configurations to hire a new agent.
Now, we need to answer a physical question: Where does this new agent actually sit?
Imagine setting up a workspace for your new employee. You have three options:
Execution Backend Strategies are the code implementations for these three scenarios. They abstract away the messy details of how to create these environments so the rest of the app doesn't have to care.
Let's look at how the code handles these three different "office" types.
Here is what happens when the Orchestrator hands off the task to a specific backend strategy.
Let's look at how this is implemented in spawnMultiAgent.ts. We will focus on the two most common strategies: In-Process and Split-Pane.
This is the "Virtual Assistant" approach. Instead of running a shell command, we simply call a JavaScript function to start the agent loop.
We prepare a config object. Notice we don't need shell flags here; we just pass JavaScript objects directly.
// handleSpawnInProcess (spawnMultiAgent.ts)
const config: InProcessSpawnConfig = {
name: sanitizedName, // e.g. "Tester-2"
teamName: teamName,
prompt: prompt, // "Write a test for..."
color: teammateColor,
// ...
}
Explanation: Because we are in the same memory space, we don't need to serialize data into text strings. We just pass the data.
We start the agent but we don't wait for it to finish. The main agent needs to keep working while the sub-agent runs in the background.
// Start the agent execution loop
startInProcessTeammate({
taskId: result.taskId,
prompt,
// ... other context
abortController: result.abortController,
})
logForDebugging(`Started agent execution for ${teammateId}`)
Explanation: startInProcessTeammate kicks off the loop. The code immediately moves on, allowing the main application to remain responsive.
This is the "Open-Plan Desk" approach. It is more complex because we have to talk to an external program (Tmux).
First, we ask the layout manager to carve out space on the screen.
// handleSpawnSplitPane (spawnMultiAgent.ts)
// Returns the ID of the new blank terminal area
const { paneId } = await createTeammatePaneInSwarmView(
sanitizedName,
teammateColor,
)
Explanation: This sends a command like tmux split-window -h to the OS. Suddenly, a blank prompt appears on your screen.
We can't just pass variables. We have to build a long text string that looks like a command a human would type.
// We build a massive string of arguments
const teammateArgs = [
`--agent-id ${quote([teammateId])}`,
`--team-name ${quote([teamName])}`,
`--agent-color ${quote([teammateColor])}`,
// ... other flags
].join(' ')
// The final executable line
const spawnCommand = `cd ${cwd} && env ${vars} ${binary} ${teammateArgs}`
Explanation: This turns our nice JavaScript objects back into a raw CLI string: node app.js --agent-id "Tester-2" ...
Finally, we "type" that command into the new pane programmatically.
// Send the command to the new pane
await sendCommandToPane(paneId, spawnCommand, !insideTmux)
Explanation: We use a socket or shell command to paste our spawnCommand into the target pane and hit "Enter" virtually. The agent boots up in that window.
Regardless of where the agent sits (Process or Pane), we must update our "HR Roster" (the AppState) so the UI knows where to find them.
setAppState(prev => ({
...prev,
teamContext: {
// ...
teammates: {
[teammateId]: {
name: sanitizedName,
// We record the specific pane ID here
tmuxPaneId: paneId,
// Or "in-process" if it has no pane
tmuxSessionName: sessionName,
},
},
},
}))
Explanation: This unifies the strategies. The UI sidebar doesn't care if tmuxPaneId is a real number (Split-Pane) or the string "in-process". It just knows there is an active agent working there.
In this chapter, we learned about Execution Backend Strategies:
AppState so the UI remains consistent.Now we have agents spawning, running, and working in their specific environments. But how do we know what they are actually doing? How do we see the commands they run and keep a history of their work?
We will explore that in the final chapter.
Next Chapter: Command Telemetry & Git Tracking
Generated by Code IQ