fabri 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 (85) hide show
  1. fabri-0.1.0/LICENSE +201 -0
  2. fabri-0.1.0/PKG-INFO +243 -0
  3. fabri-0.1.0/README.md +209 -0
  4. fabri-0.1.0/pyproject.toml +57 -0
  5. fabri-0.1.0/setup.cfg +4 -0
  6. fabri-0.1.0/src/fabri/__init__.py +35 -0
  7. fabri-0.1.0/src/fabri/admin.py +73 -0
  8. fabri-0.1.0/src/fabri/cli.py +182 -0
  9. fabri-0.1.0/src/fabri/config.py +76 -0
  10. fabri-0.1.0/src/fabri/core/__init__.py +0 -0
  11. fabri-0.1.0/src/fabri/core/agent.py +229 -0
  12. fabri-0.1.0/src/fabri/core/decompose.py +65 -0
  13. fabri-0.1.0/src/fabri/core/llm.py +254 -0
  14. fabri-0.1.0/src/fabri/core/logging_setup.py +42 -0
  15. fabri-0.1.0/src/fabri/core/outcome.py +8 -0
  16. fabri-0.1.0/src/fabri/memory/__init__.py +0 -0
  17. fabri-0.1.0/src/fabri/memory/compress.py +34 -0
  18. fabri-0.1.0/src/fabri/memory/embeddings.py +17 -0
  19. fabri-0.1.0/src/fabri/memory/pruning.py +76 -0
  20. fabri-0.1.0/src/fabri/memory/schema.py +50 -0
  21. fabri-0.1.0/src/fabri/memory/store.py +83 -0
  22. fabri-0.1.0/src/fabri/orchestrator/__init__.py +0 -0
  23. fabri-0.1.0/src/fabri/orchestrator/pipeline.py +56 -0
  24. fabri-0.1.0/src/fabri/orchestrator/retrieval.py +45 -0
  25. fabri-0.1.0/src/fabri/orchestrator/traces.py +22 -0
  26. fabri-0.1.0/src/fabri/paths.py +27 -0
  27. fabri-0.1.0/src/fabri/runtime.py +68 -0
  28. fabri-0.1.0/src/fabri/scaffold.py +104 -0
  29. fabri-0.1.0/src/fabri/tools/__init__.py +0 -0
  30. fabri-0.1.0/src/fabri/tools/agent_runner_tool.py +49 -0
  31. fabri-0.1.0/src/fabri/tools/agent_tool.py +34 -0
  32. fabri-0.1.0/src/fabri/tools/examples/bash.json +12 -0
  33. fabri-0.1.0/src/fabri/tools/examples/bash.py +54 -0
  34. fabri-0.1.0/src/fabri/tools/examples/broken_tool.json +8 -0
  35. fabri-0.1.0/src/fabri/tools/examples/broken_tool.py +7 -0
  36. fabri-0.1.0/src/fabri/tools/examples/echo_tool.json +8 -0
  37. fabri-0.1.0/src/fabri/tools/examples/echo_tool.py +5 -0
  38. fabri-0.1.0/src/fabri/tools/examples/edit_file.json +17 -0
  39. fabri-0.1.0/src/fabri/tools/examples/edit_file.py +48 -0
  40. fabri-0.1.0/src/fabri/tools/examples/example_go_tool/go.mod +3 -0
  41. fabri-0.1.0/src/fabri/tools/examples/example_go_tool/main.go +28 -0
  42. fabri-0.1.0/src/fabri/tools/examples/fetch_url.json +12 -0
  43. fabri-0.1.0/src/fabri/tools/examples/fetch_url.py +40 -0
  44. fabri-0.1.0/src/fabri/tools/examples/grep.json +16 -0
  45. fabri-0.1.0/src/fabri/tools/examples/grep.py +62 -0
  46. fabri-0.1.0/src/fabri/tools/examples/list_dir.json +8 -0
  47. fabri-0.1.0/src/fabri/tools/examples/list_dir.py +35 -0
  48. fabri-0.1.0/src/fabri/tools/examples/mcp_tool.json +16 -0
  49. fabri-0.1.0/src/fabri/tools/examples/mcp_tool.py +37 -0
  50. fabri-0.1.0/src/fabri/tools/examples/python_exec.json +12 -0
  51. fabri-0.1.0/src/fabri/tools/examples/python_exec.py +52 -0
  52. fabri-0.1.0/src/fabri/tools/examples/read_file.json +8 -0
  53. fabri-0.1.0/src/fabri/tools/examples/read_file.py +31 -0
  54. fabri-0.1.0/src/fabri/tools/examples/sum_tool.json +8 -0
  55. fabri-0.1.0/src/fabri/tools/examples/web_search.json +8 -0
  56. fabri-0.1.0/src/fabri/tools/examples/web_search.py +37 -0
  57. fabri-0.1.0/src/fabri/tools/examples/write_file.json +12 -0
  58. fabri-0.1.0/src/fabri/tools/examples/write_file.py +30 -0
  59. fabri-0.1.0/src/fabri/tools/manifest_schema.py +34 -0
  60. fabri-0.1.0/src/fabri/tools/registry.py +34 -0
  61. fabri-0.1.0/src/fabri/tools/runner.py +71 -0
  62. fabri-0.1.0/src/fabri/toon.py +354 -0
  63. fabri-0.1.0/src/fabri.egg-info/PKG-INFO +243 -0
  64. fabri-0.1.0/src/fabri.egg-info/SOURCES.txt +83 -0
  65. fabri-0.1.0/src/fabri.egg-info/dependency_links.txt +1 -0
  66. fabri-0.1.0/src/fabri.egg-info/entry_points.txt +2 -0
  67. fabri-0.1.0/src/fabri.egg-info/requires.txt +13 -0
  68. fabri-0.1.0/src/fabri.egg-info/top_level.txt +1 -0
  69. fabri-0.1.0/tests/test_cli_init.py +43 -0
  70. fabri-0.1.0/tests/test_compress.py +14 -0
  71. fabri-0.1.0/tests/test_e2e_agent_loop.py +193 -0
  72. fabri-0.1.0/tests/test_e2e_config_and_admin.py +136 -0
  73. fabri-0.1.0/tests/test_memory_store.py +61 -0
  74. fabri-0.1.0/tests/test_pruning.py +85 -0
  75. fabri-0.1.0/tests/test_retrieval.py +56 -0
  76. fabri-0.1.0/tests/test_tool_runner.py +42 -0
  77. fabri-0.1.0/tests/test_toon.py +125 -0
  78. fabri-0.1.0/tests/test_unit_agent_runner_tool.py +36 -0
  79. fabri-0.1.0/tests/test_unit_decompose.py +66 -0
  80. fabri-0.1.0/tests/test_unit_file_tools.py +168 -0
  81. fabri-0.1.0/tests/test_unit_manifest_schema.py +60 -0
  82. fabri-0.1.0/tests/test_unit_new_tools.py +186 -0
  83. fabri-0.1.0/tests/test_unit_outcome_classification.py +74 -0
  84. fabri-0.1.0/tests/test_unit_registry.py +79 -0
  85. fabri-0.1.0/tests/test_unit_runtime.py +90 -0
fabri-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 Derivative
95
+ 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 those 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Rushikesh Patade
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
fabri-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabri
3
+ Version: 0.1.0
4
+ Summary: A local memory + orchestration framework for custom LLM agents: tactical/strategic memory over execution traces, polyglot subprocess tools, agent-as-tool composition, and token-efficient TOON I/O.
5
+ Author-email: Rushikesh Patade <pataderushikesh@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Rushour0/fabri
8
+ Project-URL: Repository, https://github.com/Rushour0/fabri
9
+ Project-URL: Issues, https://github.com/Rushour0/fabri/issues
10
+ Keywords: llm,agent,agents,memory,anthropic,claude,openai,qdrant,orchestration,toon,react,tool-use
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: qdrant-client>=1.9
23
+ Requires-Dist: sentence-transformers>=3.0
24
+ Requires-Dist: anthropic>=0.40
25
+ Requires-Dist: tiktoken>=0.7
26
+ Requires-Dist: pyyaml>=6.0
27
+ Provides-Extra: openai
28
+ Requires-Dist: openai>=1.0; extra == "openai"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0; extra == "dev"
31
+ Requires-Dist: build>=1.0; extra == "dev"
32
+ Requires-Dist: twine>=5.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # fabri
36
+
37
+ A local, open-source memory + orchestration layer for a custom LLM agent.
38
+ Built around two ideas:
39
+
40
+ - **SCOPE** (arXiv:2512.15374): treat the agent's prompt context as something
41
+ that evolves automatically from execution traces, via a tactical/strategic
42
+ memory split with conflict resolution before promotion.
43
+ - Context engineering over prompt engineering: keep retrieved context
44
+ compact and just-in-time, give each tool a single clear job, and let tools
45
+ be polyglot processes behind a uniform JSON contract.
46
+
47
+ ## Quickstart
48
+
49
+ ```bash
50
+ pip install fabri # the `fabri` console command lands on your PATH
51
+ docker run -p 6333:6333 qdrant/qdrant # vector store for the agent's memory
52
+ export ANTHROPIC_API_KEY=...
53
+
54
+ fabri init demo && cd demo # scaffold a runnable starter project
55
+ fabri --config agent.yaml run "greet Ada with the hello tool"
56
+ ```
57
+
58
+ `fabri init` writes an `agent.yaml`, an example tool under `tools/agent_tools/`,
59
+ and a `docker-compose.yml` — edit those, not the library. For OpenAI models,
60
+ `pip install "fabri[openai]"` and set `llm.provider: openai`.
61
+
62
+ ## Setup (from a checkout)
63
+
64
+ ```bash
65
+ docker compose up -d # starts Qdrant on :6333
66
+ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
67
+ export ANTHROPIC_API_KEY=... # only needed for AnthropicLLMBackend
68
+ ```
69
+
70
+ Installing puts a `fabri` console command on your PATH — that's the entry point
71
+ everything below uses. Embeddings run fully locally via
72
+ `sentence-transformers/all-MiniLM-L6-v2` — no embedding API calls, no cloud
73
+ dependency beyond the LLM itself.
74
+
75
+ ## Usage
76
+
77
+ ```bash
78
+ fabri run "some task description"
79
+ fabri --config agent.yaml run "some task description" # config-driven agent, see docs/creating-an-agent.md
80
+ fabri --verbose run "some task description" # DEBUG logging to console too
81
+ fabri inspect-memory "a query to test retrieval"
82
+ fabri ingest-traces <session-id>
83
+ ```
84
+
85
+ (`python cli.py ...` still works from a source checkout — it's a thin shim over
86
+ the same `fabri.cli:main` the console script points at.)
87
+
88
+ See `docs/creating-an-agent.md` for using this as a library/framework in
89
+ another project: installing it, writing an `agent.yaml`, adding tools, and a
90
+ worked example.
91
+
92
+ `run` executes the agent loop, then immediately mines the resulting trace for
93
+ failures and synthesizes any new guidelines. `ingest-traces` re-runs that
94
+ synthesis step against a past session's trace on its own. `run` and
95
+ `ingest-traces` both require `ANTHROPIC_API_KEY` (they fail fast with a clear
96
+ message if it's unset, rather than a raw stack trace) — `inspect-memory` does
97
+ not, since it only talks to Qdrant.
98
+
99
+ Every run produces two records, both keyed by `session_id`: a structured
100
+ JSONL trace (`.fabri/traces/<session_id>.jsonl`, the machine-readable
101
+ record used by the pipeline) and a human-readable log
102
+ (`.fabri/logs/<session_id>.log`, always
103
+ DEBUG-level regardless of `--verbose` — that flag only controls what's also
104
+ echoed to the console) with LLM call latency/token usage, tool dispatch
105
+ latency, and every promotion/dedup decision the pipeline makes.
106
+
107
+ Both land under `.fabri/` in the directory you run from (override with
108
+ `$FABRI_HOME`), so each consuming project keeps its own traces and logs
109
+ rather than scattering them into wherever the package happens to be installed.
110
+ Add `.fabri/` to your project's `.gitignore`.
111
+
112
+ Each run returns an `outcome`: `success` (clean), `success_with_recovery`
113
+ (finished, but at least one tool call failed along the way), or `incomplete`
114
+ (hit the step limit with no final answer).
115
+
116
+ ## Architecture
117
+
118
+ ```
119
+ src/fabri/ # src/ layout: repo is "fabri", package is "fabri"
120
+ memory/ embeddings, schema, Qdrant store, compression, pruning/promotion
121
+ orchestrator/ retrieval, trace logging, the trace -> guideline pipeline
122
+ tools/ manifest schema, subprocess runner, example tools, agent-as-tool adapter
123
+ core/ the ReAct agent loop, decompose, and the pluggable LLM backend
124
+ runtime.py build_llm/build_tools/build_tool_defs -- shared by cli and agent_runner_tool
125
+ admin.py admin-only config inspection + dashboard (stub auth seam, see below)
126
+ config.py YAML agent config loader (DEFAULT_CONFIG + load_config)
127
+ toon.py TOON codec: compact JSON-shaped encoding for tool results (token savings)
128
+ paths.py project-local .fabri/ resolution for traces + logs
129
+ cli.py the `fabri` console command (composition over the public API)
130
+ __init__.py public API: run_agent, load_config, ToolRegistry, QdrantMemoryStore, ...
131
+ cli.py thin shim: `python cli.py ...` -> fabri.cli:main
132
+ ```
133
+
134
+ ### Agents as tools
135
+
136
+ A `tools.agents` entry in a config exposes a *different* agent.yaml as a tool
137
+ on this one (`fabri/tools/agent_tool.py` builds the manifest,
138
+ `agent_runner_tool.py` runs the sub-agent as an ordinary subprocess tool —
139
+ stdin `{"task": ...}`, stdout `{"final_text", "outcome"}`). This is
140
+ composition, not a new orchestrator: each sub-agent is just another tool call
141
+ in the parent's normal ReAct loop. See `ludexel/.agent/game_content_agent.yaml`
142
+ for a worked example wiring four domain agents (character/tiles/map/story)
143
+ into one top-level agent.
144
+
145
+ ### Admin CLI / dashboard
146
+
147
+ `cli.py admin config --config agent.yaml` prints the merged config plus the
148
+ resolved tool registry as JSON; `cli.py admin dashboard --config agent.yaml`
149
+ prints a human-readable summary (agent/llm/tools/memory counts). Both are
150
+ gated by `require_admin()` (`fabri/admin.py`): if `FABRI_ADMIN_TOKEN`
151
+ is unset the gate is open (no auth backend exists yet), but once it's set,
152
+ `--admin-token` must match it. This is a placeholder seam for real auth
153
+ (SSO/API gateway/etc.), not a security boundary by itself.
154
+
155
+ ### Tool contract
156
+
157
+ A tool is a JSON manifest (`name`, `description`, `command`, schemas, timeout)
158
+ next to an executable in any language. `runner.py` invokes `command` as a
159
+ subprocess, writes the call's args as JSON to stdin, and parses stdout as
160
+ JSON. The result is always normalized to `{ok, error?, result?, stderr?}`
161
+ before the agent sees it — malformed output, timeouts, and tool error exits
162
+ are distinct, well-defined failure modes rather than crashes. See
163
+ `tools/examples/` for a Python tool (`echo`), a Go tool (`sum`), and a
164
+ deliberately misbehaving tool (`broken`) used only by the test suite.
165
+
166
+ ### Token efficiency (TOON)
167
+
168
+ Tool results are encoded into the model's context as **TOON**
169
+ (Token-Oriented Object Notation, `toon.py`) rather than JSON by default — a
170
+ compact indentation-based encoding that drops braces and collapses uniform
171
+ arrays to a single header row plus data rows, typically ~30–40% fewer
172
+ characters on tabular results. The framework encodes this itself (no model
173
+ reliability risk); the trace/logs keep raw JSON. Pipeline: `json → toon → llm`
174
+ inbound, and JSON outbound by default (`tools.result_format`,
175
+ `agent.output_format` — see `docs/creating-an-agent.md`). Native tool-call
176
+ arguments stay provider JSON. The codec round-trips any JSON-shaped value and
177
+ `fabri.toon.encode`/`.decode` are public.
178
+
179
+ ### Memory lifecycle
180
+
181
+ 1. Every agent run logs a JSONL trace (`traces/<session_id>.jsonl`).
182
+ 2. `orchestrator/pipeline.py` scans a trace for tool-call failures and asks
183
+ the LLM to compress each into a short, generalized guideline
184
+ (`memory/compress.py` enforces a hard token cap regardless of what the
185
+ LLM returns).
186
+ 3. `memory/pruning.py` checks the new guideline against existing **tactical**
187
+ entries by cosine similarity. A near-duplicate increments that entry's
188
+ recurrence count instead of inserting a copy; once it has recurred across
189
+ 3 distinct sessions (`PROMOTION_THRESHOLD_SESSIONS`), it's promoted to
190
+ **strategic**.
191
+ 4. `orchestrator/retrieval.py` embeds the next task, pulls the top-k most
192
+ relevant guidelines (tactical + strategic) from Qdrant, and formats them
193
+ as a compact bullet list injected into the agent's system prompt. If any
194
+ available tool's name appears in the task text, a second query filters by
195
+ that tool's tag (`MemoryEntry.tools`, populated in step 2 from whichever
196
+ tool actually failed) and those hits are *guaranteed* inclusion — this
197
+ surfaces tool-specific guidelines even when their wording is too
198
+ dissimilar from the query for cosine similarity alone to rank them in the
199
+ top-k. (A graph-DB-backed version of this was considered and rejected: the
200
+ only capability needed was a single-hop "guidelines for this tool" lookup,
201
+ which a payload filter gives you for free — a second database would have
202
+ added a dependency, a migration risk, and a way for the graph and the
203
+ vector store to drift out of sync, for no real capability gain.)
204
+
205
+ This is what closes the loop: a failure in session N becomes retrievable
206
+ context in session N+1, without a human re-writing the prompt by hand.
207
+
208
+ ## Known v1 limitations (intentional, not bugs)
209
+
210
+ - **No embedding-model migration path.** Each memory point stores a
211
+ `model_version` payload field, but swapping the embedding model means
212
+ recreating the Qdrant collection from scratch — old vectors are not
213
+ re-embedded automatically.
214
+ - **Single-writer assumption.** Concurrent *distinct* agent processes
215
+ ingesting guidelines at the same time are not locked against each other.
216
+ This is made safe-by-construction for the common case (same guideline
217
+ text) via deterministic point IDs (hash of the compressed text), but two
218
+ different writers racing on genuinely different new guidelines is
219
+ untested.
220
+ - **No automatic eviction.** `memory/pruning.py:evict_stale` exists but is
221
+ not wired into a scheduled job — run it manually if the strategic store
222
+ grows large with low-value entries.
223
+
224
+ ## Tests
225
+
226
+ ```bash
227
+ .venv/bin/python -m pytest tests/ -q
228
+ ```
229
+
230
+ Covers store round-trip/idempotency, the dedup + promotion rule, the tool
231
+ runner's normalized failure contract (Python + Go + malformed output +
232
+ timeout), the token-cap enforcement in `compress.py`, the TOON codec
233
+ (round-trip + fuzz), and the `fabri init` scaffold.
234
+
235
+ ## Releasing
236
+
237
+ Tag a version (`git tag v0.1.0 && git push origin v0.1.0`) and GitHub Actions
238
+ publishes to PyPI via Trusted Publishing — see `RELEASING.md` for the one-time
239
+ setup.
240
+
241
+ ## License
242
+
243
+ [Apache-2.0](LICENSE) © Rushikesh Patade.
fabri-0.1.0/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # fabri
2
+
3
+ A local, open-source memory + orchestration layer for a custom LLM agent.
4
+ Built around two ideas:
5
+
6
+ - **SCOPE** (arXiv:2512.15374): treat the agent's prompt context as something
7
+ that evolves automatically from execution traces, via a tactical/strategic
8
+ memory split with conflict resolution before promotion.
9
+ - Context engineering over prompt engineering: keep retrieved context
10
+ compact and just-in-time, give each tool a single clear job, and let tools
11
+ be polyglot processes behind a uniform JSON contract.
12
+
13
+ ## Quickstart
14
+
15
+ ```bash
16
+ pip install fabri # the `fabri` console command lands on your PATH
17
+ docker run -p 6333:6333 qdrant/qdrant # vector store for the agent's memory
18
+ export ANTHROPIC_API_KEY=...
19
+
20
+ fabri init demo && cd demo # scaffold a runnable starter project
21
+ fabri --config agent.yaml run "greet Ada with the hello tool"
22
+ ```
23
+
24
+ `fabri init` writes an `agent.yaml`, an example tool under `tools/agent_tools/`,
25
+ and a `docker-compose.yml` — edit those, not the library. For OpenAI models,
26
+ `pip install "fabri[openai]"` and set `llm.provider: openai`.
27
+
28
+ ## Setup (from a checkout)
29
+
30
+ ```bash
31
+ docker compose up -d # starts Qdrant on :6333
32
+ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
33
+ export ANTHROPIC_API_KEY=... # only needed for AnthropicLLMBackend
34
+ ```
35
+
36
+ Installing puts a `fabri` console command on your PATH — that's the entry point
37
+ everything below uses. Embeddings run fully locally via
38
+ `sentence-transformers/all-MiniLM-L6-v2` — no embedding API calls, no cloud
39
+ dependency beyond the LLM itself.
40
+
41
+ ## Usage
42
+
43
+ ```bash
44
+ fabri run "some task description"
45
+ fabri --config agent.yaml run "some task description" # config-driven agent, see docs/creating-an-agent.md
46
+ fabri --verbose run "some task description" # DEBUG logging to console too
47
+ fabri inspect-memory "a query to test retrieval"
48
+ fabri ingest-traces <session-id>
49
+ ```
50
+
51
+ (`python cli.py ...` still works from a source checkout — it's a thin shim over
52
+ the same `fabri.cli:main` the console script points at.)
53
+
54
+ See `docs/creating-an-agent.md` for using this as a library/framework in
55
+ another project: installing it, writing an `agent.yaml`, adding tools, and a
56
+ worked example.
57
+
58
+ `run` executes the agent loop, then immediately mines the resulting trace for
59
+ failures and synthesizes any new guidelines. `ingest-traces` re-runs that
60
+ synthesis step against a past session's trace on its own. `run` and
61
+ `ingest-traces` both require `ANTHROPIC_API_KEY` (they fail fast with a clear
62
+ message if it's unset, rather than a raw stack trace) — `inspect-memory` does
63
+ not, since it only talks to Qdrant.
64
+
65
+ Every run produces two records, both keyed by `session_id`: a structured
66
+ JSONL trace (`.fabri/traces/<session_id>.jsonl`, the machine-readable
67
+ record used by the pipeline) and a human-readable log
68
+ (`.fabri/logs/<session_id>.log`, always
69
+ DEBUG-level regardless of `--verbose` — that flag only controls what's also
70
+ echoed to the console) with LLM call latency/token usage, tool dispatch
71
+ latency, and every promotion/dedup decision the pipeline makes.
72
+
73
+ Both land under `.fabri/` in the directory you run from (override with
74
+ `$FABRI_HOME`), so each consuming project keeps its own traces and logs
75
+ rather than scattering them into wherever the package happens to be installed.
76
+ Add `.fabri/` to your project's `.gitignore`.
77
+
78
+ Each run returns an `outcome`: `success` (clean), `success_with_recovery`
79
+ (finished, but at least one tool call failed along the way), or `incomplete`
80
+ (hit the step limit with no final answer).
81
+
82
+ ## Architecture
83
+
84
+ ```
85
+ src/fabri/ # src/ layout: repo is "fabri", package is "fabri"
86
+ memory/ embeddings, schema, Qdrant store, compression, pruning/promotion
87
+ orchestrator/ retrieval, trace logging, the trace -> guideline pipeline
88
+ tools/ manifest schema, subprocess runner, example tools, agent-as-tool adapter
89
+ core/ the ReAct agent loop, decompose, and the pluggable LLM backend
90
+ runtime.py build_llm/build_tools/build_tool_defs -- shared by cli and agent_runner_tool
91
+ admin.py admin-only config inspection + dashboard (stub auth seam, see below)
92
+ config.py YAML agent config loader (DEFAULT_CONFIG + load_config)
93
+ toon.py TOON codec: compact JSON-shaped encoding for tool results (token savings)
94
+ paths.py project-local .fabri/ resolution for traces + logs
95
+ cli.py the `fabri` console command (composition over the public API)
96
+ __init__.py public API: run_agent, load_config, ToolRegistry, QdrantMemoryStore, ...
97
+ cli.py thin shim: `python cli.py ...` -> fabri.cli:main
98
+ ```
99
+
100
+ ### Agents as tools
101
+
102
+ A `tools.agents` entry in a config exposes a *different* agent.yaml as a tool
103
+ on this one (`fabri/tools/agent_tool.py` builds the manifest,
104
+ `agent_runner_tool.py` runs the sub-agent as an ordinary subprocess tool —
105
+ stdin `{"task": ...}`, stdout `{"final_text", "outcome"}`). This is
106
+ composition, not a new orchestrator: each sub-agent is just another tool call
107
+ in the parent's normal ReAct loop. See `ludexel/.agent/game_content_agent.yaml`
108
+ for a worked example wiring four domain agents (character/tiles/map/story)
109
+ into one top-level agent.
110
+
111
+ ### Admin CLI / dashboard
112
+
113
+ `cli.py admin config --config agent.yaml` prints the merged config plus the
114
+ resolved tool registry as JSON; `cli.py admin dashboard --config agent.yaml`
115
+ prints a human-readable summary (agent/llm/tools/memory counts). Both are
116
+ gated by `require_admin()` (`fabri/admin.py`): if `FABRI_ADMIN_TOKEN`
117
+ is unset the gate is open (no auth backend exists yet), but once it's set,
118
+ `--admin-token` must match it. This is a placeholder seam for real auth
119
+ (SSO/API gateway/etc.), not a security boundary by itself.
120
+
121
+ ### Tool contract
122
+
123
+ A tool is a JSON manifest (`name`, `description`, `command`, schemas, timeout)
124
+ next to an executable in any language. `runner.py` invokes `command` as a
125
+ subprocess, writes the call's args as JSON to stdin, and parses stdout as
126
+ JSON. The result is always normalized to `{ok, error?, result?, stderr?}`
127
+ before the agent sees it — malformed output, timeouts, and tool error exits
128
+ are distinct, well-defined failure modes rather than crashes. See
129
+ `tools/examples/` for a Python tool (`echo`), a Go tool (`sum`), and a
130
+ deliberately misbehaving tool (`broken`) used only by the test suite.
131
+
132
+ ### Token efficiency (TOON)
133
+
134
+ Tool results are encoded into the model's context as **TOON**
135
+ (Token-Oriented Object Notation, `toon.py`) rather than JSON by default — a
136
+ compact indentation-based encoding that drops braces and collapses uniform
137
+ arrays to a single header row plus data rows, typically ~30–40% fewer
138
+ characters on tabular results. The framework encodes this itself (no model
139
+ reliability risk); the trace/logs keep raw JSON. Pipeline: `json → toon → llm`
140
+ inbound, and JSON outbound by default (`tools.result_format`,
141
+ `agent.output_format` — see `docs/creating-an-agent.md`). Native tool-call
142
+ arguments stay provider JSON. The codec round-trips any JSON-shaped value and
143
+ `fabri.toon.encode`/`.decode` are public.
144
+
145
+ ### Memory lifecycle
146
+
147
+ 1. Every agent run logs a JSONL trace (`traces/<session_id>.jsonl`).
148
+ 2. `orchestrator/pipeline.py` scans a trace for tool-call failures and asks
149
+ the LLM to compress each into a short, generalized guideline
150
+ (`memory/compress.py` enforces a hard token cap regardless of what the
151
+ LLM returns).
152
+ 3. `memory/pruning.py` checks the new guideline against existing **tactical**
153
+ entries by cosine similarity. A near-duplicate increments that entry's
154
+ recurrence count instead of inserting a copy; once it has recurred across
155
+ 3 distinct sessions (`PROMOTION_THRESHOLD_SESSIONS`), it's promoted to
156
+ **strategic**.
157
+ 4. `orchestrator/retrieval.py` embeds the next task, pulls the top-k most
158
+ relevant guidelines (tactical + strategic) from Qdrant, and formats them
159
+ as a compact bullet list injected into the agent's system prompt. If any
160
+ available tool's name appears in the task text, a second query filters by
161
+ that tool's tag (`MemoryEntry.tools`, populated in step 2 from whichever
162
+ tool actually failed) and those hits are *guaranteed* inclusion — this
163
+ surfaces tool-specific guidelines even when their wording is too
164
+ dissimilar from the query for cosine similarity alone to rank them in the
165
+ top-k. (A graph-DB-backed version of this was considered and rejected: the
166
+ only capability needed was a single-hop "guidelines for this tool" lookup,
167
+ which a payload filter gives you for free — a second database would have
168
+ added a dependency, a migration risk, and a way for the graph and the
169
+ vector store to drift out of sync, for no real capability gain.)
170
+
171
+ This is what closes the loop: a failure in session N becomes retrievable
172
+ context in session N+1, without a human re-writing the prompt by hand.
173
+
174
+ ## Known v1 limitations (intentional, not bugs)
175
+
176
+ - **No embedding-model migration path.** Each memory point stores a
177
+ `model_version` payload field, but swapping the embedding model means
178
+ recreating the Qdrant collection from scratch — old vectors are not
179
+ re-embedded automatically.
180
+ - **Single-writer assumption.** Concurrent *distinct* agent processes
181
+ ingesting guidelines at the same time are not locked against each other.
182
+ This is made safe-by-construction for the common case (same guideline
183
+ text) via deterministic point IDs (hash of the compressed text), but two
184
+ different writers racing on genuinely different new guidelines is
185
+ untested.
186
+ - **No automatic eviction.** `memory/pruning.py:evict_stale` exists but is
187
+ not wired into a scheduled job — run it manually if the strategic store
188
+ grows large with low-value entries.
189
+
190
+ ## Tests
191
+
192
+ ```bash
193
+ .venv/bin/python -m pytest tests/ -q
194
+ ```
195
+
196
+ Covers store round-trip/idempotency, the dedup + promotion rule, the tool
197
+ runner's normalized failure contract (Python + Go + malformed output +
198
+ timeout), the token-cap enforcement in `compress.py`, the TOON codec
199
+ (round-trip + fuzz), and the `fabri init` scaffold.
200
+
201
+ ## Releasing
202
+
203
+ Tag a version (`git tag v0.1.0 && git push origin v0.1.0`) and GitHub Actions
204
+ publishes to PyPI via Trusted Publishing — see `RELEASING.md` for the one-time
205
+ setup.
206
+
207
+ ## License
208
+
209
+ [Apache-2.0](LICENSE) © Rushikesh Patade.