halfabyte-synapse 0.2.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 (157) hide show
  1. halfabyte_synapse-0.2.0/LICENSE +21 -0
  2. halfabyte_synapse-0.2.0/PKG-INFO +254 -0
  3. halfabyte_synapse-0.2.0/README.md +197 -0
  4. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/PKG-INFO +254 -0
  5. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/SOURCES.txt +155 -0
  6. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/dependency_links.txt +1 -0
  7. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/entry_points.txt +2 -0
  8. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/requires.txt +40 -0
  9. halfabyte_synapse-0.2.0/halfabyte_synapse.egg-info/top_level.txt +1 -0
  10. halfabyte_synapse-0.2.0/pyproject.toml +95 -0
  11. halfabyte_synapse-0.2.0/setup.cfg +4 -0
  12. halfabyte_synapse-0.2.0/synapse/__init__.py +57 -0
  13. halfabyte_synapse-0.2.0/synapse/__main__.py +14 -0
  14. halfabyte_synapse-0.2.0/synapse/alerts.py +227 -0
  15. halfabyte_synapse-0.2.0/synapse/api/__init__.py +0 -0
  16. halfabyte_synapse-0.2.0/synapse/api/main.py +967 -0
  17. halfabyte_synapse-0.2.0/synapse/bot.py +161 -0
  18. halfabyte_synapse-0.2.0/synapse/capsule.py +58 -0
  19. halfabyte_synapse-0.2.0/synapse/chaos_panel.py +138 -0
  20. halfabyte_synapse-0.2.0/synapse/chatops.py +363 -0
  21. halfabyte_synapse-0.2.0/synapse/ci.py +109 -0
  22. halfabyte_synapse-0.2.0/synapse/cli.py +1321 -0
  23. halfabyte_synapse-0.2.0/synapse/core/__init__.py +0 -0
  24. halfabyte_synapse-0.2.0/synapse/core/agents.py +70 -0
  25. halfabyte_synapse-0.2.0/synapse/core/effects.py +345 -0
  26. halfabyte_synapse-0.2.0/synapse/core/hashing.py +85 -0
  27. halfabyte_synapse-0.2.0/synapse/core/lattice.py +60 -0
  28. halfabyte_synapse-0.2.0/synapse/core/retention.py +87 -0
  29. halfabyte_synapse-0.2.0/synapse/core/sir.py +654 -0
  30. halfabyte_synapse-0.2.0/synapse/core/store.py +568 -0
  31. halfabyte_synapse-0.2.0/synapse/core/store_mongo.py +420 -0
  32. halfabyte_synapse-0.2.0/synapse/correctness/__init__.py +6 -0
  33. halfabyte_synapse-0.2.0/synapse/correctness/audit.py +107 -0
  34. halfabyte_synapse-0.2.0/synapse/correctness/chaos.py +180 -0
  35. halfabyte_synapse-0.2.0/synapse/correctness/equivalence.py +114 -0
  36. halfabyte_synapse-0.2.0/synapse/correctness/firewall.py +274 -0
  37. halfabyte_synapse-0.2.0/synapse/correctness/net_rule.py +114 -0
  38. halfabyte_synapse-0.2.0/synapse/correctness/preconditions.py +212 -0
  39. halfabyte_synapse-0.2.0/synapse/correctness/receipt.py +80 -0
  40. halfabyte_synapse-0.2.0/synapse/correctness/runner.py +199 -0
  41. halfabyte_synapse-0.2.0/synapse/correctness/splits.py +39 -0
  42. halfabyte_synapse-0.2.0/synapse/correctness/verify.py +240 -0
  43. halfabyte_synapse-0.2.0/synapse/data/models.yaml +85 -0
  44. halfabyte_synapse-0.2.0/synapse/demo.py +477 -0
  45. halfabyte_synapse-0.2.0/synapse/doctor.py +80 -0
  46. halfabyte_synapse-0.2.0/synapse/export.py +51 -0
  47. halfabyte_synapse-0.2.0/synapse/frontend/__init__.py +0 -0
  48. halfabyte_synapse-0.2.0/synapse/frontend/adapters/__init__.py +0 -0
  49. halfabyte_synapse-0.2.0/synapse/frontend/adapters/adk.py +300 -0
  50. halfabyte_synapse-0.2.0/synapse/frontend/adapters/crewai.py +441 -0
  51. halfabyte_synapse-0.2.0/synapse/frontend/adapters/langgraph.py +290 -0
  52. halfabyte_synapse-0.2.0/synapse/frontend/dsl.py +602 -0
  53. halfabyte_synapse-0.2.0/synapse/frontend/importers/__init__.py +45 -0
  54. halfabyte_synapse-0.2.0/synapse/frontend/importers/_common.py +102 -0
  55. halfabyte_synapse-0.2.0/synapse/frontend/importers/blackbox.py +41 -0
  56. halfabyte_synapse-0.2.0/synapse/frontend/importers/langfuse.py +64 -0
  57. halfabyte_synapse-0.2.0/synapse/frontend/importers/otel.py +105 -0
  58. halfabyte_synapse-0.2.0/synapse/frontend/lift.py +376 -0
  59. halfabyte_synapse-0.2.0/synapse/insights.py +205 -0
  60. halfabyte_synapse-0.2.0/synapse/mcp/__init__.py +22 -0
  61. halfabyte_synapse-0.2.0/synapse/mcp/__main__.py +5 -0
  62. halfabyte_synapse-0.2.0/synapse/mcp/prompts.py +88 -0
  63. halfabyte_synapse-0.2.0/synapse/mcp/protocol.py +35 -0
  64. halfabyte_synapse-0.2.0/synapse/mcp/registry.py +123 -0
  65. halfabyte_synapse-0.2.0/synapse/mcp/resources.py +84 -0
  66. halfabyte_synapse-0.2.0/synapse/mcp/server.py +124 -0
  67. halfabyte_synapse-0.2.0/synapse/mcp/tools.py +531 -0
  68. halfabyte_synapse-0.2.0/synapse/menus.py +146 -0
  69. halfabyte_synapse-0.2.0/synapse/monitor.py +144 -0
  70. halfabyte_synapse-0.2.0/synapse/passes/__init__.py +5 -0
  71. halfabyte_synapse-0.2.0/synapse/passes/base.py +414 -0
  72. halfabyte_synapse-0.2.0/synapse/passes/batch.py +189 -0
  73. halfabyte_synapse-0.2.0/synapse/passes/constfold.py +204 -0
  74. halfabyte_synapse-0.2.0/synapse/passes/context_prune.py +214 -0
  75. halfabyte_synapse-0.2.0/synapse/passes/context_trim.py +96 -0
  76. halfabyte_synapse-0.2.0/synapse/passes/cse.py +195 -0
  77. halfabyte_synapse-0.2.0/synapse/passes/dce.py +125 -0
  78. halfabyte_synapse-0.2.0/synapse/passes/downgrade.py +241 -0
  79. halfabyte_synapse-0.2.0/synapse/passes/early_exit.py +232 -0
  80. halfabyte_synapse-0.2.0/synapse/passes/loop_cutoff.py +140 -0
  81. halfabyte_synapse-0.2.0/synapse/passes/manager.py +439 -0
  82. halfabyte_synapse-0.2.0/synapse/passes/memoize.py +161 -0
  83. halfabyte_synapse-0.2.0/synapse/passes/parallelize.py +325 -0
  84. halfabyte_synapse-0.2.0/synapse/passes/speculate.py +178 -0
  85. halfabyte_synapse-0.2.0/synapse/profile/__init__.py +20 -0
  86. halfabyte_synapse-0.2.0/synapse/profile/collect.py +275 -0
  87. halfabyte_synapse-0.2.0/synapse/profile/costmodel.py +85 -0
  88. halfabyte_synapse-0.2.0/synapse/profile/critical_path.py +98 -0
  89. halfabyte_synapse-0.2.0/synapse/profile/ledger.py +145 -0
  90. halfabyte_synapse-0.2.0/synapse/profile/presentation.py +65 -0
  91. halfabyte_synapse-0.2.0/synapse/profile/pricing.py +25 -0
  92. halfabyte_synapse-0.2.0/synapse/profile/waste.py +64 -0
  93. halfabyte_synapse-0.2.0/synapse/proxy.py +123 -0
  94. halfabyte_synapse-0.2.0/synapse/quarantine.py +24 -0
  95. halfabyte_synapse-0.2.0/synapse/runtime/__init__.py +0 -0
  96. halfabyte_synapse-0.2.0/synapse/runtime/cache.py +157 -0
  97. halfabyte_synapse-0.2.0/synapse/runtime/executor.py +667 -0
  98. halfabyte_synapse-0.2.0/synapse/runtime/meter.py +89 -0
  99. halfabyte_synapse-0.2.0/synapse/runtime/providers.py +434 -0
  100. halfabyte_synapse-0.2.0/synapse/runtime/rate_gate.py +71 -0
  101. halfabyte_synapse-0.2.0/synapse/runtime/recording.py +199 -0
  102. halfabyte_synapse-0.2.0/synapse/runtime/scheduler.py +686 -0
  103. halfabyte_synapse-0.2.0/synapse/runtime/semantic.py +97 -0
  104. halfabyte_synapse-0.2.0/synapse/search.py +183 -0
  105. halfabyte_synapse-0.2.0/synapse/skills/__init__.py +32 -0
  106. halfabyte_synapse-0.2.0/synapse/skills/synapse/SKILL.md +73 -0
  107. halfabyte_synapse-0.2.0/synapse/skills/synapse/references/effects.md +24 -0
  108. halfabyte_synapse-0.2.0/tests/test_ablation.py +113 -0
  109. halfabyte_synapse-0.2.0/tests/test_adk_adapter.py +101 -0
  110. halfabyte_synapse-0.2.0/tests/test_alerts.py +136 -0
  111. halfabyte_synapse-0.2.0/tests/test_api.py +280 -0
  112. halfabyte_synapse-0.2.0/tests/test_audit_gate.py +119 -0
  113. halfabyte_synapse-0.2.0/tests/test_bench_tools.py +105 -0
  114. halfabyte_synapse-0.2.0/tests/test_chaos.py +10 -0
  115. halfabyte_synapse-0.2.0/tests/test_chatops.py +151 -0
  116. halfabyte_synapse-0.2.0/tests/test_checkers.py +54 -0
  117. halfabyte_synapse-0.2.0/tests/test_cli.py +111 -0
  118. halfabyte_synapse-0.2.0/tests/test_contracts.py +52 -0
  119. halfabyte_synapse-0.2.0/tests/test_corpus.py +83 -0
  120. halfabyte_synapse-0.2.0/tests/test_correctness.py +103 -0
  121. halfabyte_synapse-0.2.0/tests/test_cost_resources.py +51 -0
  122. halfabyte_synapse-0.2.0/tests/test_crewai_adapter.py +265 -0
  123. halfabyte_synapse-0.2.0/tests/test_dsl.py +415 -0
  124. halfabyte_synapse-0.2.0/tests/test_effects.py +221 -0
  125. halfabyte_synapse-0.2.0/tests/test_features.py +253 -0
  126. halfabyte_synapse-0.2.0/tests/test_hashing.py +102 -0
  127. halfabyte_synapse-0.2.0/tests/test_importers.py +160 -0
  128. halfabyte_synapse-0.2.0/tests/test_langgraph_adapter.py +108 -0
  129. halfabyte_synapse-0.2.0/tests/test_lattice.py +70 -0
  130. halfabyte_synapse-0.2.0/tests/test_ledger.py +94 -0
  131. halfabyte_synapse-0.2.0/tests/test_lift.py +218 -0
  132. halfabyte_synapse-0.2.0/tests/test_manager.py +261 -0
  133. halfabyte_synapse-0.2.0/tests/test_mcp.py +237 -0
  134. halfabyte_synapse-0.2.0/tests/test_monitor_menus.py +189 -0
  135. halfabyte_synapse-0.2.0/tests/test_net_rule.py +91 -0
  136. halfabyte_synapse-0.2.0/tests/test_passes.py +960 -0
  137. halfabyte_synapse-0.2.0/tests/test_policy_study.py +79 -0
  138. halfabyte_synapse-0.2.0/tests/test_profile.py +126 -0
  139. halfabyte_synapse-0.2.0/tests/test_providers.py +211 -0
  140. halfabyte_synapse-0.2.0/tests/test_recording.py +213 -0
  141. halfabyte_synapse-0.2.0/tests/test_report.py +190 -0
  142. halfabyte_synapse-0.2.0/tests/test_research_fanout.py +68 -0
  143. halfabyte_synapse-0.2.0/tests/test_review_fixes.py +94 -0
  144. halfabyte_synapse-0.2.0/tests/test_runner.py +119 -0
  145. halfabyte_synapse-0.2.0/tests/test_runtime.py +686 -0
  146. halfabyte_synapse-0.2.0/tests/test_search.py +96 -0
  147. halfabyte_synapse-0.2.0/tests/test_sir.py +220 -0
  148. halfabyte_synapse-0.2.0/tests/test_skill.py +126 -0
  149. halfabyte_synapse-0.2.0/tests/test_speculation.py +168 -0
  150. halfabyte_synapse-0.2.0/tests/test_splits.py +40 -0
  151. halfabyte_synapse-0.2.0/tests/test_store_backends.py +268 -0
  152. halfabyte_synapse-0.2.0/tests/test_suite.py +344 -0
  153. halfabyte_synapse-0.2.0/tests/test_usp.py +169 -0
  154. halfabyte_synapse-0.2.0/tests/test_usp_batch.py +299 -0
  155. halfabyte_synapse-0.2.0/tests/test_verdict_labels.py +60 -0
  156. halfabyte_synapse-0.2.0/tests/test_workflow_graphs.py +172 -0
  157. halfabyte_synapse-0.2.0/tests/test_workflows.py +168 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Half a Byte
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.4
2
+ Name: halfabyte-synapse
3
+ Version: 0.2.0
4
+ Summary: A compiler and runtime for AI agent workflows: faster and cheaper runs, with side effects protected and every change checked by a firewall.
5
+ Author: Aryan Lomte, Radhesh, Aditya, Advay Chavan
6
+ Maintainer: Half a Byte
7
+ License-Expression: MIT
8
+ Keywords: ai-agents,llm,compiler,optimization,workflow,intermediate-representation,agent-runtime,scheduling,caching,profiling,observability,mcp,benchmarking,groq,ollama,crewai,langgraph,google-adk,whatsapp
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Topic :: Software Development :: Compilers
17
+ Classifier: Topic :: Software Development :: Testing
18
+ Classifier: Topic :: System :: Benchmark
19
+ Classifier: Topic :: System :: Monitoring
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Environment :: Console
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pydantic>=2.5
26
+ Requires-Dist: pyyaml>=6
27
+ Requires-Dist: python-dotenv>=1
28
+ Requires-Dist: openai>=1.40
29
+ Requires-Dist: psutil>=5.9
30
+ Provides-Extra: ui
31
+ Requires-Dist: fastapi>=0.110; extra == "ui"
32
+ Requires-Dist: uvicorn[standard]>=0.29; extra == "ui"
33
+ Requires-Dist: sse-starlette>=2; extra == "ui"
34
+ Provides-Extra: ml
35
+ Requires-Dist: scikit-learn>=1.4; extra == "ml"
36
+ Requires-Dist: lightgbm>=4; extra == "ml"
37
+ Requires-Dist: numpy; extra == "ml"
38
+ Provides-Extra: bench
39
+ Requires-Dist: rank-bm25>=0.2; extra == "bench"
40
+ Requires-Dist: datasets>=2.18; extra == "bench"
41
+ Provides-Extra: cloud
42
+ Requires-Dist: pymongo>=4.6; extra == "cloud"
43
+ Provides-Extra: crewai
44
+ Requires-Dist: crewai<1.16,>=1.15; extra == "crewai"
45
+ Provides-Extra: langgraph
46
+ Requires-Dist: langgraph<1.1,>=1.0; extra == "langgraph"
47
+ Provides-Extra: adk
48
+ Requires-Dist: google-adk<2.14,>=2.13; extra == "adk"
49
+ Provides-Extra: dev
50
+ Requires-Dist: pytest>=8; extra == "dev"
51
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
52
+ Requires-Dist: ruff>=0.5; extra == "dev"
53
+ Requires-Dist: mongomock>=4.1; extra == "dev"
54
+ Provides-Extra: all
55
+ Requires-Dist: halfabyte-synapse[bench,cloud,ml,ui]; extra == "all"
56
+ Dynamic: license-file
57
+
58
+ # Synapse
59
+
60
+ **A compiler and runtime for AI agent workflows.** It finds the work your agent repeats or waits for, makes it faster and cheaper, and refuses any change it can't check.
61
+
62
+ ```bash
63
+ pip install halfabyte-synapse
64
+ synapse demo
65
+ ```
66
+
67
+ No API key, GPU or model needed: the demo runs on a built-in fake provider. The package is `halfabyte-synapse`; the command and the import are both `synapse`.
68
+
69
+ Built by team **Half a Byte** for the BitNBuild 2026 "Around the World" final round (GDG On Campus, Fr. Conceicao Rodrigues College of Engineering), AI/ML problem statement 2.
70
+
71
+ ## Why it exists
72
+
73
+ Agents run steps one after another even when nothing connects them, repeat calls they have already made, and send context nobody reads. Fixing that by hand is easy to get wrong: run two steps together, and a model may answer differently. Cache a step, and an email may never get sent.
74
+
75
+ Synapse treats a workflow as a program:
76
+
77
+ 1. **Compile** it to SIR, a graph where every dependency is explicit and every step declares what it can do to the world.
78
+ 2. **Profile** real runs: time on the clock, tokens from the provider, and cost from listed prices. If nobody reported a number, it stays blank.
79
+ 3. **Optimize** with passes that each state when they are safe. The passes are chosen by measuring them.
80
+ 4. **Check** the result with a firewall that runs both versions on real tasks and returns **APPROVE** or **BLOCK**.
81
+
82
+ ## What makes it different
83
+
84
+ - **It says no.** A BLOCK shows which tasks broke. You can plant a fault and watch the firewall catch it.
85
+ - **Side effects are law.** A step that sends an email or moves money is never cached, reordered or repeated. Steps that can't be undone never run while Synapse is testing.
86
+ - **It measures what others assume.** `synapse audit` checks whether a model server keeps its answers when requests overlap. On local Ollama, 5 of 6 prompts changed under concurrency.
87
+ - **It counts its own cost.** The savings ledger counts every run Synapse makes to check an optimization, and says when that pays back, including "never".
88
+ - **It says what it can't do.** Unknown values stay blank, demo results are labelled, and `batch` is listed as marking steps only.
89
+
90
+ ## Real results
91
+
92
+ Held-out tasks on Groq `qwen/qwen3.8-27b`, `memoize` and `parallelize`, cold cache. Costs use Groq's listed prices.
93
+
94
+ | Workflow | Tasks | Time (p50) | Speedup | Tokens per task | Cost per task | Tasks passing | Answers broken | Firewall |
95
+ |---|---|---|---|---|---|---|---|---|
96
+ | `research_fanout` | 41 | 2.35 s to 1.39 s | 1.82x | 2,333 to 2,040 (-12.6%) | $0.00264 to $0.00232 (-12.2%) | 36 to 36 | 0 | **APPROVE** |
97
+ | `code_review` | 41 | 1.64 s to 0.81 s | 2.15x | no change | no change | 25 to 25 | 0 | **BLOCK** |
98
+
99
+ How to read this:
100
+
101
+ - **The APPROVE rests on cost and tokens.** Both speedups fall just inside the measured noise band (47.9% and 52.7%, against time gains of 41.1% and 50.7%), so the firewall doesn't count them as proven. That's why `code_review` is blocked even though nothing broke.
102
+ - **This is a second look at these tasks.** They ran first on a local model, and we chose this provider after seeing those results.
103
+ - **Locally, the same tasks blocked.** On Ollama, `research_fanout` reached 1.51x with 2 answers broken. That break led us to find that Ollama changes answers under concurrent requests.
104
+ - **Checking has a cost.** At these savings, the `research_fanout` check pays for itself after about 1,230 runs.
105
+
106
+ Fake-provider demos measure scheduling, not a model, so don't read them as model performance. "Verified" here means on these tasks, not proven for every input.
107
+
108
+ ## Effect tiers
109
+
110
+ Every step has one, and it decides what Synapse may do. An undeclared tool is assumed to be `external`.
111
+
112
+ | Effect | Means | Example | What's allowed |
113
+ |---|---|---|---|
114
+ | `pure` | Same input, same output, nothing else happens | A seeded model call, a parse | Every rewrite, except merging random samples |
115
+ | `read` | Looks at the outside world | Web search, retrieval | Reuse while still fresh, overlap |
116
+ | `write` | Changes the workflow's own state | An agent's memory | Ordered by key, overlap only on separate keys |
117
+ | `external` | Changes the outside world | An email, a POST | Nothing: never repeated, reordered or cached |
118
+ | `irreversible` | Can't be undone | An order, a payment | As `external`, and never run while testing |
119
+
120
+ ## Passes
121
+
122
+ `synapse passes` prints each one's safety rule, and `synapse explain PASS` explains one.
123
+
124
+ | Pass | What it does | Default |
125
+ |---|---|---|
126
+ | `constfold` | Works out pure steps over fixed values at compile time | on |
127
+ | `dce` | Removes steps whose results nothing uses | on |
128
+ | `context_prune` | Drops arguments a prompt never references | on |
129
+ | `cse` | Merges steps that compute the same thing | on |
130
+ | `loop_cutoff` | Stops a loop once its state stops changing | on |
131
+ | `memoize` | Serves a repeat from a content-addressed cache | on |
132
+ | `parallelize` | Runs independent steps together, within limits | on |
133
+ | `downgrade` | Moves a call to a cheaper model on the same provider | on |
134
+ | `speculate` | Starts a read before its branch is decided, within a budget | off |
135
+ | `context_trim` | Clips context, kept only if the firewall approves | off |
136
+ | `early_exit` | Ends early on a calibrated confidence signal | off |
137
+ | `batch` | Marks calls that could share a request. **The runtime doesn't fuse them yet** | off |
138
+
139
+ ## Tools
140
+
141
+ ### Commands
142
+
143
+ | Command | What it does |
144
+ |---|---|
145
+ | `synapse demo [--workflow NAME\|all]` | Compile, optimize and compare, with no provider |
146
+ | `synapse compile`, `graph`, `graphs` | Turn a workflow into SIR, and read it back |
147
+ | `synapse import FORMAT FILE` | Turn an OTel, Langfuse or Black Box trace into SIR |
148
+ | `synapse optimize`, `run`, `compare` | Optimize, execute with measurements, compare |
149
+ | `synapse profile`, `why`, `explain` | Measured profile, why a step wasn't optimized, what a pass does |
150
+ | `synapse verify GRAPH` | Run the firewall |
151
+ | `synapse force GRAPH PASS` | Apply one pass and let the firewall judge it |
152
+ | `synapse replay GRAPH` | Check on recordings: tokens only where a prompt changed |
153
+ | `synapse receipt GRAPH` | A record of the verdict that shows if it was edited; `--check FILE --rerun` tests one |
154
+ | `synapse savings GRAPH` | What checking cost, what it saves per run, when it pays back |
155
+ | `synapse audit --model ID` | Does this model keep its answers under concurrent requests? |
156
+ | `synapse chaos GRAPH FAULT` | Break a demo workflow on purpose |
157
+ | `synapse diagnose FORMAT FILE` | Waste report on a trace, changing nothing |
158
+ | `synapse agents`, `export`, `capsule` | Multi-agent view, Mermaid, DOT or JSON export, one run as a file |
159
+ | `synapse crew`, `langgraph`, `adk` | Run a CrewAI, LangGraph or Google ADK workflow through Synapse |
160
+ | `synapse proxy --upstream URL` | Point any OpenAI client's `base_url` here to record its calls |
161
+ | `synapse ci pin\|run WORKFLOW` | Fail when a workflow gets slower, costlier or less correct |
162
+ | `synapse monitor` | Watch runs and alert on crashes, slowdowns and overspend |
163
+ | `synapse alerts`, `digest` | Test alert channels, send a summary |
164
+ | `synapse bot` | Operate Synapse from WhatsApp and Slack |
165
+ | `synapse storage`, `doctor`, `models` | What's stored, find setup problems, check model names |
166
+ | `synapse ui`, `mcp`, `skill` | Serve the API, run the MCP server, install the agent Skill |
167
+ | `synapse bench` | Benchmark suite, from a repository checkout only |
168
+
169
+ ### Write a workflow
170
+
171
+ ```python
172
+ from synapse import Effect, node, workflow
173
+
174
+ @node(kind="retrieval", target="web_search", effect=Effect.READ, staleness_s=3600)
175
+ def search(query: str) -> list[str]:
176
+ ...
177
+
178
+ @node(kind="io", target="send_email", effect=Effect.EXTERNAL)
179
+ def send(text: str) -> str:
180
+ ...
181
+
182
+ @workflow(name="my_agent")
183
+ def my_agent(question: str):
184
+ ...
185
+ ```
186
+
187
+ Multi-agent workflows wrap steps in `with agent("researcher"):`, and they're still one graph.
188
+
189
+ ### Use it with no code changes
190
+
191
+ ```bash
192
+ synapse proxy --upstream https://api.groq.com/openai/v1
193
+ ```
194
+
195
+ Point your client's `base_url` at `http://127.0.0.1:8030/v1`. Synapse records every call and serves exact repeats only when `temperature` is 0. `GET /synapse/report` shows the waste. It sees model calls, not your tools. Streaming isn't supported yet.
196
+
197
+ ### Use it from an AI agent
198
+
199
+ `synapse mcp` is an MCP server with 21 tools, such as `optimize`, `why_not_optimized`, `verify`, `savings` and `inject_fault`. `synapse skill --target openclaw` installs a lean Skill instead (`hermes`, `claude` or a folder also work). Start a new agent session afterwards.
200
+
201
+ ### Operate it from WhatsApp and Slack
202
+
203
+ `synapse bot` gives you tappable WhatsApp menus through Twilio, and buttons in Slack. Send `hi`, or type a command such as `health`, `spend`, `verify research_fanout`, `chaos research_fanout crash`, `pending` or `ship`. Only signed requests from allowed numbers get in. Nothing runs live, and `ship` refuses anything the firewall hasn't approved. Email is outbound only.
204
+
205
+ ```bash
206
+ synapse bot --port 8010
207
+ ngrok http 8010 # any tunnel works; set SYNAPSE_BOT_URL to its address
208
+ ```
209
+
210
+ ## Install options
211
+
212
+ ```bash
213
+ pip install "halfabyte-synapse[ui]" # the API server
214
+ pip install "halfabyte-synapse[cloud]" # MongoDB or Atlas as the store
215
+ pip install "halfabyte-synapse[ml]" # the learned pass policy
216
+ pip install "halfabyte-synapse[all]" # all of the above, plus benchmark loaders
217
+ pip install "halfabyte-synapse[crewai]" # or [langgraph], or [adk]
218
+ ```
219
+
220
+ `crewai` and `adk` can't share an environment, because their OpenTelemetry requirements clash.
221
+
222
+ ## Configuration
223
+
224
+ Settings live in `.env`, and models live in `models.yaml`. Everything is optional.
225
+
226
+ | Setting | For |
227
+ |---|---|
228
+ | `GROQ_API_KEYS`, `OPENROUTER_API_KEYS` | Comma-separated keys for those providers |
229
+ | `SYNAPSE_STORE` | `mongodb+srv://...` for a shared store. Local SQLite otherwise |
230
+ | `SYNAPSE_READ_ONLY=1` | API serves reads only, for public hosting |
231
+ | `SLACK_WEBHOOK_URL`, `SLACK_SIGNING_SECRET` | Slack alerts, commands and buttons |
232
+ | `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_WHATSAPP_FROM`, `ALERT_WHATSAPP_TO` | WhatsApp |
233
+ | `EMAILJS_SERVICE_ID`, `EMAILJS_TEMPLATE_ID`, `EMAILJS_PUBLIC_KEY`, `EMAILJS_PRIVATE_KEY`, `ALERT_EMAIL_TO` | Email |
234
+ | `SYNAPSE_RPM_<PROVIDER>`, `SYNAPSE_TPM_<PROVIDER>` | Wait before a rate limit is hit |
235
+ | `SYNAPSE_RECEIPT_KEY` | Sign receipts |
236
+
237
+ Runs are stored locally by default, as digests rather than full outputs, for 30 days, with a 256 MB cache. `synapse storage` shows what's held.
238
+
239
+ ## Limits
240
+
241
+ - Correctness is checked on your tasks, not proven for every input. Without checkers, there's nothing to judge against.
242
+ - `verify`, `force`, `replay` and `chaos` run on built-in demo workflows. Real corpora run through `synapse bench` in a repository checkout.
243
+ - Replay can't see a server that changes answers under load, so run `synapse audit` first.
244
+ - A live run never reuses recordings, so only stubbed runs resume after a crash.
245
+ - The semantic cache uses word overlap, not embeddings, and is experimental.
246
+ - Adapters refuse what they can't compile safely, such as CrewAI hierarchical crews and LangGraph conditional edges.
247
+
248
+ ## Team
249
+
250
+ Half a Byte: Aryan Lomte ([Aryan-lomte05](https://github.com/Aryan-lomte05)), Radhesh ([rad117](https://github.com/rad117)), Aditya ([02Aditya2323](https://github.com/02Aditya2323)), Advay Chavan ([advay1608](https://github.com/advay1608)).
251
+
252
+ ## License
253
+
254
+ MIT.
@@ -0,0 +1,197 @@
1
+ # Synapse
2
+
3
+ **A compiler and runtime for AI agent workflows.** It finds the work your agent repeats or waits for, makes it faster and cheaper, and refuses any change it can't check.
4
+
5
+ ```bash
6
+ pip install halfabyte-synapse
7
+ synapse demo
8
+ ```
9
+
10
+ No API key, GPU or model needed: the demo runs on a built-in fake provider. The package is `halfabyte-synapse`; the command and the import are both `synapse`.
11
+
12
+ Built by team **Half a Byte** for the BitNBuild 2026 "Around the World" final round (GDG On Campus, Fr. Conceicao Rodrigues College of Engineering), AI/ML problem statement 2.
13
+
14
+ ## Why it exists
15
+
16
+ Agents run steps one after another even when nothing connects them, repeat calls they have already made, and send context nobody reads. Fixing that by hand is easy to get wrong: run two steps together, and a model may answer differently. Cache a step, and an email may never get sent.
17
+
18
+ Synapse treats a workflow as a program:
19
+
20
+ 1. **Compile** it to SIR, a graph where every dependency is explicit and every step declares what it can do to the world.
21
+ 2. **Profile** real runs: time on the clock, tokens from the provider, and cost from listed prices. If nobody reported a number, it stays blank.
22
+ 3. **Optimize** with passes that each state when they are safe. The passes are chosen by measuring them.
23
+ 4. **Check** the result with a firewall that runs both versions on real tasks and returns **APPROVE** or **BLOCK**.
24
+
25
+ ## What makes it different
26
+
27
+ - **It says no.** A BLOCK shows which tasks broke. You can plant a fault and watch the firewall catch it.
28
+ - **Side effects are law.** A step that sends an email or moves money is never cached, reordered or repeated. Steps that can't be undone never run while Synapse is testing.
29
+ - **It measures what others assume.** `synapse audit` checks whether a model server keeps its answers when requests overlap. On local Ollama, 5 of 6 prompts changed under concurrency.
30
+ - **It counts its own cost.** The savings ledger counts every run Synapse makes to check an optimization, and says when that pays back, including "never".
31
+ - **It says what it can't do.** Unknown values stay blank, demo results are labelled, and `batch` is listed as marking steps only.
32
+
33
+ ## Real results
34
+
35
+ Held-out tasks on Groq `qwen/qwen3.8-27b`, `memoize` and `parallelize`, cold cache. Costs use Groq's listed prices.
36
+
37
+ | Workflow | Tasks | Time (p50) | Speedup | Tokens per task | Cost per task | Tasks passing | Answers broken | Firewall |
38
+ |---|---|---|---|---|---|---|---|---|
39
+ | `research_fanout` | 41 | 2.35 s to 1.39 s | 1.82x | 2,333 to 2,040 (-12.6%) | $0.00264 to $0.00232 (-12.2%) | 36 to 36 | 0 | **APPROVE** |
40
+ | `code_review` | 41 | 1.64 s to 0.81 s | 2.15x | no change | no change | 25 to 25 | 0 | **BLOCK** |
41
+
42
+ How to read this:
43
+
44
+ - **The APPROVE rests on cost and tokens.** Both speedups fall just inside the measured noise band (47.9% and 52.7%, against time gains of 41.1% and 50.7%), so the firewall doesn't count them as proven. That's why `code_review` is blocked even though nothing broke.
45
+ - **This is a second look at these tasks.** They ran first on a local model, and we chose this provider after seeing those results.
46
+ - **Locally, the same tasks blocked.** On Ollama, `research_fanout` reached 1.51x with 2 answers broken. That break led us to find that Ollama changes answers under concurrent requests.
47
+ - **Checking has a cost.** At these savings, the `research_fanout` check pays for itself after about 1,230 runs.
48
+
49
+ Fake-provider demos measure scheduling, not a model, so don't read them as model performance. "Verified" here means on these tasks, not proven for every input.
50
+
51
+ ## Effect tiers
52
+
53
+ Every step has one, and it decides what Synapse may do. An undeclared tool is assumed to be `external`.
54
+
55
+ | Effect | Means | Example | What's allowed |
56
+ |---|---|---|---|
57
+ | `pure` | Same input, same output, nothing else happens | A seeded model call, a parse | Every rewrite, except merging random samples |
58
+ | `read` | Looks at the outside world | Web search, retrieval | Reuse while still fresh, overlap |
59
+ | `write` | Changes the workflow's own state | An agent's memory | Ordered by key, overlap only on separate keys |
60
+ | `external` | Changes the outside world | An email, a POST | Nothing: never repeated, reordered or cached |
61
+ | `irreversible` | Can't be undone | An order, a payment | As `external`, and never run while testing |
62
+
63
+ ## Passes
64
+
65
+ `synapse passes` prints each one's safety rule, and `synapse explain PASS` explains one.
66
+
67
+ | Pass | What it does | Default |
68
+ |---|---|---|
69
+ | `constfold` | Works out pure steps over fixed values at compile time | on |
70
+ | `dce` | Removes steps whose results nothing uses | on |
71
+ | `context_prune` | Drops arguments a prompt never references | on |
72
+ | `cse` | Merges steps that compute the same thing | on |
73
+ | `loop_cutoff` | Stops a loop once its state stops changing | on |
74
+ | `memoize` | Serves a repeat from a content-addressed cache | on |
75
+ | `parallelize` | Runs independent steps together, within limits | on |
76
+ | `downgrade` | Moves a call to a cheaper model on the same provider | on |
77
+ | `speculate` | Starts a read before its branch is decided, within a budget | off |
78
+ | `context_trim` | Clips context, kept only if the firewall approves | off |
79
+ | `early_exit` | Ends early on a calibrated confidence signal | off |
80
+ | `batch` | Marks calls that could share a request. **The runtime doesn't fuse them yet** | off |
81
+
82
+ ## Tools
83
+
84
+ ### Commands
85
+
86
+ | Command | What it does |
87
+ |---|---|
88
+ | `synapse demo [--workflow NAME\|all]` | Compile, optimize and compare, with no provider |
89
+ | `synapse compile`, `graph`, `graphs` | Turn a workflow into SIR, and read it back |
90
+ | `synapse import FORMAT FILE` | Turn an OTel, Langfuse or Black Box trace into SIR |
91
+ | `synapse optimize`, `run`, `compare` | Optimize, execute with measurements, compare |
92
+ | `synapse profile`, `why`, `explain` | Measured profile, why a step wasn't optimized, what a pass does |
93
+ | `synapse verify GRAPH` | Run the firewall |
94
+ | `synapse force GRAPH PASS` | Apply one pass and let the firewall judge it |
95
+ | `synapse replay GRAPH` | Check on recordings: tokens only where a prompt changed |
96
+ | `synapse receipt GRAPH` | A record of the verdict that shows if it was edited; `--check FILE --rerun` tests one |
97
+ | `synapse savings GRAPH` | What checking cost, what it saves per run, when it pays back |
98
+ | `synapse audit --model ID` | Does this model keep its answers under concurrent requests? |
99
+ | `synapse chaos GRAPH FAULT` | Break a demo workflow on purpose |
100
+ | `synapse diagnose FORMAT FILE` | Waste report on a trace, changing nothing |
101
+ | `synapse agents`, `export`, `capsule` | Multi-agent view, Mermaid, DOT or JSON export, one run as a file |
102
+ | `synapse crew`, `langgraph`, `adk` | Run a CrewAI, LangGraph or Google ADK workflow through Synapse |
103
+ | `synapse proxy --upstream URL` | Point any OpenAI client's `base_url` here to record its calls |
104
+ | `synapse ci pin\|run WORKFLOW` | Fail when a workflow gets slower, costlier or less correct |
105
+ | `synapse monitor` | Watch runs and alert on crashes, slowdowns and overspend |
106
+ | `synapse alerts`, `digest` | Test alert channels, send a summary |
107
+ | `synapse bot` | Operate Synapse from WhatsApp and Slack |
108
+ | `synapse storage`, `doctor`, `models` | What's stored, find setup problems, check model names |
109
+ | `synapse ui`, `mcp`, `skill` | Serve the API, run the MCP server, install the agent Skill |
110
+ | `synapse bench` | Benchmark suite, from a repository checkout only |
111
+
112
+ ### Write a workflow
113
+
114
+ ```python
115
+ from synapse import Effect, node, workflow
116
+
117
+ @node(kind="retrieval", target="web_search", effect=Effect.READ, staleness_s=3600)
118
+ def search(query: str) -> list[str]:
119
+ ...
120
+
121
+ @node(kind="io", target="send_email", effect=Effect.EXTERNAL)
122
+ def send(text: str) -> str:
123
+ ...
124
+
125
+ @workflow(name="my_agent")
126
+ def my_agent(question: str):
127
+ ...
128
+ ```
129
+
130
+ Multi-agent workflows wrap steps in `with agent("researcher"):`, and they're still one graph.
131
+
132
+ ### Use it with no code changes
133
+
134
+ ```bash
135
+ synapse proxy --upstream https://api.groq.com/openai/v1
136
+ ```
137
+
138
+ Point your client's `base_url` at `http://127.0.0.1:8030/v1`. Synapse records every call and serves exact repeats only when `temperature` is 0. `GET /synapse/report` shows the waste. It sees model calls, not your tools. Streaming isn't supported yet.
139
+
140
+ ### Use it from an AI agent
141
+
142
+ `synapse mcp` is an MCP server with 21 tools, such as `optimize`, `why_not_optimized`, `verify`, `savings` and `inject_fault`. `synapse skill --target openclaw` installs a lean Skill instead (`hermes`, `claude` or a folder also work). Start a new agent session afterwards.
143
+
144
+ ### Operate it from WhatsApp and Slack
145
+
146
+ `synapse bot` gives you tappable WhatsApp menus through Twilio, and buttons in Slack. Send `hi`, or type a command such as `health`, `spend`, `verify research_fanout`, `chaos research_fanout crash`, `pending` or `ship`. Only signed requests from allowed numbers get in. Nothing runs live, and `ship` refuses anything the firewall hasn't approved. Email is outbound only.
147
+
148
+ ```bash
149
+ synapse bot --port 8010
150
+ ngrok http 8010 # any tunnel works; set SYNAPSE_BOT_URL to its address
151
+ ```
152
+
153
+ ## Install options
154
+
155
+ ```bash
156
+ pip install "halfabyte-synapse[ui]" # the API server
157
+ pip install "halfabyte-synapse[cloud]" # MongoDB or Atlas as the store
158
+ pip install "halfabyte-synapse[ml]" # the learned pass policy
159
+ pip install "halfabyte-synapse[all]" # all of the above, plus benchmark loaders
160
+ pip install "halfabyte-synapse[crewai]" # or [langgraph], or [adk]
161
+ ```
162
+
163
+ `crewai` and `adk` can't share an environment, because their OpenTelemetry requirements clash.
164
+
165
+ ## Configuration
166
+
167
+ Settings live in `.env`, and models live in `models.yaml`. Everything is optional.
168
+
169
+ | Setting | For |
170
+ |---|---|
171
+ | `GROQ_API_KEYS`, `OPENROUTER_API_KEYS` | Comma-separated keys for those providers |
172
+ | `SYNAPSE_STORE` | `mongodb+srv://...` for a shared store. Local SQLite otherwise |
173
+ | `SYNAPSE_READ_ONLY=1` | API serves reads only, for public hosting |
174
+ | `SLACK_WEBHOOK_URL`, `SLACK_SIGNING_SECRET` | Slack alerts, commands and buttons |
175
+ | `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_WHATSAPP_FROM`, `ALERT_WHATSAPP_TO` | WhatsApp |
176
+ | `EMAILJS_SERVICE_ID`, `EMAILJS_TEMPLATE_ID`, `EMAILJS_PUBLIC_KEY`, `EMAILJS_PRIVATE_KEY`, `ALERT_EMAIL_TO` | Email |
177
+ | `SYNAPSE_RPM_<PROVIDER>`, `SYNAPSE_TPM_<PROVIDER>` | Wait before a rate limit is hit |
178
+ | `SYNAPSE_RECEIPT_KEY` | Sign receipts |
179
+
180
+ Runs are stored locally by default, as digests rather than full outputs, for 30 days, with a 256 MB cache. `synapse storage` shows what's held.
181
+
182
+ ## Limits
183
+
184
+ - Correctness is checked on your tasks, not proven for every input. Without checkers, there's nothing to judge against.
185
+ - `verify`, `force`, `replay` and `chaos` run on built-in demo workflows. Real corpora run through `synapse bench` in a repository checkout.
186
+ - Replay can't see a server that changes answers under load, so run `synapse audit` first.
187
+ - A live run never reuses recordings, so only stubbed runs resume after a crash.
188
+ - The semantic cache uses word overlap, not embeddings, and is experimental.
189
+ - Adapters refuse what they can't compile safely, such as CrewAI hierarchical crews and LangGraph conditional edges.
190
+
191
+ ## Team
192
+
193
+ Half a Byte: Aryan Lomte ([Aryan-lomte05](https://github.com/Aryan-lomte05)), Radhesh ([rad117](https://github.com/rad117)), Aditya ([02Aditya2323](https://github.com/02Aditya2323)), Advay Chavan ([advay1608](https://github.com/advay1608)).
194
+
195
+ ## License
196
+
197
+ MIT.