cosmonapse 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.
Files changed (51) hide show
  1. cosmonapse-0.1.0/.gitignore +73 -0
  2. cosmonapse-0.1.0/PKG-INFO +232 -0
  3. cosmonapse-0.1.0/README.md +202 -0
  4. cosmonapse-0.1.0/cosmo/__init__.py +0 -0
  5. cosmonapse-0.1.0/cosmo/_install.py +225 -0
  6. cosmonapse-0.1.0/cosmo/commands/__init__.py +0 -0
  7. cosmonapse-0.1.0/cosmo/commands/_prism.py +310 -0
  8. cosmonapse-0.1.0/cosmo/commands/_prism_hero.py +249 -0
  9. cosmonapse-0.1.0/cosmo/commands/_prism_view.py +550 -0
  10. cosmonapse-0.1.0/cosmo/commands/_shared.py +112 -0
  11. cosmonapse-0.1.0/cosmo/commands/completion.py +79 -0
  12. cosmonapse-0.1.0/cosmo/commands/doppler.py +343 -0
  13. cosmonapse-0.1.0/cosmo/commands/init.py +270 -0
  14. cosmonapse-0.1.0/cosmo/commands/prism_dist/assets/index.css +1 -0
  15. cosmonapse-0.1.0/cosmo/commands/prism_dist/assets/mark.png +0 -0
  16. cosmonapse-0.1.0/cosmo/commands/prism_dist/assets/prism.js +40 -0
  17. cosmonapse-0.1.0/cosmo/commands/prism_dist/index.html +14 -0
  18. cosmonapse-0.1.0/cosmo/commands/prism_dist/mark.png +0 -0
  19. cosmonapse-0.1.0/cosmo/commands/synapse.py +690 -0
  20. cosmonapse-0.1.0/cosmo/commands/validate.py +278 -0
  21. cosmonapse-0.1.0/cosmo/main.py +36 -0
  22. cosmonapse-0.1.0/cosmonapse/__init__.py +242 -0
  23. cosmonapse-0.1.0/cosmonapse/_hooks.py +233 -0
  24. cosmonapse-0.1.0/cosmonapse/_neuron_base.py +82 -0
  25. cosmonapse-0.1.0/cosmonapse/_neuron_http.py +184 -0
  26. cosmonapse-0.1.0/cosmonapse/_neuron_mcp.py +365 -0
  27. cosmonapse-0.1.0/cosmonapse/_url.py +72 -0
  28. cosmonapse-0.1.0/cosmonapse/axon.py +297 -0
  29. cosmonapse-0.1.0/cosmonapse/dendrite.py +1976 -0
  30. cosmonapse-0.1.0/cosmonapse/engram/__init__.py +57 -0
  31. cosmonapse-0.1.0/cosmonapse/engram/base.py +231 -0
  32. cosmonapse-0.1.0/cosmonapse/engram/client.py +373 -0
  33. cosmonapse-0.1.0/cosmonapse/engram/memory.py +377 -0
  34. cosmonapse-0.1.0/cosmonapse/engram/postgres.py +423 -0
  35. cosmonapse-0.1.0/cosmonapse/engram/sqlite.py +457 -0
  36. cosmonapse-0.1.0/cosmonapse/envelope.py +1287 -0
  37. cosmonapse-0.1.0/cosmonapse/neuron.py +372 -0
  38. cosmonapse-0.1.0/cosmonapse/pathway.py +385 -0
  39. cosmonapse-0.1.0/cosmonapse/py.typed +0 -0
  40. cosmonapse-0.1.0/cosmonapse/storage/__init__.py +33 -0
  41. cosmonapse-0.1.0/cosmonapse/storage/base.py +113 -0
  42. cosmonapse-0.1.0/cosmonapse/storage/memory.py +73 -0
  43. cosmonapse-0.1.0/cosmonapse/storage/postgres.py +214 -0
  44. cosmonapse-0.1.0/cosmonapse/storage/sqlite.py +233 -0
  45. cosmonapse-0.1.0/cosmonapse/synapse/__init__.py +32 -0
  46. cosmonapse-0.1.0/cosmonapse/synapse/base.py +96 -0
  47. cosmonapse-0.1.0/cosmonapse/synapse/dev.py +560 -0
  48. cosmonapse-0.1.0/cosmonapse/synapse/kafka.py +288 -0
  49. cosmonapse-0.1.0/cosmonapse/synapse/memory.py +207 -0
  50. cosmonapse-0.1.0/cosmonapse/synapse/nats.py +161 -0
  51. cosmonapse-0.1.0/pyproject.toml +94 -0
@@ -0,0 +1,73 @@
1
+ # ---------------------------------------------------------------------------
2
+ # Python
3
+ # ---------------------------------------------------------------------------
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ *.so
8
+ .Python
9
+ build/
10
+ develop-eggs/
11
+ dist/
12
+ downloads/
13
+ eggs/
14
+ .eggs/
15
+ lib/
16
+ lib64/
17
+ parts/
18
+ sdist/
19
+ var/
20
+ wheels/
21
+ share/python-wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+ MANIFEST
26
+
27
+ # Virtual environments
28
+ .venv/
29
+ venv/
30
+ env/
31
+ ENV/
32
+ .python-version
33
+
34
+ # Test / coverage / type-check caches
35
+ .pytest_cache/
36
+ .mypy_cache/
37
+ .ruff_cache/
38
+ .coverage
39
+ .coverage.*
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ coverage.xml
44
+ *.cover
45
+
46
+ # ---------------------------------------------------------------------------
47
+ # Node / web (cosmonapse-landing-page, ts-sdk)
48
+ # ---------------------------------------------------------------------------
49
+ node_modules/
50
+ .next/
51
+ out/
52
+ *.tsbuildinfo
53
+ npm-debug.log*
54
+ yarn-debug.log*
55
+ yarn-error.log*
56
+ .pnpm-debug.log*
57
+
58
+ # ---------------------------------------------------------------------------
59
+ # Editors / OS
60
+ # ---------------------------------------------------------------------------
61
+ .idea/
62
+ .vscode/
63
+ *.swp
64
+ *~
65
+ .DS_Store
66
+ Thumbs.db
67
+
68
+ # ---------------------------------------------------------------------------
69
+ # Local secrets / env
70
+ # ---------------------------------------------------------------------------
71
+ .env
72
+ .env.*
73
+ !.env.example
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: cosmonapse
3
+ Version: 0.1.0
4
+ Summary: Event-driven Agent-to-Agent protocol SDK and developer CLI
5
+ License: MIT
6
+ Keywords: a2a,agents,multi-agent,protocol
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: aiohttp>=3.9
9
+ Requires-Dist: click>=8.1
10
+ Requires-Dist: pydantic>=2.0
11
+ Requires-Dist: python-ulid>=2.0
12
+ Requires-Dist: rich>=13.0
13
+ Provides-Extra: dev
14
+ Requires-Dist: aiokafka>=0.10; extra == 'dev'
15
+ Requires-Dist: asyncpg>=0.29; extra == 'dev'
16
+ Requires-Dist: flask>=3.0; extra == 'dev'
17
+ Requires-Dist: mypy>=1.9; extra == 'dev'
18
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
19
+ Requires-Dist: pytest>=8.0; extra == 'dev'
20
+ Requires-Dist: ruff>=0.4; extra == 'dev'
21
+ Provides-Extra: flask
22
+ Requires-Dist: flask>=3.0; extra == 'flask'
23
+ Provides-Extra: kafka
24
+ Requires-Dist: aiokafka>=0.10; extra == 'kafka'
25
+ Provides-Extra: nats
26
+ Requires-Dist: nats-py>=2.3; extra == 'nats'
27
+ Provides-Extra: postgres
28
+ Requires-Dist: asyncpg>=0.29; extra == 'postgres'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # cosmonapse
32
+
33
+ Event-driven Agent-to-Agent protocol SDK for Python.
34
+
35
+ **v0.1.0** — Python 3.11+ · MIT
36
+
37
+ ---
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install cosmonapse
43
+
44
+ # Optional synapse adapters
45
+ pip install "cosmonapse[nats]" # NATS transport
46
+ pip install "cosmonapse[kafka]" # Kafka transport (aiokafka)
47
+
48
+ # Optional storage backend
49
+ pip install "cosmonapse[postgres]" # Postgres registry store (asyncpg)
50
+
51
+ # Optional Flask / WSGI Neuron factory
52
+ pip install "cosmonapse[flask]"
53
+
54
+ # Provider-backed Neurons (Ollama / HuggingFace) need httpx
55
+ pip install httpx
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Quick start
61
+
62
+ ```python
63
+ import asyncio
64
+ from cosmonapse import (
65
+ Axon, Dendrite, Neuron,
66
+ MemoryRegistryStore,
67
+ connect_synapse,
68
+ )
69
+
70
+ async def main():
71
+ # 1. Connect to a running synapse (cosmo synapse start memory)
72
+ synapse = await connect_synapse("cosmo://127.0.0.1:7070")
73
+ try:
74
+ # 2. Define a pure agent function (zero protocol knowledge)
75
+ async def my_agent(input, context):
76
+ return {"answer": f"You asked: {input['q']}"}
77
+
78
+ # -- Worker Dendrite: hosts an Axon --------------------------
79
+ worker = Dendrite(synapse=synapse, namespace="demo")
80
+ worker.attach_axon(Axon(neuron_id="answerer", neuron_fn=my_agent))
81
+
82
+ # -- Orchestrator Dendrite: drives the workflow ---------------
83
+ orch = Dendrite(
84
+ synapse=synapse,
85
+ registry_store=MemoryRegistryStore(),
86
+ namespace="demo",
87
+ )
88
+
89
+ @orch.on_agent_output
90
+ async def done(sig):
91
+ print("Got answer:", sig.payload["output"])
92
+ await orch.emit_final(
93
+ trace_id=sig.trace_id,
94
+ parent_id=sig.id,
95
+ result=sig.payload["output"],
96
+ )
97
+
98
+ async with orch, worker:
99
+ await orch.dispatch_task(neuron="answerer", input={"q": "hi"})
100
+ await asyncio.sleep(0.5)
101
+ finally:
102
+ await synapse.close()
103
+
104
+ asyncio.run(main())
105
+ ```
106
+
107
+ Start the dev synapse first:
108
+
109
+ ```bash
110
+ cosmo synapse start memory --namespace=demo
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Provider-backed Neurons
116
+
117
+ Drop an LLM into any workflow with `Neuron(source=...)`:
118
+
119
+ ```python
120
+ from cosmonapse import Axon, Neuron
121
+
122
+ # Local Ollama daemon
123
+ axon = Axon(
124
+ neuron_id="chat",
125
+ neuron_fn=Neuron(source="ollama", model="llama3"),
126
+ )
127
+
128
+ # HuggingFace TGI / vLLM / llama.cpp / LM Studio
129
+ axon = Axon(
130
+ neuron_id="summariser",
131
+ neuron_fn=Neuron(
132
+ source="huggingface",
133
+ endpoint="http://localhost:8080",
134
+ ),
135
+ )
136
+
137
+ # HuggingFace hosted endpoint (requires api_key)
138
+ axon = Axon(
139
+ neuron_id="classifier",
140
+ neuron_fn=Neuron(
141
+ source="huggingface",
142
+ endpoint="https://<your-endpoint>.endpoints.huggingface.cloud",
143
+ api_key="hf_…",
144
+ use_chat_api=True,
145
+ ),
146
+ )
147
+ ```
148
+
149
+ `Neuron(...)` returns an async callable satisfying `NeuronFn`. Pass `prompt` or
150
+ `messages` (OpenAI-style) in the task input. Output is always
151
+ `{"response": "<text>", "meta": <raw provider payload>}`.
152
+
153
+ Requires `httpx` (`pip install httpx`).
154
+
155
+ ---
156
+
157
+ ## Synapse adapters
158
+
159
+ | Import | Use when |
160
+ |---|---|
161
+ | `MemorySynapse` | tests, single-process |
162
+ | `DevSynapse` | multi-process dev on one host (`cosmo synapse start memory`) |
163
+ | `NatsSynapse` | production default (`pip install cosmonapse[nats]`) |
164
+ | `KafkaSynapse` | durable audit log (`pip install "cosmonapse[kafka]"`) |
165
+
166
+ URL factory:
167
+
168
+ ```python
169
+ from cosmonapse import connect_synapse, synapse_from_url
170
+
171
+ synapse = await connect_synapse("cosmo://127.0.0.1:7070") # DevSynapse
172
+ synapse = await connect_synapse("nats://nats:4222") # NatsSynapse
173
+ synapse = await connect_synapse("kafka://broker:9092") # KafkaSynapse
174
+ ```
175
+
176
+ For `MemorySynapse`, construct directly:
177
+
178
+ ```python
179
+ from cosmonapse import MemorySynapse
180
+ synapse = MemorySynapse()
181
+ await synapse.connect()
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Storage backends
187
+
188
+ | Import | Use when |
189
+ |---|---|
190
+ | `MemoryRegistryStore` | tests, ephemeral orchestrators |
191
+ | `SqliteRegistryStore` | single-process production, zero extra deps |
192
+ | `PostgresRegistryStore` | multi-process production (`pip install "cosmonapse[postgres]"`) |
193
+
194
+ ---
195
+
196
+ ## CLI
197
+
198
+ ```bash
199
+ # Start a local dev synapse (TCP + NDJSON)
200
+ cosmo synapse start memory --namespace=dev
201
+
202
+ # View active namespaces
203
+ cosmo synapse view --url=cosmo://127.0.0.1:7070
204
+
205
+ # Stream signals for one namespace
206
+ cosmo synapse view --url=cosmo://127.0.0.1:7070 --namespace=dev
207
+
208
+ # Stop a namespace
209
+ cosmo synapse stop --url=cosmo://127.0.0.1:7070 --namespace=dev
210
+
211
+ # Passive signal watcher (Doppler)
212
+ cosmo doppler --url=cosmo://127.0.0.1:7070 --namespace=dev
213
+
214
+ # Validate envelope conformance
215
+ cosmo validate --url=cosmo://127.0.0.1:7070 --namespace=dev
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Key concepts
221
+
222
+ | Term | What it is |
223
+ |---|---|
224
+ | **Neuron** | A pure async function — zero protocol knowledge |
225
+ | **Axon** | Agent-side wrapper that turns Neuron output into Signals |
226
+ | **Dendrite** | Synapse-side participant; hosts Axons, handles routing, orchestration |
227
+ | **Cortex** | Back-compat alias for `Dendrite` |
228
+ | **Synapse** | The message transport (memory / dev TCP / NATS / Kafka) |
229
+ | **Signal** | An envelope crossing the Synapse |
230
+ | **RegistryStore** | Live view of Neurons seen on a namespace |
231
+
232
+ See `design/SDK_DESIGN.md` for the full design document and `design/ENVELOPE_SPEC.md` for the wire protocol.
@@ -0,0 +1,202 @@
1
+ # cosmonapse
2
+
3
+ Event-driven Agent-to-Agent protocol SDK for Python.
4
+
5
+ **v0.1.0** — Python 3.11+ · MIT
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install cosmonapse
13
+
14
+ # Optional synapse adapters
15
+ pip install "cosmonapse[nats]" # NATS transport
16
+ pip install "cosmonapse[kafka]" # Kafka transport (aiokafka)
17
+
18
+ # Optional storage backend
19
+ pip install "cosmonapse[postgres]" # Postgres registry store (asyncpg)
20
+
21
+ # Optional Flask / WSGI Neuron factory
22
+ pip install "cosmonapse[flask]"
23
+
24
+ # Provider-backed Neurons (Ollama / HuggingFace) need httpx
25
+ pip install httpx
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Quick start
31
+
32
+ ```python
33
+ import asyncio
34
+ from cosmonapse import (
35
+ Axon, Dendrite, Neuron,
36
+ MemoryRegistryStore,
37
+ connect_synapse,
38
+ )
39
+
40
+ async def main():
41
+ # 1. Connect to a running synapse (cosmo synapse start memory)
42
+ synapse = await connect_synapse("cosmo://127.0.0.1:7070")
43
+ try:
44
+ # 2. Define a pure agent function (zero protocol knowledge)
45
+ async def my_agent(input, context):
46
+ return {"answer": f"You asked: {input['q']}"}
47
+
48
+ # -- Worker Dendrite: hosts an Axon --------------------------
49
+ worker = Dendrite(synapse=synapse, namespace="demo")
50
+ worker.attach_axon(Axon(neuron_id="answerer", neuron_fn=my_agent))
51
+
52
+ # -- Orchestrator Dendrite: drives the workflow ---------------
53
+ orch = Dendrite(
54
+ synapse=synapse,
55
+ registry_store=MemoryRegistryStore(),
56
+ namespace="demo",
57
+ )
58
+
59
+ @orch.on_agent_output
60
+ async def done(sig):
61
+ print("Got answer:", sig.payload["output"])
62
+ await orch.emit_final(
63
+ trace_id=sig.trace_id,
64
+ parent_id=sig.id,
65
+ result=sig.payload["output"],
66
+ )
67
+
68
+ async with orch, worker:
69
+ await orch.dispatch_task(neuron="answerer", input={"q": "hi"})
70
+ await asyncio.sleep(0.5)
71
+ finally:
72
+ await synapse.close()
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ Start the dev synapse first:
78
+
79
+ ```bash
80
+ cosmo synapse start memory --namespace=demo
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Provider-backed Neurons
86
+
87
+ Drop an LLM into any workflow with `Neuron(source=...)`:
88
+
89
+ ```python
90
+ from cosmonapse import Axon, Neuron
91
+
92
+ # Local Ollama daemon
93
+ axon = Axon(
94
+ neuron_id="chat",
95
+ neuron_fn=Neuron(source="ollama", model="llama3"),
96
+ )
97
+
98
+ # HuggingFace TGI / vLLM / llama.cpp / LM Studio
99
+ axon = Axon(
100
+ neuron_id="summariser",
101
+ neuron_fn=Neuron(
102
+ source="huggingface",
103
+ endpoint="http://localhost:8080",
104
+ ),
105
+ )
106
+
107
+ # HuggingFace hosted endpoint (requires api_key)
108
+ axon = Axon(
109
+ neuron_id="classifier",
110
+ neuron_fn=Neuron(
111
+ source="huggingface",
112
+ endpoint="https://<your-endpoint>.endpoints.huggingface.cloud",
113
+ api_key="hf_…",
114
+ use_chat_api=True,
115
+ ),
116
+ )
117
+ ```
118
+
119
+ `Neuron(...)` returns an async callable satisfying `NeuronFn`. Pass `prompt` or
120
+ `messages` (OpenAI-style) in the task input. Output is always
121
+ `{"response": "<text>", "meta": <raw provider payload>}`.
122
+
123
+ Requires `httpx` (`pip install httpx`).
124
+
125
+ ---
126
+
127
+ ## Synapse adapters
128
+
129
+ | Import | Use when |
130
+ |---|---|
131
+ | `MemorySynapse` | tests, single-process |
132
+ | `DevSynapse` | multi-process dev on one host (`cosmo synapse start memory`) |
133
+ | `NatsSynapse` | production default (`pip install cosmonapse[nats]`) |
134
+ | `KafkaSynapse` | durable audit log (`pip install "cosmonapse[kafka]"`) |
135
+
136
+ URL factory:
137
+
138
+ ```python
139
+ from cosmonapse import connect_synapse, synapse_from_url
140
+
141
+ synapse = await connect_synapse("cosmo://127.0.0.1:7070") # DevSynapse
142
+ synapse = await connect_synapse("nats://nats:4222") # NatsSynapse
143
+ synapse = await connect_synapse("kafka://broker:9092") # KafkaSynapse
144
+ ```
145
+
146
+ For `MemorySynapse`, construct directly:
147
+
148
+ ```python
149
+ from cosmonapse import MemorySynapse
150
+ synapse = MemorySynapse()
151
+ await synapse.connect()
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Storage backends
157
+
158
+ | Import | Use when |
159
+ |---|---|
160
+ | `MemoryRegistryStore` | tests, ephemeral orchestrators |
161
+ | `SqliteRegistryStore` | single-process production, zero extra deps |
162
+ | `PostgresRegistryStore` | multi-process production (`pip install "cosmonapse[postgres]"`) |
163
+
164
+ ---
165
+
166
+ ## CLI
167
+
168
+ ```bash
169
+ # Start a local dev synapse (TCP + NDJSON)
170
+ cosmo synapse start memory --namespace=dev
171
+
172
+ # View active namespaces
173
+ cosmo synapse view --url=cosmo://127.0.0.1:7070
174
+
175
+ # Stream signals for one namespace
176
+ cosmo synapse view --url=cosmo://127.0.0.1:7070 --namespace=dev
177
+
178
+ # Stop a namespace
179
+ cosmo synapse stop --url=cosmo://127.0.0.1:7070 --namespace=dev
180
+
181
+ # Passive signal watcher (Doppler)
182
+ cosmo doppler --url=cosmo://127.0.0.1:7070 --namespace=dev
183
+
184
+ # Validate envelope conformance
185
+ cosmo validate --url=cosmo://127.0.0.1:7070 --namespace=dev
186
+ ```
187
+
188
+ ---
189
+
190
+ ## Key concepts
191
+
192
+ | Term | What it is |
193
+ |---|---|
194
+ | **Neuron** | A pure async function — zero protocol knowledge |
195
+ | **Axon** | Agent-side wrapper that turns Neuron output into Signals |
196
+ | **Dendrite** | Synapse-side participant; hosts Axons, handles routing, orchestration |
197
+ | **Cortex** | Back-compat alias for `Dendrite` |
198
+ | **Synapse** | The message transport (memory / dev TCP / NATS / Kafka) |
199
+ | **Signal** | An envelope crossing the Synapse |
200
+ | **RegistryStore** | Live view of Neurons seen on a namespace |
201
+
202
+ See `design/SDK_DESIGN.md` for the full design document and `design/ENVELOPE_SPEC.md` for the wire protocol.
File without changes