agent_comm_protocol
Protocol schemas, builders, and template resolution for agent communication.
This package implements Layers 1-3 of the agent communication protocol:
- Layer 1: :class:
TaskManifest— structured facts about a task. - Layer 2: :func:
resolve_instructions— role-specific work instructions. - Layer 3: :class:
WorkflowPolicies— composable workflow configuration.
All types and functions are framework-agnostic. Framework adapters
(in task_runner/implementations/) consume these outputs.
DependencyInfo
dataclass
Description of a dependency task for manifest purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
Optional[str]
|
Human-readable description of the dependency task,
or |
Source code in src/agentrelay/agent_comm_protocol/manifest.py
30 31 32 33 34 35 36 37 38 39 | |
TaskManifest
dataclass
Frozen Layer-1 manifest: pure facts about a task.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
str
|
Schema version string. |
task_id |
str
|
Unique task identifier. |
role |
AgentRole
|
Agent role for this task. |
description |
Optional[str]
|
Human-readable task description, or |
tagged_paths |
tuple[TaggedPath, ...]
|
Category-tagged file paths for this task. |
branch_name |
str
|
Feature branch for this task's work. |
integration_branch |
str
|
Branch this task's PR targets. |
attempt_num |
int
|
Current attempt number (0-indexed). |
graph_name |
Optional[str]
|
Name of the containing graph, or |
dependencies |
dict[str, DependencyInfo]
|
Mapping of dependency task IDs to :class: |
tools |
tuple[str, ...]
|
Declared tool names from the graph YAML. |
Source code in src/agentrelay/agent_comm_protocol/manifest.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
WorkflowPolicies
dataclass
Frozen Layer-3 policies: composable workflow configuration.
Each optional field is independently None (behavior absent) or
present (behavior active). Framework adapters read these policies and
translate them into framework-specific actions.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
str
|
Schema version string. |
commit_policy |
Optional[_CommitPolicy]
|
Commit and push policy, or |
pr_policy |
Optional[_PrPolicy]
|
PR creation policy, or |
completion_gate |
Optional[_CompletionGatePolicy]
|
Gate loop policy, or |
review |
Optional[_ReviewPolicy]
|
Self-review policy, or |
adr |
Optional[_AdrPolicy]
|
ADR writing policy, or |
verification |
Optional[_VerificationPolicy]
|
Verification command policy, or |
Source code in src/agentrelay/agent_comm_protocol/policies.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
build_manifest(task, branch_name, integration_branch, graph_name, attempt_num, dependency_descriptions, tools=(), input_files=())
Build a :class:TaskManifest from task spec and contextual data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
Frozen task specification. |
required |
branch_name
|
str
|
Git branch for this task's work. |
required |
integration_branch
|
str
|
Branch this task's PR targets. |
required |
graph_name
|
Optional[str]
|
Name of the containing task graph. |
required |
attempt_num
|
int
|
Current execution attempt (0-indexed). |
required |
dependency_descriptions
|
dict[str, Optional[str]]
|
Map of dependency task ID to description
( |
required |
tools
|
tuple[str, ...]
|
Declared tool names from the graph YAML. |
()
|
Returns:
| Type | Description |
|---|---|
TaskManifest
|
Frozen manifest with all task facts. |
Source code in src/agentrelay/agent_comm_protocol/manifest.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
manifest_to_dict(manifest)
Serialize a :class:TaskManifest to a JSON-compatible dict.
The dict structure matches the Layer-1 schema defined in
docs/AGENT_COMM_PROTOCOL.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
TaskManifest
|
Frozen manifest to serialize. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Nested dict with |
dict[str, Any]
|
|
Source code in src/agentrelay/agent_comm_protocol/manifest.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
build_policies(task, integration_branch, default_max_gate_attempts=5)
Build :class:WorkflowPolicies from a task spec and contextual data.
Derives policies from the task's configuration:
commit_policy: always present (commit_and_push).pr_policy: always present;base_branchfrom integration_branch.completion_gate: present iftask.completion_gateis set.review: present iftask.reviewis set.adr: present iftask.primary_agent.adr_verbosityis notNONE.verification: present forTEST_WRITERandTEST_REVIEWERroles (defaultpytest --collect-only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
Frozen task specification. |
required |
integration_branch
|
str
|
Branch for PR base. |
required |
default_max_gate_attempts
|
int
|
Fallback when |
5
|
Returns:
| Type | Description |
|---|---|
WorkflowPolicies
|
Composable workflow configuration. |
Source code in src/agentrelay/agent_comm_protocol/policies.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
policies_to_dict(policies)
Serialize :class:WorkflowPolicies to a JSON-compatible dict.
The dict structure matches the Layer-3 schema defined in
docs/AGENT_COMM_PROTOCOL.md. None-valued policies become
JSON null.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policies
|
WorkflowPolicies
|
Frozen policies to serialize. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with |
Source code in src/agentrelay/agent_comm_protocol/policies.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
resolve_instructions(role, manifest, adapter_name=None, adr_verbosity=AdrVerbosity.NONE, sandbox_type=None, worktree_path=None, graph_yaml_path=None, signals_base_path=None)
Resolve work instructions by loading and parameterizing a role template.
The assembled document is structured as a work order:
- Role — who the agent is and what it's doing.
- Working Directory — where the agent must work (if
worktree_pathis provided). - Tools — environment tools available (if any).
- What to Do — role-specific steps from the template, or the task description for GENERIC roles.
- Graph Awareness — graph YAML location, signal directory formula,
and guidance on reading upstream artifacts and writing summaries
(if
graph_yaml_pathis provided andmanifest.graph_nameis set). - Previous Attempts — archived artifacts from prior retry
attempts (if
manifest.attempt_num > 0andsignals_base_pathis provided). - Architecture Decision Record — ADR writing instructions (if
adr_verbosityis notNONE). - Isolation Boundary — what the agent can/cannot access and
what exists beyond its boundary (if
sandbox_typeisOCI). - Submitting Your Work — how to commit, create a PR, and signal the orchestrator.
- Task Details — the task author's description (non-generic only, when present).
Template variables ($var syntax via :class:string.Template):
$description— task description$paths_by_category— paths grouped by category as a bullet list, or"(none specified)"when empty$task_id— task identifier
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
AgentRole
|
Agent role determining which template to load. |
required |
manifest
|
TaskManifest
|
Task manifest providing substitution values. |
required |
adapter_name
|
Optional[str]
|
Optional adapter name for adapter-specific override. |
None
|
adr_verbosity
|
AdrVerbosity
|
ADR detail level. |
NONE
|
sandbox_type
|
Optional[SandboxType]
|
Sandbox type. When |
None
|
worktree_path
|
Optional[Path]
|
Absolute path to the git worktree for this task. When provided, a Working Directory section is included instructing the agent to stay within the worktree. |
None
|
graph_yaml_path
|
Optional[Path]
|
Absolute path to the copied graph YAML at
|
None
|
signals_base_path
|
Optional[Path]
|
Absolute path to |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Resolved markdown instruction text. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no template found for a non-GENERIC role. |
ValueError
|
If GENERIC role has no description. |
Source code in src/agentrelay/agent_comm_protocol/templates.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |