multi-agent-protocol 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,292 @@
1
+ # MAP Trajectory Protocol
2
+
3
+ ## Overview
4
+
5
+ The Trajectory Protocol is an **optional extension** to MAP that adds agent work trajectory tracking. While MAP's core protocol tracks agent lifecycle and state, and Mail tracks conversations between agents, Trajectory tracks **what agents actually do** — checkpoints of work with extensible metadata.
6
+
7
+ ### Design Rationale
8
+
9
+ Multi-agent systems need observability not just into agent state (active, idle, stopped) and communication (messages, conversations), but into the **substance of agent work**:
10
+
11
+ - **Progress visibility**: What was accomplished at each milestone?
12
+ - **Cost tracking**: How many resources did an agent consume?
13
+ - **Session continuity**: What happened in previous work sessions?
14
+ - **Auditability**: A structured log of agent activity over time
15
+
16
+ Trajectory addresses these needs without changing the core agent lifecycle model. It records checkpoints — snapshots of agent work at meaningful points (task completions, session boundaries, or any agent-defined milestone).
17
+
18
+ ### Design Philosophy
19
+
20
+ Trajectory is intentionally **minimal and agent-agnostic**. The core checkpoint type carries only universal fields (id, agentId, timestamp, label, sessionId). All domain-specific data — token usage, file lists, AI summaries, VCS info, attribution — goes into a freeform `metadata` bag.
21
+
22
+ This means:
23
+ - A coding agent can store `filesTouched`, `branch`, `commitHash` in metadata
24
+ - An LLM agent can store `tokenUsage` with whatever fields its provider uses
25
+ - A research agent can store `sourcesConsulted`, `documentsGenerated`
26
+ - Any agent can attach whatever makes sense for its workflow
27
+
28
+ ### Relationship to Mail
29
+
30
+ Mail and Trajectory are **complementary**:
31
+
32
+ | Aspect | Mail | Trajectory |
33
+ |--------|------|-----------|
34
+ | **Tracks** | Conversations between participants | Individual agent work output |
35
+ | **Unit** | Turn (a message in a conversation) | Checkpoint (a snapshot of work) |
36
+ | **Content** | Text, data, events, references | Named artifacts (freeform) |
37
+ | **Trigger** | Explicit or intercepted messages | Agent-reported at meaningful milestones |
38
+ | **Primary audience** | Other agents, coordinators | Dashboards, auditors, developers |
39
+
40
+ An agent working on a task might participate in Mail conversations (coordinating with other agents) while also reporting Trajectory checkpoints (recording what work was done).
41
+
42
+ ---
43
+
44
+ ## Concepts
45
+
46
+ ### Checkpoint
47
+
48
+ A **checkpoint** is the atomic unit of trajectory tracking. It records a snapshot of agent work at a meaningful point:
49
+
50
+ - **Identity**: Which agent created it (`agentId`)
51
+ - **Timing**: When it was created (`timestamp`)
52
+ - **Label**: Human-readable description of the milestone (`label`)
53
+ - **Session**: Which work session it belongs to (`sessionId`)
54
+ - **Metadata**: Extensible key-value bag for agent-specific data (`metadata`)
55
+
56
+ Checkpoints are reported by agents via `trajectory/checkpoint` and stored server-side for querying.
57
+
58
+ ### Content
59
+
60
+ Each checkpoint may have associated **content artifacts** — named blobs of data such as session transcripts, logs, prompts, or any other agent-specific content. Artifacts are served on-demand via `trajectory/content` with support for streaming large payloads.
61
+
62
+ Artifact names are freeform strings. Well-known names include:
63
+ - `metadata` — Structured checkpoint metadata
64
+ - `transcript` — Session transcript (may be large)
65
+ - `prompts` — User prompts
66
+ - `context` — Session context
67
+
68
+ Agents may define their own artifact names as needed.
69
+
70
+ ### Content Streaming
71
+
72
+ For large artifacts, the response to `trajectory/content` indicates streaming mode:
73
+
74
+ ```
75
+ Client Server
76
+ | |
77
+ |--- trajectory/content -->| (request with id)
78
+ | |
79
+ |<-- response (streaming) -| (small artifacts inline, streamId, streamInfo)
80
+ | |
81
+ |<-- content.chunk [0] ----| (base64-encoded chunk)
82
+ |<-- content.chunk [1] ----|
83
+ |<-- content.chunk [N] ----| (final=true, checksum)
84
+ ```
85
+
86
+ Small artifacts are returned inline in the response. One large artifact per request can be streamed via chunks.
87
+
88
+ ---
89
+
90
+ ## Methods
91
+
92
+ ### trajectory/checkpoint
93
+
94
+ **Report a trajectory checkpoint.** Called by agents when they reach a meaningful milestone.
95
+
96
+ - **Tier**: Extension
97
+ - **Callable by**: Agent
98
+ - **Capability**: `trajectory.canReport`
99
+
100
+ ```typescript
101
+ // Request
102
+ {
103
+ method: "trajectory/checkpoint",
104
+ params: {
105
+ checkpoint: {
106
+ id: "a1b2c3d4e5f6",
107
+ agentId: "agent-1",
108
+ label: "Implement JWT authentication middleware",
109
+ sessionId: "sess-abc",
110
+ metadata: {
111
+ agent: "Claude Code",
112
+ branch: "feature/auth",
113
+ commitHash: "abc123def",
114
+ filesTouched: ["src/auth.ts", "src/middleware.ts"],
115
+ tokenUsage: {
116
+ inputTokens: 50000,
117
+ outputTokens: 12000
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ // Response
125
+ {
126
+ result: {
127
+ checkpoint: { /* stored checkpoint with server timestamp */ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### trajectory/list
133
+
134
+ **List trajectory checkpoints** with optional filtering and pagination.
135
+
136
+ - **Tier**: Extension
137
+ - **Callable by**: Client, Agent
138
+ - **Capability**: `trajectory.canQuery`
139
+
140
+ ```typescript
141
+ // Request
142
+ {
143
+ method: "trajectory/list",
144
+ params: {
145
+ filter: {
146
+ agentId: "agent-1",
147
+ afterTimestamp: 1706120000000
148
+ },
149
+ limit: 20
150
+ }
151
+ }
152
+
153
+ // Response
154
+ {
155
+ result: {
156
+ checkpoints: [ /* ... */ ],
157
+ hasMore: true,
158
+ nextCursor: "ckpt-xyz"
159
+ }
160
+ }
161
+ ```
162
+
163
+ ### trajectory/get
164
+
165
+ **Get a specific checkpoint** by ID.
166
+
167
+ - **Tier**: Extension
168
+ - **Callable by**: Client, Agent
169
+ - **Capability**: `trajectory.canQuery`
170
+
171
+ ### trajectory/content
172
+
173
+ **Request content artifacts** for a checkpoint. May return inline or initiate streaming.
174
+
175
+ - **Tier**: Extension
176
+ - **Callable by**: Client, Agent
177
+ - **Capability**: `trajectory.canRequestContent`
178
+
179
+ ```typescript
180
+ // Request
181
+ {
182
+ method: "trajectory/content",
183
+ params: {
184
+ checkpointId: "a1b2c3d4e5f6",
185
+ include: ["metadata", "transcript"]
186
+ }
187
+ }
188
+
189
+ // Response (inline — all artifacts fit in a single message)
190
+ {
191
+ result: {
192
+ content: {
193
+ streaming: false,
194
+ checkpointId: "a1b2c3d4e5f6",
195
+ artifacts: {
196
+ metadata: { /* structured metadata */ },
197
+ transcript: "{ ... }\n{ ... }\n"
198
+ }
199
+ }
200
+ }
201
+ }
202
+
203
+ // Response (streaming — one large artifact will arrive as chunks)
204
+ {
205
+ result: {
206
+ content: {
207
+ streaming: true,
208
+ checkpointId: "a1b2c3d4e5f6",
209
+ streamId: "stream-123",
210
+ artifacts: {
211
+ metadata: { /* inline — small */ },
212
+ prompts: "..."
213
+ },
214
+ streamArtifact: "transcript",
215
+ streamInfo: {
216
+ totalBytes: 2048000,
217
+ totalChunks: 4,
218
+ encoding: "base64"
219
+ }
220
+ }
221
+ }
222
+ }
223
+ ```
224
+
225
+ ### trajectory/content.chunk (notification)
226
+
227
+ **Content chunk** sent after a streaming content response. Not a request — no response expected.
228
+
229
+ ```typescript
230
+ {
231
+ method: "trajectory/content.chunk",
232
+ params: {
233
+ streamId: "stream-123",
234
+ index: 0,
235
+ data: "eyJ0eXBlIjoi...", // base64-encoded chunk
236
+ final: false
237
+ }
238
+ }
239
+ ```
240
+
241
+ The final chunk includes `final: true` and a `checksum` (SHA-256 of the full content).
242
+
243
+ ---
244
+
245
+ ## Events
246
+
247
+ ### trajectory.checkpoint
248
+
249
+ Emitted when an agent reports a checkpoint. Subscribe to track agent work in real-time.
250
+
251
+ ```typescript
252
+ {
253
+ type: "trajectory.checkpoint",
254
+ data: {
255
+ checkpoint: { /* TrajectoryCheckpoint */ }
256
+ },
257
+ source: { agentId: "agent-1" }
258
+ }
259
+ ```
260
+
261
+ ### trajectory.content.available
262
+
263
+ Emitted when full content for a checkpoint becomes available (e.g., after caching from a remote agent).
264
+
265
+ ---
266
+
267
+ ## Capabilities
268
+
269
+ Add `trajectory` to `ParticipantCapabilities`:
270
+
271
+ ```typescript
272
+ trajectory?: {
273
+ enabled?: boolean; // Server supports trajectory
274
+ canReport?: boolean; // Can report checkpoints
275
+ canQuery?: boolean; // Can list/get checkpoints
276
+ canRequestContent?: boolean; // Can request full content
277
+ }
278
+ ```
279
+
280
+ Advertised in `map/connect` response when the server supports trajectory tracking.
281
+
282
+ ---
283
+
284
+ ## Error Codes
285
+
286
+ | Code | Name | Description |
287
+ |------|------|-------------|
288
+ | 13000 | TRAJECTORY_NOT_ENABLED | Server does not support trajectory extension |
289
+ | 13001 | TRAJECTORY_CHECKPOINT_NOT_FOUND | Checkpoint ID not found |
290
+ | 13002 | TRAJECTORY_CONTENT_UNAVAILABLE | Content provider not configured or content not available |
291
+ | 13003 | TRAJECTORY_STREAM_FAILED | Streaming content transfer failed |
292
+ | 13004 | TRAJECTORY_PERMISSION_DENIED | Insufficient permissions for trajectory operation |