Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b814f2c
feat(agents): add boss agent hierarchy with escalation protocol
aspotton Apr 4, 2026
a0bd96d
fix(ui): add crown and clipboard-list icons for boss and planning-lea…
aspotton Apr 4, 2026
25bc19f
feat(presets): add link configuration instructions to boss and planni…
aspotton Apr 4, 2026
1803004
feat(presets): add request triage section to boss agent ROLE.md
aspotton Apr 4, 2026
37b1a77
feat(presets): add request triage section to planning-lead ROLE.md
aspotton Apr 4, 2026
7623727
feat(presets): add task completion handling and triage to boss and pl…
aspotton Apr 4, 2026
c56dafb
feat: add dual-mode hierarchical agent support for Boss Agent pat…
aspotton Apr 5, 2026
77dec64
feat(planning-lead): implement capability-based delegation for flexib…
aspotton Apr 5, 2026
1437d87
feat(tools): add DelegationConfig for optional worker delegation
aspotton Apr 5, 2026
4edbd4b
feat(worker): add task_metadata field for delegation detection
aspotton Apr 5, 2026
3354c03
feat(prompts): add build_org_context_for_agent helper
aspotton Apr 5, 2026
f422dbf
feat(cortex): detect delegated tasks and build agent-aware workers
aspotton Apr 5, 2026
58eb6d0
chore: verify gate-pr — cargo check clean (no new errors)
aspotton Apr 5, 2026
9eb7b4f
fix(planning-lead): make subordinate delegation mandatory, remove wor…
aspotton Apr 5, 2026
a624c93
fix(agents): add environmental blocker handling and trust rules
aspotton Apr 5, 2026
bb17d2c
fix(agents): add anti-bounce rules to Engineering Assistant, Research…
aspotton Apr 5, 2026
f546b53
fix(planning-lead): add Wait for Subordinate Results section
aspotton Apr 5, 2026
0dee4e7
fix(agents): add Wait for Subordinate Results to all presets
aspotton Apr 5, 2026
1ad0e57
fix(cortex): put identity after worker template in delegated prompts
aspotton Apr 5, 2026
6105fa4
feat(tools): add task_list and task_update to delegated workers
aspotton Apr 5, 2026
792bb54
fix(agents): mention task_list tool in Wait for Subordinate Results
aspotton Apr 5, 2026
779c6e9
fix(tools): use TaskUpdateTool::for_worker instead of non-existent new()
aspotton Apr 5, 2026
062b964
fix(tools): use agent_id.to_string() for TaskListTool constructor
aspotton Apr 5, 2026
0f759e0
fix(tools): use agent_id_for_delegation for all delegation tools
aspotton Apr 6, 2026
896a500
feat(tools): add task_get tool for reading delegated task results
aspotton Apr 7, 2026
7be1ce4
docs: update hierarchy documentation with complete delegation flow
aspotton Apr 7, 2026
1e5c3bd
fix(boss-agent): add Patience and Synchronization section
aspotton Apr 7, 2026
b00c055
fix(agents): add Patience and Synchronization to all delegating agents
aspotton Apr 7, 2026
21bed41
fix(task_get): allow reading tasks assigned to calling agent
aspotton Apr 7, 2026
9be0db1
feat(tools): add originating_channel to DelegationConfig
aspotton Apr 7, 2026
c0e9a3a
fix(channel): set originating_channel on send_agent_message tool
aspotton Apr 7, 2026
2c092ff
feat(cortex): add parent-child task tracking to eliminate delegation …
aspotton Apr 7, 2026
191e23b
feat: inject hierarchical behavior rules based on agent link structure
aspotton Apr 10, 2026
c7ff799
fix(cortex): inject hierarchical rules into all workers from hierarch…
aspotton Apr 10, 2026
f145d3c
fix(cortex): replace missing helper with inline hierarchical links check
aspotton Apr 10, 2026
f5072f4
docs: clarify delegation flow and add spawn_worker warning for hierar…
aspotton Apr 10, 2026
febd288
Fixed duplicate text
aspotton Apr 10, 2026
8ed1f78
feat: add agent role awareness to hierarchical delegation
aspotton Apr 10, 2026
36b811a
fix: remove duplicate agent_roles field in AgentDeps construction
aspotton Apr 10, 2026
470052b
fix: increase delegation notification truncation to 3000 chars and st…
aspotton Apr 10, 2026
7a278bc
fix: strengthen anti-bounce rules with explicit STOP instructions for…
aspotton Apr 11, 2026
fc94791
feat(tools): add wait_for_task tool to eliminate delegation polling
aspotton Apr 11, 2026
78291a6
fix: clone task status before moving task in wait_for_task borrow che…
aspotton Apr 11, 2026
f614a04
feat(prompts): add critical rule to report findings to task metadata …
aspotton Apr 11, 2026
43d2ccf
fix(cortex): remove unused parent_summary variable
aspotton Apr 12, 2026
d132c23
style: apply rustfmt formatting to all modified files
aspotton Apr 12, 2026
ba29df1
fix: add missing agent_roles field and remove duplicate definition
aspotton Apr 12, 2026
2cd4c42
fix(tests): add missing agent_roles and DelegationConfig to context_d…
aspotton Apr 12, 2026
82f02bd
fix: address clippy clone_on_copy and formatting issues
aspotton Apr 12, 2026
206f369
Merge branch 'main' into feat/hierarchical-behavior-injection
jamiepine Apr 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,70 @@ Module roots (e.g., `src/memory.rs`) contain `mod` declarations and re-exports.

Tools are organized by function, not by consumer. Which processes get which tools is configured via factory functions in `tools.rs`.

## Delegated Worker Architecture

The cortex detects delegated tasks (via `delegated_by` metadata on tasks) and enhances the worker creation path to support hierarchical delegation chains.

### Cortex Detection

When the cortex picks up a `Ready` task from the task board, it checks for `delegated_by` metadata. If present, the task was created by a superior agent via `send_agent_message`, and the worker gets an enhanced setup:

1. **Identity injection** — SOUL.md, IDENTITY.md, and ROLE.md are appended AFTER the worker template, giving the worker its full personality and role context.
2. **Org context** — The worker sees its position in the hierarchy (reports to, direct reports, peers) so it knows who to escalate to and who to delegate to.
3. **Delegation tools** — Four additional tools are added to the worker's ToolServer.

### DelegationConfig

An optional `DelegationConfig` param to `create_worker_tool_server` that adds four delegation tools:

| Tool | Description |
|------|-------------|
| `send_agent_message` | Send a message to a linked agent, creating a task in their task store |
| `task_list` | List tasks in the worker's task store, filtered by status |
| `task_get` | Read full details of a specific task |
| `task_update` | Update task status, priority, or metadata |

### Task Metadata

Tasks created via `send_agent_message` carry `delegated_by` metadata containing the source agent ID. This triggers the enhanced worker path:

```
Task metadata: {
"delegated_by": "boss",
"escalation_chain": ["builder-1"], // optional, for loop protection
...
}
```

### Access Control

`task_get` enforces strict access control: workers can only read tasks they created or that were assigned to them. This prevents information leakage between parallel workers — a builder working on task A cannot read the details of task B assigned to a different builder.

### Complete Delegation Flow

```
Boss → send_agent_message → Planning-lead task store
→ Cortex detects delegated_by metadata
→ Planning-lead spawns Engineering Assistant (with DelegationConfig)
→ task_list → sees assigned tasks
→ send_agent_message → Builder workers
→ Workers execute (shell, file, browser)
→ set_status(kind: "outcome") → done
→ task_get → reads worker results
→ Synthesizes findings
→ task_update → marks complete
→ Planning-lead synthesizes and reports to Boss
```

### Anti-Bounce Rules

Delegated workers follow behavioral rules to prevent common failure modes:

- **Environmental Blockers** — Handle sandbox restrictions, missing credentials, and permission errors gracefully. Report blockers via escalation rather than silently failing.
- **No Status Check Tasks** — Don't spawn workers just to check task status. Use `task_list` to poll the task board directly.
- **Wait for Subordinate Results** — Don't mark a task as done until all subordinate workers have completed. Synthesize their results before reporting up.
- **Trust Your Subordinates** — The boss doesn't micro-manage planning-lead escalations. Each level trusts the level below to handle what it can.

## Three Databases

Each doing what it's best at. No server processes.
Expand Down
87 changes: 87 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,93 @@ Channel context hits 80%

For process capabilities, tool access by type, memory internals, cron, and multi-agent isolation, see [ARCHITECTURE.md](ARCHITECTURE.md).

### Boss Agent Hierarchy

For teams that need structured delegation, Spacebot supports hierarchical agent org charts. A **boss** agent delegates work to subordinate agents (like a **planning-lead**), which in turn delegate to specialized agents (like **engineering-assistant**) or orchestrate builder workers. This creates a clear chain of command with built-in escalation paths and specialized roles.

#### How It Works

1. **Boss delegates** — The boss agent uses `send_agent_message` to create a task in the planning-lead's task store. The task includes `delegated_by` metadata.
2. **Cortex detects delegation** — When the cortex picks up the task, it detects the `delegated_by` metadata and:
- Injects the agent's identity files (SOUL.md, IDENTITY.md, ROLE.md) **after** the worker template so they take precedence
- Injects `org_context` showing subordinates, superiors, and peers from the link graph
- Adds delegation tools: `send_agent_message`, `task_list`, `task_get`, `task_update`
3. **Planning-lead orchestrates** — The planning-lead's worker sees its subordinates in the org context and uses `send_agent_message` to delegate to the appropriate agent (e.g., engineering-assistant for code work).
4. **Polling and synthesis** — The planning-lead uses `task_list` to poll for task completion, then `task_get` to read the subordinate's findings. It synthesizes the results and reports to the boss.
5. **Builders execute** — If no suitable subordinate exists, the planning-lead spawns a builder worker with shell, file, and browser tools.

**Complete delegation flow:**

```
Boss receives user request
Boss calls send_agent_message(target="Planning Lead")
Cortex detects delegated_by metadata → injects identity + org_context + delegation tools
Planning Lead worker sees Engineering Assistant as subordinate
Planning Lead calls send_agent_message(target="Engineering Assistant")
Planning Lead polls task_list until task is "done"
Planning Lead calls task_get(task_number=N) → reads findings
Planning Lead synthesizes findings → reports to Boss → marks done
```

**Access control:** The `task_get` tool only allows reading tasks where `owner_agent_id` matches the calling agent or `created_by` matches the calling agent. Workers cannot read superior's tasks (prevents information leakage) but can read subordinate results (enables synthesis).

**Config example:**

```toml
[[agents]]
id = "boss-agent"
preset = "boss-agent"
display_name = "Boss Agent"

[[agents]]
id = "planning-lead"
preset = "planning-lead"
display_name = "Planning Lead"

[[agents]]
id = "engineering-assistant"
preset = "engineering-assistant"
display_name = "Engineering Assistant"

[[links]]
from = "boss-agent"
to = "planning-lead"
direction = "two_way"
kind = "hierarchical"

[[links]]
from = "planning-lead"
to = "engineering-assistant"
direction = "two_way"
kind = "hierarchical"
```

#### Anti-Bounce Rules

All agents follow these rules to prevent task spam and escalation loops:

- **Environmental Blockers**: When a worker hits sandbox isolation, missing credentials, or missing repo path — acknowledge the blocker, request specific info, wait for response. Do NOT escalate repeatedly.
- **No Status Check Tasks**: Do NOT spawn workers to check status of other workers. Use `task_list` to poll the task store directly.
- **Wait for Subordinate Results**: Do NOT mark your task done until all delegated subtasks are complete. Use `task_list` to poll, `task_get` to read results, synthesize, then report to superior.
- **Trust Your Subordinates**: When a subordinate escalates a blocker, provide the info or ask the user. Do NOT create parallel unblock tasks.

#### Specialized Agent Roles

The hierarchy supports specialized agents that operate in both standalone and hierarchical modes:

- **Research Analyst** — Conducts research and analysis. In hierarchical mode, receives research tasks from Planning Lead, delegates data gathering to workers, and reports synthesized findings with evidence.
- **Project Manager** — Tracks work and coordinates across teams. In hierarchical mode, receives objectives from Boss, delegates analysis to Research Analysts and implementation to Engineering Assistants, and relays synthesized status to the Boss.
- **Engineering Assistant** — Handles technical work. In hierarchical mode, triages tasks to determine if analysis is needed, delegates implementation to builders, and reports results with evidence.

All specialized agents follow the same pattern: triage requests before acting, delegate execution to appropriate subordinates or workers, and always report back to their superior with clear structure and evidence.

---

## Goals and Tasks
Expand Down
191 changes: 191 additions & 0 deletions docs/content/docs/(core)/agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,197 @@ You are part of a multi-agent system. Here is your position:

The agent sees its position in the hierarchy before processing any message. Authority framing comes from the link structure — the agent knows who to escalate to, who to delegate to, and who to collaborate with.

## Boss Agent Hierarchy

The communication graph enables a structured delegation pattern: the **boss hierarchy**. This is a multi-tier org chart where a boss agent delegates to a planning-lead, which delegates to an engineering assistant, which orchestrates builder workers to execute tasks. The pattern supports specialized agent roles that operate in both standalone and hierarchical modes.

### Configuration

```toml
[[agents]]
id = "boss"
display_name = "Strategic Director"
preset = "boss"

[[agents]]
id = "planning-lead"
display_name = "Planning Lead"
preset = "planning-lead"

[[agents]]
id = "engineering-assistant"
display_name = "Engineering Assistant"
preset = "engineering-assistant"

[[links]]
from = "boss"
to = "planning-lead"
direction = "two_way"
kind = "hierarchical"

[[links]]
from = "planning-lead"
to = "engineering-assistant"
direction = "two_way"
kind = "hierarchical"
```

The `hierarchical` link kind establishes the chain of command. The `preset` field configures each agent with appropriate model routing and behavior defaults for its role.

### How It Works

**Complete delegation flow:**

```
Boss receives user request
→ send_agent_message → Planning-lead task store
→ Cortex detects delegated_by metadata
→ Injects identity (SOUL.md, IDENTITY.md, ROLE.md) + org_context + hierarchical_rules
→ Planning-lead spawns Engineering Assistant (with DelegationConfig)
→ task_list → sees assigned tasks
→ send_agent_message → Builder workers
→ Workers execute (shell, file, browser)
→ set_status(kind: "outcome") → done
→ task_get → reads worker results
→ Synthesizes findings
→ task_update → marks complete
→ Planning-lead reviews results
→ Synthesizes and reports to Boss
→ Boss relays synthesized result to user
```

1. **Boss delegates** — The boss agent uses `send_agent_message` to create a task in the planning-lead's task store. This appears as a message in the planning-lead's link channel (`link:planning-lead:boss`). **Do NOT use `spawn_worker` for delegation** — `spawn_worker` creates a worker directly without task board tracking, bypasses the delegation chain, and breaks completion notifications.
2. **Cortex detects delegation** — The planning-lead's cortex picks up `Ready` tasks with `delegated_by` metadata. It detects this is a delegated task and enhances the worker setup:
- **Identity injection** — SOUL.md, IDENTITY.md, and ROLE.md are appended AFTER the worker template
- **Org context** — The worker sees its position in the hierarchy (reports to, direct reports, peers)
- **Hierarchical rules** — Behavioral rules for delegation, anti-bounce, and synthesis are automatically injected based on link structure
- **Delegation tools** — Four additional tools are added to the ToolServer
3. **Planning-lead orchestrates** — Spawns an engineering assistant with `DelegationConfig`, giving it `send_agent_message`, `task_list`, `task_get`, and `task_update` tools.
4. **Engineering Assistant delegates** — Polls `task_list` for assigned tasks, delegates implementation to builder workers via `send_agent_message`, and waits for completion.
5. **Builders execute** — Workers run autonomously with shell, file, and browser tools. They signal completion via `set_status(kind: "outcome")`.
6. **Synthesis and report** — The engineering assistant reads results with `task_get`, synthesizes findings, updates the task, and reports back. The planning-lead synthesizes and reports to the boss. The boss relays the synthesized result to the user.

### Hierarchical Behavior Injection

When an agent has hierarchical links, behavioral rules are automatically injected into its prompt — no ROLE.md changes needed. These rules are agent-agnostic and work for any hierarchy configuration:

- **Agents with superiors** get rules for receiving delegated work, synthesizing reports, and reporting up
- **Agents with subordinates** get rules for delegating via `send_agent_message`, waiting for completion notifications, and avoiding status-check tasks
- **All hierarchical agents** get rules about escalation chains, delegation as progress (not a blocker), and trusting the notification system

The rules use dynamic agent names from the link structure (e.g., "When you delegate work to planning-lead...") so they work for any agent configuration without hardcoded names.

Additionally, the `spawn_worker` tool description includes a warning for hierarchical agents: if you have subordinates, use `send_agent_message` instead of `spawn_worker` for delegation.

### Delegation Tools

Workers created with a `DelegationConfig` get four additional tools for hierarchical task management:

| Tool | Description |
|------|-------------|
| `send_agent_message` | Send a message to a linked agent, creating a task in their task store |
| `task_list` | List tasks in the worker's task store, filtered by status |
| `task_get` | Read full details of a specific task. **Access control:** only tasks owned by or created by the calling agent |
| `task_update` | Update task status, priority, or metadata |

### Access Control

`task_get` enforces strict access control: workers can only read tasks they created or that were assigned to them. This prevents information leakage between parallel workers — a builder working on task A cannot read the details of task B assigned to a different builder.

### Anti-Bounce Rules

Delegated workers follow behavioral rules to prevent common failure modes:

- **Environmental Blockers** — Handle sandbox restrictions, missing credentials, and permission errors gracefully. Report blockers via escalation rather than silently failing.
- **No Status Check Tasks** — Don't spawn workers just to check task status. Use `task_list` to poll the task board directly.
- **Wait for Subordinate Results** — Don't mark a task as done until all subordinate workers have completed. Synthesize their results before reporting up.
- **Trust Your Subordinates** — The boss doesn't micro-manage planning-lead escalations. Each level trusts the level below to handle what it can.

### Escalation Flow

Builder workers are injected with an escalation protocol (from `prompts/en/fragments/builder_escalation.md.j2`) that defines when and how to escalate:

```
Builder hits blocker
→ task_create (escalation) → Planning-lead
→ Planning-lead resolves or escalates to Boss
→ Boss makes decision, routes back down
```

**When to escalate:**

- **Blockers** — A dependency is missing, a service is unreachable, or an external system prevents progress.
- **Missing information** — The task references files, credentials, or context that do not exist and cannot be inferred.
- **Ambiguous requirements** — Conflicting instructions or underspecified goals where the choice materially affects the outcome.

**When NOT to escalate:**

- Routine errors recoverable by retry or alternative approach.
- Minor ambiguities where a reasonable default exists — pick one and document the choice.
- Tasks that are simply difficult or time-consuming.

### Escalation Loop Protection

Before escalating, builders check the `escalation_chain` metadata array on their task:

- If the builder's **own agent ID** appears in the chain, escalation is blocked — the builder reports the loop condition via `set_status` instead.
- When escalating, the builder **appends its agent ID** to the `escalation_chain` so downstream agents can detect loops.
- If no `escalation_chain` exists, a new one is started with the builder's ID as the first entry.

This prevents infinite escalation cycles in complex multi-agent setups.

### Escalation Task Structure

When a builder escalates, it creates a task via `task_create` with this structure:

```
title: "Escalation: <brief description of the blocker>"
description: "<detailed explanation of what was encountered, what was tried, and why progress is blocked>"
priority: "high"
metadata: {
"escalation": true,
"original_task": "<the task title or description>",
"reason": "blocker | missing_info | ambiguous_requirement",
"escalation_chain": ["<agent-id-1>", "<agent-id-2>"]
}
```

After creating the escalation task, the builder calls `set_status` with `kind: "outcome"` and a summary, then waits for resolution.

### Specialized Agent Roles

The hierarchy supports specialized agents that can operate in both standalone and hierarchical modes:

**Research Analyst** — Conducts research and analysis on topics. In standalone mode, works independently on research requests. In hierarchical mode:
- Receives research tasks from Planning Lead
- Triage requests to check if scoping is needed before research begins
- Delegates data gathering (web browsing, document retrieval) to workers
- Synthesizes findings and reports back with clear structure and evidence
- Escalates when access or context is missing

**Project Manager** — Tracks work, coordinates across teams, and maintains project visibility. In standalone mode, manages projects independently. In hierarchical mode:
- Receives objectives from Boss agent
- Triage requests to determine if analysis or implementation is needed
- Delegates analysis to Research Analysts and implementation to Engineering Assistants
- Synthesizes status reports from specialists and creates task-board tasks
- Relays synthesized status to Boss with clear summaries

**Engineering Assistant** — Handles technical work including code reviews and implementation. In standalone mode, provides technical assistance directly. In hierarchical mode:
- Receives technical tasks from Planning Lead
- Cortex detects `delegated_by` metadata and injects identity + org_context
- Triage requests to check if analysis is needed before implementation
- Delegates implementation work to builder workers via `send_agent_message`
- Uses `task_list` to poll for assigned tasks, `task_get` to read results
- Reports results with evidence including files modified, test results, and follow-up needs
- Waits for all subordinate workers to complete before marking task done

All specialized agents follow the same behavioral rules:
1. **Triage before acting** — Always check the request against the org chart and classify before taking action
2. **Delegate execution** — Never do work that a subordinate or worker can handle
3. **Report with structure** — Always return complete reports with clear organization and evidence
4. **Never leave superior waiting** — Even if the answer is "insufficient data," return something rather than leaving the superior in limbo
5. **Escalate appropriately** — Only escalate genuine blockers, not routine errors or tasks that are simply difficult

## Humans

Org-level humans represent real people in the organization. They appear as nodes in the topology graph and can be linked to agents.
Expand Down
Loading
Loading