mpac 0.1.0__tar.gz
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.
- mpac-0.1.0/LICENSE +190 -0
- mpac-0.1.0/PKG-INFO +260 -0
- mpac-0.1.0/README.md +228 -0
- mpac-0.1.0/pyproject.toml +47 -0
- mpac-0.1.0/setup.cfg +4 -0
- mpac-0.1.0/src/mpac.egg-info/PKG-INFO +260 -0
- mpac-0.1.0/src/mpac.egg-info/SOURCES.txt +19 -0
- mpac-0.1.0/src/mpac.egg-info/dependency_links.txt +1 -0
- mpac-0.1.0/src/mpac.egg-info/requires.txt +2 -0
- mpac-0.1.0/src/mpac.egg-info/top_level.txt +1 -0
- mpac-0.1.0/src/mpac_protocol/__init__.py +7 -0
- mpac-0.1.0/src/mpac_protocol/agent.py +957 -0
- mpac-0.1.0/src/mpac_protocol/core/__init__.py +15 -0
- mpac-0.1.0/src/mpac_protocol/core/coordinator.py +2209 -0
- mpac-0.1.0/src/mpac_protocol/core/envelope.py +90 -0
- mpac-0.1.0/src/mpac_protocol/core/models.py +521 -0
- mpac-0.1.0/src/mpac_protocol/core/participant.py +355 -0
- mpac-0.1.0/src/mpac_protocol/core/scope.py +94 -0
- mpac-0.1.0/src/mpac_protocol/core/state_machines.py +181 -0
- mpac-0.1.0/src/mpac_protocol/core/watermark.py +50 -0
- mpac-0.1.0/src/mpac_protocol/server.py +356 -0
mpac-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Kaiyang Qian
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
mpac-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mpac
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MPAC (Multi-Principal Agent Coordination Protocol) — coordinate multiple AI agents serving different principals over shared state
|
|
5
|
+
Author-email: Kaiyang Qian <kaiyang.2.qian@ucdenver.edu>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/KaiyangQ/mpac-protocol
|
|
8
|
+
Project-URL: Repository, https://github.com/KaiyangQ/mpac-protocol
|
|
9
|
+
Project-URL: Specification, https://github.com/KaiyangQ/mpac-protocol/blob/main/SPEC.md
|
|
10
|
+
Project-URL: Two-machine demo, https://github.com/KaiyangQ/mpac-protocol/tree/main/examples/two_machine_demo
|
|
11
|
+
Project-URL: Issues, https://github.com/KaiyangQ/mpac-protocol/issues
|
|
12
|
+
Keywords: mpac,multi-agent,agent-coordination,ai-agents,llm,claude,protocol,coordination,mcp,a2a
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: websockets>=12.0
|
|
30
|
+
Requires-Dist: anthropic>=0.40.0
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# mpac-protocol
|
|
34
|
+
|
|
35
|
+
**Multi-Principal Agent Coordination Protocol — Python reference runtime.**
|
|
36
|
+
|
|
37
|
+
When multiple AI agents — each serving a different person, team, or
|
|
38
|
+
organization — need to work together over shared state, existing
|
|
39
|
+
protocols come up short. MCP standardizes how one agent invokes tools;
|
|
40
|
+
A2A standardizes how one orchestrator delegates to its own workers;
|
|
41
|
+
neither covers what happens when two agents from *different* principals
|
|
42
|
+
meet as peers over a shared repository, a shared itinerary, a shared
|
|
43
|
+
contract draft, or any other piece of state that neither principal
|
|
44
|
+
controls alone.
|
|
45
|
+
|
|
46
|
+
**MPAC** is the application-layer protocol that fills that gap. It
|
|
47
|
+
defines how agents declare intent before acting, how the coordinator
|
|
48
|
+
surfaces overlap as structured conflicts, how those conflicts get
|
|
49
|
+
resolved with explicit governance authority, and how every consequential
|
|
50
|
+
action carries causal context for after-the-fact audit across
|
|
51
|
+
organizational boundaries.
|
|
52
|
+
|
|
53
|
+
This package is the Python reference runtime: a WebSocket coordinator,
|
|
54
|
+
an interactive Claude-backed agent, and the full protocol state machine
|
|
55
|
+
from the specification.
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install mpac
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Python 3.9+ required. The package depends on `websockets` and
|
|
64
|
+
`anthropic`; bring your own Anthropic API key.
|
|
65
|
+
|
|
66
|
+
## Minimal example
|
|
67
|
+
|
|
68
|
+
Host side — start a coordinator that shares any directory on your
|
|
69
|
+
machine:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import asyncio
|
|
73
|
+
from mpac_protocol import MPACServer
|
|
74
|
+
|
|
75
|
+
async def main():
|
|
76
|
+
server = MPACServer(
|
|
77
|
+
session_id="collab-session-001",
|
|
78
|
+
host="0.0.0.0",
|
|
79
|
+
port=8766,
|
|
80
|
+
workspace_dir="/path/to/any/directory/you/want/to/share",
|
|
81
|
+
)
|
|
82
|
+
await server.run()
|
|
83
|
+
|
|
84
|
+
asyncio.run(main())
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The loader walks `workspace_dir` recursively and safely skips VCS
|
|
88
|
+
metadata (`.git`, `.hg`), build caches (`__pycache__`, `node_modules`,
|
|
89
|
+
`.venv`, `dist`, `build`, …), IDE configs, OS cruft, and binary files.
|
|
90
|
+
Whatever text files remain become the shared workspace. The pip package
|
|
91
|
+
does **not** bundle any workspace files of its own.
|
|
92
|
+
|
|
93
|
+
Guest side — connect an interactive agent to someone else's
|
|
94
|
+
coordinator:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import asyncio
|
|
98
|
+
from mpac_protocol import MPACAgent
|
|
99
|
+
|
|
100
|
+
async def main():
|
|
101
|
+
agent = MPACAgent(
|
|
102
|
+
name="Bob",
|
|
103
|
+
api_key="sk-ant-...",
|
|
104
|
+
model="claude-sonnet-4-6",
|
|
105
|
+
role_description="Collaborative AI agent operated by Bob",
|
|
106
|
+
roles=["contributor"], # optional: owner, arbiter, contributor
|
|
107
|
+
principal_id="agent:Bob", # optional: custom identity
|
|
108
|
+
)
|
|
109
|
+
await agent.connect("ws://192.168.1.42:8766", "collab-session-001")
|
|
110
|
+
await agent.run_interactive()
|
|
111
|
+
await agent.close()
|
|
112
|
+
|
|
113
|
+
asyncio.run(main())
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Two-machine worked example
|
|
117
|
+
|
|
118
|
+
A complete, copy-paste end-to-end example for two people on two
|
|
119
|
+
different computers lives in the repo at
|
|
120
|
+
[`examples/two_machine_demo/`](https://github.com/KaiyangQ/mpac-protocol/tree/main/examples/two_machine_demo).
|
|
121
|
+
It ships a host `run.py`, a guest `run.py`, a sample workspace with
|
|
122
|
+
three buggy Python files, and a README walking through both LAN mode
|
|
123
|
+
(same WiFi) and Internet mode (ngrok).
|
|
124
|
+
|
|
125
|
+
Clone and try it:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
git clone https://github.com/KaiyangQ/mpac-protocol.git mpac
|
|
129
|
+
cd mpac/examples/two_machine_demo/host
|
|
130
|
+
cp config.example.json config.json # add your Anthropic API key
|
|
131
|
+
python run.py # prints the WebSocket URL to share
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## API reference
|
|
135
|
+
|
|
136
|
+
### MPACServer
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
MPACServer(
|
|
140
|
+
session_id: str,
|
|
141
|
+
host: str = "0.0.0.0",
|
|
142
|
+
port: int = 8766,
|
|
143
|
+
workspace_dir: str | None = None, # directory to share; None = empty workspace
|
|
144
|
+
# Optional coordinator tuning (passed via **kwargs):
|
|
145
|
+
execution_model: str = "post_commit", # or "pre_commit"
|
|
146
|
+
compliance_profile: str = "core", # or "governance"
|
|
147
|
+
security_profile: str = "open", # or "authenticated", "verified"
|
|
148
|
+
unavailability_timeout_sec: float = 90.0,
|
|
149
|
+
resolution_timeout_sec: float = 300.0,
|
|
150
|
+
intent_claim_grace_sec: float = 0.0,
|
|
151
|
+
role_policy: dict | None = None,
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Call `await server.run()` to start listening. The server loads every
|
|
156
|
+
text file under `workspace_dir` into an in-memory `FileStore`, skipping
|
|
157
|
+
VCS metadata, build caches, and binary files automatically.
|
|
158
|
+
|
|
159
|
+
### MPACAgent
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
MPACAgent(
|
|
163
|
+
name: str,
|
|
164
|
+
api_key: str, # Anthropic API key
|
|
165
|
+
model: str = "claude-sonnet-4-6",
|
|
166
|
+
role_description: str | None = None,
|
|
167
|
+
roles: list[str] | None = None, # default: ["contributor"]
|
|
168
|
+
principal_id: str | None = None, # default: "agent:{name}"
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Connection
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
await agent.connect(
|
|
176
|
+
uri: str, # ws:// or wss:// — any WebSocket endpoint
|
|
177
|
+
session_id: str,
|
|
178
|
+
extra_headers: dict | None = None, # transport-specific HTTP headers
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The protocol is transport-agnostic. Pass any reachable WebSocket URI —
|
|
183
|
+
LAN address, SSH tunnel, Cloudflare Tunnel, Tailscale, or any relay
|
|
184
|
+
service. Use `extra_headers` for transports that require custom HTTP
|
|
185
|
+
headers during the handshake.
|
|
186
|
+
|
|
187
|
+
#### High-level workflows
|
|
188
|
+
|
|
189
|
+
| Method | Description |
|
|
190
|
+
|--------|------------|
|
|
191
|
+
| `run_interactive()` | Interactive CLI: view files, give tasks, see diffs |
|
|
192
|
+
| `execute_task(task)` | Programmatic: intent → conflict check → fix → commit |
|
|
193
|
+
| `run_task(task)` | Full lifecycle: HELLO → execute_task → GOODBYE |
|
|
194
|
+
|
|
195
|
+
#### Extended protocol operations
|
|
196
|
+
|
|
197
|
+
| Method | Protocol Feature |
|
|
198
|
+
|--------|-----------------|
|
|
199
|
+
| `do_propose(intent_id, op_id, target)` | Pre-commit authorization (OP_PROPOSE) |
|
|
200
|
+
| `propose_and_commit(...)` | Complete pre-commit flow (propose → auth → commit) |
|
|
201
|
+
| `do_claim_intent(...)` | Fault recovery: take over a crashed agent's intent |
|
|
202
|
+
| `do_escalate_conflict(...)` | Escalate a dispute to a designated arbiter |
|
|
203
|
+
| `do_resolve_conflict(...)` | Arbiter renders a binding resolution |
|
|
204
|
+
| `do_ack_conflict(...)` | Acknowledge or dispute a conflict |
|
|
205
|
+
| `do_heartbeat(status)` | Maintain liveness |
|
|
206
|
+
| `do_update_intent(...)` | Modify intent scope or objective mid-session |
|
|
207
|
+
|
|
208
|
+
### Lower-level building blocks
|
|
209
|
+
|
|
210
|
+
If you want to embed MPAC into your own agent runtime instead of using
|
|
211
|
+
`MPACAgent`, the `mpac_protocol.core` module exposes:
|
|
212
|
+
`SessionCoordinator`, state machines, envelopes, scope objects,
|
|
213
|
+
watermarks, and principal models.
|
|
214
|
+
|
|
215
|
+
## Protocol specification
|
|
216
|
+
|
|
217
|
+
The full normative specification is [`SPEC.md`](https://github.com/KaiyangQ/mpac-protocol/blob/main/SPEC.md)
|
|
218
|
+
on the `opensource` branch — 30 sections covering all five layers
|
|
219
|
+
(Session, Intent, Operation, Conflict, Governance), 21 message types,
|
|
220
|
+
three state machines with normative transition tables, two execution
|
|
221
|
+
models (pre-commit / post-commit), three security profiles (open /
|
|
222
|
+
authenticated / verified), Lamport-clock causal watermarking,
|
|
223
|
+
optimistic concurrency control, and Backend Health Monitoring.
|
|
224
|
+
|
|
225
|
+
The runtime in this package is faithful to that specification and is
|
|
226
|
+
cross-tested against an independent TypeScript reference implementation
|
|
227
|
+
in the same repository (14 messages exchanged bidirectionally with
|
|
228
|
+
byte-identical wire format).
|
|
229
|
+
|
|
230
|
+
## Scope — protocol, not platform
|
|
231
|
+
|
|
232
|
+
MPAC defines **what agents say to each other**: intent declarations,
|
|
233
|
+
conflict detection, resolution negotiation, causal-context commits, and
|
|
234
|
+
governance authority. It does not prescribe how the underlying network
|
|
235
|
+
is provisioned. The reference runtime uses WebSocket as a convenient
|
|
236
|
+
default transport, but the coordinator can sit behind any infrastructure
|
|
237
|
+
you choose — a LAN socket, an SSH tunnel, a cloud relay, a mesh VPN, or
|
|
238
|
+
a managed WebSocket service. Networking, deployment topology, and
|
|
239
|
+
infrastructure automation are engineering concerns outside the protocol
|
|
240
|
+
boundary; MPAC intentionally stays silent on them so that implementers
|
|
241
|
+
are free to make their own trade-offs.
|
|
242
|
+
|
|
243
|
+
## Status
|
|
244
|
+
|
|
245
|
+
**Draft / experimental.** The protocol is at v0.1.13. This package is
|
|
246
|
+
at 0.1.0. Not yet stable for production interoperability — intended for
|
|
247
|
+
reference implementations, research prototypes, and early ecosystem
|
|
248
|
+
feedback.
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
Apache-2.0. See [`LICENSE`](https://github.com/KaiyangQ/mpac-protocol/blob/main/LICENSE).
|
|
253
|
+
|
|
254
|
+
## Links
|
|
255
|
+
|
|
256
|
+
- [GitHub repository](https://github.com/KaiyangQ/mpac-protocol)
|
|
257
|
+
- [v0.1.13 release notes](https://github.com/KaiyangQ/mpac-protocol/releases/tag/v0.1.13)
|
|
258
|
+
- [Specification (SPEC.md)](https://github.com/KaiyangQ/mpac-protocol/blob/main/SPEC.md)
|
|
259
|
+
- [Two-machine demo](https://github.com/KaiyangQ/mpac-protocol/tree/main/examples/two_machine_demo)
|
|
260
|
+
- [Report an issue](https://github.com/KaiyangQ/mpac-protocol/issues)
|
mpac-0.1.0/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# mpac-protocol
|
|
2
|
+
|
|
3
|
+
**Multi-Principal Agent Coordination Protocol — Python reference runtime.**
|
|
4
|
+
|
|
5
|
+
When multiple AI agents — each serving a different person, team, or
|
|
6
|
+
organization — need to work together over shared state, existing
|
|
7
|
+
protocols come up short. MCP standardizes how one agent invokes tools;
|
|
8
|
+
A2A standardizes how one orchestrator delegates to its own workers;
|
|
9
|
+
neither covers what happens when two agents from *different* principals
|
|
10
|
+
meet as peers over a shared repository, a shared itinerary, a shared
|
|
11
|
+
contract draft, or any other piece of state that neither principal
|
|
12
|
+
controls alone.
|
|
13
|
+
|
|
14
|
+
**MPAC** is the application-layer protocol that fills that gap. It
|
|
15
|
+
defines how agents declare intent before acting, how the coordinator
|
|
16
|
+
surfaces overlap as structured conflicts, how those conflicts get
|
|
17
|
+
resolved with explicit governance authority, and how every consequential
|
|
18
|
+
action carries causal context for after-the-fact audit across
|
|
19
|
+
organizational boundaries.
|
|
20
|
+
|
|
21
|
+
This package is the Python reference runtime: a WebSocket coordinator,
|
|
22
|
+
an interactive Claude-backed agent, and the full protocol state machine
|
|
23
|
+
from the specification.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install mpac
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Python 3.9+ required. The package depends on `websockets` and
|
|
32
|
+
`anthropic`; bring your own Anthropic API key.
|
|
33
|
+
|
|
34
|
+
## Minimal example
|
|
35
|
+
|
|
36
|
+
Host side — start a coordinator that shares any directory on your
|
|
37
|
+
machine:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import asyncio
|
|
41
|
+
from mpac_protocol import MPACServer
|
|
42
|
+
|
|
43
|
+
async def main():
|
|
44
|
+
server = MPACServer(
|
|
45
|
+
session_id="collab-session-001",
|
|
46
|
+
host="0.0.0.0",
|
|
47
|
+
port=8766,
|
|
48
|
+
workspace_dir="/path/to/any/directory/you/want/to/share",
|
|
49
|
+
)
|
|
50
|
+
await server.run()
|
|
51
|
+
|
|
52
|
+
asyncio.run(main())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The loader walks `workspace_dir` recursively and safely skips VCS
|
|
56
|
+
metadata (`.git`, `.hg`), build caches (`__pycache__`, `node_modules`,
|
|
57
|
+
`.venv`, `dist`, `build`, …), IDE configs, OS cruft, and binary files.
|
|
58
|
+
Whatever text files remain become the shared workspace. The pip package
|
|
59
|
+
does **not** bundle any workspace files of its own.
|
|
60
|
+
|
|
61
|
+
Guest side — connect an interactive agent to someone else's
|
|
62
|
+
coordinator:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import asyncio
|
|
66
|
+
from mpac_protocol import MPACAgent
|
|
67
|
+
|
|
68
|
+
async def main():
|
|
69
|
+
agent = MPACAgent(
|
|
70
|
+
name="Bob",
|
|
71
|
+
api_key="sk-ant-...",
|
|
72
|
+
model="claude-sonnet-4-6",
|
|
73
|
+
role_description="Collaborative AI agent operated by Bob",
|
|
74
|
+
roles=["contributor"], # optional: owner, arbiter, contributor
|
|
75
|
+
principal_id="agent:Bob", # optional: custom identity
|
|
76
|
+
)
|
|
77
|
+
await agent.connect("ws://192.168.1.42:8766", "collab-session-001")
|
|
78
|
+
await agent.run_interactive()
|
|
79
|
+
await agent.close()
|
|
80
|
+
|
|
81
|
+
asyncio.run(main())
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Two-machine worked example
|
|
85
|
+
|
|
86
|
+
A complete, copy-paste end-to-end example for two people on two
|
|
87
|
+
different computers lives in the repo at
|
|
88
|
+
[`examples/two_machine_demo/`](https://github.com/KaiyangQ/mpac-protocol/tree/main/examples/two_machine_demo).
|
|
89
|
+
It ships a host `run.py`, a guest `run.py`, a sample workspace with
|
|
90
|
+
three buggy Python files, and a README walking through both LAN mode
|
|
91
|
+
(same WiFi) and Internet mode (ngrok).
|
|
92
|
+
|
|
93
|
+
Clone and try it:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/KaiyangQ/mpac-protocol.git mpac
|
|
97
|
+
cd mpac/examples/two_machine_demo/host
|
|
98
|
+
cp config.example.json config.json # add your Anthropic API key
|
|
99
|
+
python run.py # prints the WebSocket URL to share
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## API reference
|
|
103
|
+
|
|
104
|
+
### MPACServer
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
MPACServer(
|
|
108
|
+
session_id: str,
|
|
109
|
+
host: str = "0.0.0.0",
|
|
110
|
+
port: int = 8766,
|
|
111
|
+
workspace_dir: str | None = None, # directory to share; None = empty workspace
|
|
112
|
+
# Optional coordinator tuning (passed via **kwargs):
|
|
113
|
+
execution_model: str = "post_commit", # or "pre_commit"
|
|
114
|
+
compliance_profile: str = "core", # or "governance"
|
|
115
|
+
security_profile: str = "open", # or "authenticated", "verified"
|
|
116
|
+
unavailability_timeout_sec: float = 90.0,
|
|
117
|
+
resolution_timeout_sec: float = 300.0,
|
|
118
|
+
intent_claim_grace_sec: float = 0.0,
|
|
119
|
+
role_policy: dict | None = None,
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Call `await server.run()` to start listening. The server loads every
|
|
124
|
+
text file under `workspace_dir` into an in-memory `FileStore`, skipping
|
|
125
|
+
VCS metadata, build caches, and binary files automatically.
|
|
126
|
+
|
|
127
|
+
### MPACAgent
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
MPACAgent(
|
|
131
|
+
name: str,
|
|
132
|
+
api_key: str, # Anthropic API key
|
|
133
|
+
model: str = "claude-sonnet-4-6",
|
|
134
|
+
role_description: str | None = None,
|
|
135
|
+
roles: list[str] | None = None, # default: ["contributor"]
|
|
136
|
+
principal_id: str | None = None, # default: "agent:{name}"
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Connection
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
await agent.connect(
|
|
144
|
+
uri: str, # ws:// or wss:// — any WebSocket endpoint
|
|
145
|
+
session_id: str,
|
|
146
|
+
extra_headers: dict | None = None, # transport-specific HTTP headers
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The protocol is transport-agnostic. Pass any reachable WebSocket URI —
|
|
151
|
+
LAN address, SSH tunnel, Cloudflare Tunnel, Tailscale, or any relay
|
|
152
|
+
service. Use `extra_headers` for transports that require custom HTTP
|
|
153
|
+
headers during the handshake.
|
|
154
|
+
|
|
155
|
+
#### High-level workflows
|
|
156
|
+
|
|
157
|
+
| Method | Description |
|
|
158
|
+
|--------|------------|
|
|
159
|
+
| `run_interactive()` | Interactive CLI: view files, give tasks, see diffs |
|
|
160
|
+
| `execute_task(task)` | Programmatic: intent → conflict check → fix → commit |
|
|
161
|
+
| `run_task(task)` | Full lifecycle: HELLO → execute_task → GOODBYE |
|
|
162
|
+
|
|
163
|
+
#### Extended protocol operations
|
|
164
|
+
|
|
165
|
+
| Method | Protocol Feature |
|
|
166
|
+
|--------|-----------------|
|
|
167
|
+
| `do_propose(intent_id, op_id, target)` | Pre-commit authorization (OP_PROPOSE) |
|
|
168
|
+
| `propose_and_commit(...)` | Complete pre-commit flow (propose → auth → commit) |
|
|
169
|
+
| `do_claim_intent(...)` | Fault recovery: take over a crashed agent's intent |
|
|
170
|
+
| `do_escalate_conflict(...)` | Escalate a dispute to a designated arbiter |
|
|
171
|
+
| `do_resolve_conflict(...)` | Arbiter renders a binding resolution |
|
|
172
|
+
| `do_ack_conflict(...)` | Acknowledge or dispute a conflict |
|
|
173
|
+
| `do_heartbeat(status)` | Maintain liveness |
|
|
174
|
+
| `do_update_intent(...)` | Modify intent scope or objective mid-session |
|
|
175
|
+
|
|
176
|
+
### Lower-level building blocks
|
|
177
|
+
|
|
178
|
+
If you want to embed MPAC into your own agent runtime instead of using
|
|
179
|
+
`MPACAgent`, the `mpac_protocol.core` module exposes:
|
|
180
|
+
`SessionCoordinator`, state machines, envelopes, scope objects,
|
|
181
|
+
watermarks, and principal models.
|
|
182
|
+
|
|
183
|
+
## Protocol specification
|
|
184
|
+
|
|
185
|
+
The full normative specification is [`SPEC.md`](https://github.com/KaiyangQ/mpac-protocol/blob/main/SPEC.md)
|
|
186
|
+
on the `opensource` branch — 30 sections covering all five layers
|
|
187
|
+
(Session, Intent, Operation, Conflict, Governance), 21 message types,
|
|
188
|
+
three state machines with normative transition tables, two execution
|
|
189
|
+
models (pre-commit / post-commit), three security profiles (open /
|
|
190
|
+
authenticated / verified), Lamport-clock causal watermarking,
|
|
191
|
+
optimistic concurrency control, and Backend Health Monitoring.
|
|
192
|
+
|
|
193
|
+
The runtime in this package is faithful to that specification and is
|
|
194
|
+
cross-tested against an independent TypeScript reference implementation
|
|
195
|
+
in the same repository (14 messages exchanged bidirectionally with
|
|
196
|
+
byte-identical wire format).
|
|
197
|
+
|
|
198
|
+
## Scope — protocol, not platform
|
|
199
|
+
|
|
200
|
+
MPAC defines **what agents say to each other**: intent declarations,
|
|
201
|
+
conflict detection, resolution negotiation, causal-context commits, and
|
|
202
|
+
governance authority. It does not prescribe how the underlying network
|
|
203
|
+
is provisioned. The reference runtime uses WebSocket as a convenient
|
|
204
|
+
default transport, but the coordinator can sit behind any infrastructure
|
|
205
|
+
you choose — a LAN socket, an SSH tunnel, a cloud relay, a mesh VPN, or
|
|
206
|
+
a managed WebSocket service. Networking, deployment topology, and
|
|
207
|
+
infrastructure automation are engineering concerns outside the protocol
|
|
208
|
+
boundary; MPAC intentionally stays silent on them so that implementers
|
|
209
|
+
are free to make their own trade-offs.
|
|
210
|
+
|
|
211
|
+
## Status
|
|
212
|
+
|
|
213
|
+
**Draft / experimental.** The protocol is at v0.1.13. This package is
|
|
214
|
+
at 0.1.0. Not yet stable for production interoperability — intended for
|
|
215
|
+
reference implementations, research prototypes, and early ecosystem
|
|
216
|
+
feedback.
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
Apache-2.0. See [`LICENSE`](https://github.com/KaiyangQ/mpac-protocol/blob/main/LICENSE).
|
|
221
|
+
|
|
222
|
+
## Links
|
|
223
|
+
|
|
224
|
+
- [GitHub repository](https://github.com/KaiyangQ/mpac-protocol)
|
|
225
|
+
- [v0.1.13 release notes](https://github.com/KaiyangQ/mpac-protocol/releases/tag/v0.1.13)
|
|
226
|
+
- [Specification (SPEC.md)](https://github.com/KaiyangQ/mpac-protocol/blob/main/SPEC.md)
|
|
227
|
+
- [Two-machine demo](https://github.com/KaiyangQ/mpac-protocol/tree/main/examples/two_machine_demo)
|
|
228
|
+
- [Report an issue](https://github.com/KaiyangQ/mpac-protocol/issues)
|