multi-agent-protocol 0.0.3 → 0.0.6

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,242 @@
1
+ # Environment Awareness
2
+
3
+ ## Overview
4
+
5
+ Environment awareness enables agents to advertise and discover information about their compute environments. This facilitates intelligent task routing, filesystem coordination, and resource-aware scheduling in heterogeneous multi-agent systems.
6
+
7
+ ## Motivation
8
+
9
+ Agents may run across diverse environments:
10
+ - Different mount points (Agent A at `/home/user/project`, Agent B at `/workspace/project`)
11
+ - Different compute types (local, Docker, Kubernetes, cloud sandbox)
12
+ - Different capabilities (GPU, specific tools, network access)
13
+ - Different constraints (memory limits, ephemeral storage, execution timeouts)
14
+
15
+ Environment awareness enables:
16
+ - **Task routing**: Send GPU workloads to GPU-enabled agents
17
+ - **Filesystem coordination**: Detect shared mounts vs. need for explicit file transfer
18
+ - **Resource optimization**: Choose agents based on cost, latency, or capacity
19
+ - **Security boundaries**: Route sensitive data to appropriately isolated agents
20
+
21
+ ## Schema
22
+
23
+ The `AgentEnvironment` type uses a layered approach:
24
+
25
+ - **Layer 1 (Normative)**: Category names are standardized
26
+ - **Layer 2 (Conventions)**: Field names within categories are recommended patterns
27
+ - **Layer 3 (Extensions)**: Custom fields allowed via `additionalProperties`
28
+
29
+ ```typescript
30
+ interface AgentEnvironment {
31
+ schemaVersion?: string; // Schema version (e.g., "1.0")
32
+ profiles?: string[]; // Self-declared compliance (e.g., ["cloud-native"])
33
+
34
+ // Standard categories (all optional, all extensible)
35
+ host?: Record<string, unknown>; // CPU, memory, GPU
36
+ os?: Record<string, unknown>; // OS type, version
37
+ process?: Record<string, unknown>; // PID, cwd, runtime
38
+ container?: Record<string, unknown>; // Container runtime info
39
+ cloud?: Record<string, unknown>; // Provider, region, instance type
40
+ k8s?: Record<string, unknown>; // Kubernetes context
41
+ filesystem?: Record<string, unknown>; // Mounts, workspace, VCS
42
+ network?: Record<string, unknown>; // Connectivity, addresses
43
+ tools?: Record<string, unknown>; // Installed tools, runtimes
44
+ resources?: Record<string, unknown>; // Limits and constraints
45
+ security?: Record<string, unknown>; // Isolation, compliance
46
+ services?: Record<string, unknown>; // External APIs, MCP servers
47
+
48
+ [key: string]: unknown; // Additional categories allowed
49
+ }
50
+ ```
51
+
52
+ ## Common Field Conventions
53
+
54
+ These field names are **recommended** (not required) for interoperability:
55
+
56
+ | Category | Common Fields |
57
+ |----------|--------------|
58
+ | `host` | `arch`, `cpuCount`, `memoryBytes`, `gpu.count`, `gpu.models` |
59
+ | `os` | `type` (linux/darwin/windows), `version`, `name` |
60
+ | `process` | `pid`, `cwd`, `runtimeName`, `runtimeVersion` |
61
+ | `cloud` | `provider`, `region`, `instanceType`, `accountId` |
62
+ | `network` | `connectivity` (full/restricted/internal/isolated), `addresses` |
63
+ | `filesystem` | `cwd`, `mounts`, `workspace.root`, `workspace.vcs`, `workspace.branch` |
64
+ | `tools` | `installed`, `shell`, `runtimes`, `canInstall` |
65
+ | `resources` | `cpuLimit`, `memoryLimitBytes`, `maxExecutionSeconds`, `costProfile` |
66
+ | `security` | `isolation`, `privileged`, `sandbox`, `dataResidency` |
67
+ | `services` | `aiProviders`, `mcp` (MCP servers) |
68
+
69
+ ## Protocol Integration
70
+
71
+ ### Agent Registration
72
+
73
+ ```typescript
74
+ await connection.register({
75
+ name: 'my-agent',
76
+ environment: {
77
+ schemaVersion: '1.0',
78
+ os: { type: 'linux', version: '22.04' },
79
+ process: { cwd: '/home/user/project' },
80
+ network: { connectivity: 'full' },
81
+ tools: {
82
+ installed: { python: '3.11', node: '20.0' },
83
+ shell: 'bash'
84
+ }
85
+ }
86
+ });
87
+ ```
88
+
89
+ ### Connect Response
90
+
91
+ Servers can advertise their environment:
92
+
93
+ ```typescript
94
+ interface ConnectResponse {
95
+ // ... existing fields
96
+ serverEnvironment?: AgentEnvironment;
97
+ }
98
+ ```
99
+
100
+ ### Environment Updates
101
+
102
+ Agents can update their environment via `map/agents/update`:
103
+
104
+ ```typescript
105
+ await connection.update({
106
+ agentId: myAgentId,
107
+ environment: {
108
+ resources: { memoryLimitBytes: 8589934592 } // Updated
109
+ }
110
+ });
111
+ ```
112
+
113
+ ### Event: `agent_environment_changed`
114
+
115
+ Emitted when an agent's environment changes:
116
+
117
+ ```typescript
118
+ {
119
+ type: 'agent_environment_changed',
120
+ data: {
121
+ agentId: 'agent-123',
122
+ environment: { /* current */ },
123
+ previousEnvironment: { /* previous */ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ ### Subscription Filtering
129
+
130
+ Filter events by environment attributes:
131
+
132
+ ```typescript
133
+ await client.subscribe({
134
+ filter: {
135
+ eventTypes: ['agent_registered'],
136
+ environmentMatch: {
137
+ 'os.type': 'linux',
138
+ 'cloud.provider': 'aws'
139
+ }
140
+ }
141
+ });
142
+ ```
143
+
144
+ ## Extension Patterns
145
+
146
+ ### Adding fields to categories
147
+
148
+ ```json
149
+ {
150
+ "host": {
151
+ "arch": "arm64",
152
+ "memoryBytes": 17179869184,
153
+ "x-apple-silicon": { "chip": "M2 Pro" }
154
+ }
155
+ }
156
+ ```
157
+
158
+ ### Adding new categories
159
+
160
+ ```json
161
+ {
162
+ "schemaVersion": "1.0",
163
+ "os": { "type": "linux" },
164
+ "x-anthropic-sandbox": {
165
+ "sandboxId": "sb-abc123",
166
+ "tier": "premium"
167
+ }
168
+ }
169
+ ```
170
+
171
+ ### Services with custom providers
172
+
173
+ ```json
174
+ {
175
+ "services": {
176
+ "aiProviders": {
177
+ "huggingface": { "available": true, "tier": "pro" },
178
+ "openai": { "available": true }
179
+ },
180
+ "mcp": {
181
+ "filesystem": { "available": true, "tools": ["read_file", "write_file"] }
182
+ },
183
+ "x-internal": {
184
+ "userService": { "available": true }
185
+ }
186
+ }
187
+ }
188
+ ```
189
+
190
+ ## Use Cases
191
+
192
+ ### Task Routing by Capability
193
+
194
+ ```typescript
195
+ const agents = await client.agents.list();
196
+ const gpuAgent = agents.find(a =>
197
+ a.environment?.host?.gpu?.count > 0
198
+ );
199
+ if (gpuAgent) {
200
+ await client.send({ to: gpuAgent.id, payload: mlTask });
201
+ }
202
+ ```
203
+
204
+ ### Filesystem Coordination
205
+
206
+ ```typescript
207
+ // Check if agents share a filesystem
208
+ const myMounts = myAgent.environment?.filesystem?.mounts ?? {};
209
+ const peerMounts = peerAgent.environment?.filesystem?.mounts ?? {};
210
+
211
+ const sharedMount = Object.keys(myMounts).find(name =>
212
+ myMounts[name]?.shared && peerMounts[name]?.shared
213
+ );
214
+
215
+ if (sharedMount) {
216
+ // Can use file paths directly
217
+ } else {
218
+ // Need to transfer file contents via messages
219
+ }
220
+ ```
221
+
222
+ ### Network-Aware Routing
223
+
224
+ ```typescript
225
+ const agents = await client.agents.list();
226
+ const internetAgent = agents.find(a =>
227
+ a.environment?.network?.connectivity === 'full'
228
+ );
229
+ // Route external API calls through this agent
230
+ ```
231
+
232
+ ## Security Considerations
233
+
234
+ 1. **Sensitive data**: Filter environment variables before exposing (no API keys, tokens)
235
+ 2. **Opt-in exposure**: Agents explicitly choose what to advertise
236
+ 3. **Visibility rules**: Environment respects existing MAP visibility/permissions
237
+ 4. **Trust boundaries**: Don't implicitly trust environment claims from untrusted agents
238
+
239
+ ## References
240
+
241
+ - [OpenTelemetry Resource Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/resource/)
242
+ - [Kubernetes Node Feature Discovery](https://kubernetes-sigs.github.io/node-feature-discovery/)