tensorcode 0.1.0a1__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 (54) hide show
  1. tensorcode-0.1.0a1/.gitignore +165 -0
  2. tensorcode-0.1.0a1/LICENSE +21 -0
  3. tensorcode-0.1.0a1/PKG-INFO +196 -0
  4. tensorcode-0.1.0a1/README.md +156 -0
  5. tensorcode-0.1.0a1/pyproject.toml +54 -0
  6. tensorcode-0.1.0a1/src/tensorcode/__init__.py +84 -0
  7. tensorcode-0.1.0a1/src/tensorcode/actions.py +137 -0
  8. tensorcode-0.1.0a1/src/tensorcode/answer_type.py +222 -0
  9. tensorcode-0.1.0a1/src/tensorcode/awareness.py +344 -0
  10. tensorcode-0.1.0a1/src/tensorcode/backends/__init__.py +0 -0
  11. tensorcode-0.1.0a1/src/tensorcode/backends/builtin.py +167 -0
  12. tensorcode-0.1.0a1/src/tensorcode/backends/hf_local.py +89 -0
  13. tensorcode-0.1.0a1/src/tensorcode/backends/linear.py +133 -0
  14. tensorcode-0.1.0a1/src/tensorcode/backends/neural.py +361 -0
  15. tensorcode-0.1.0a1/src/tensorcode/causal.py +262 -0
  16. tensorcode-0.1.0a1/src/tensorcode/change.py +566 -0
  17. tensorcode-0.1.0a1/src/tensorcode/chunking.py +195 -0
  18. tensorcode-0.1.0a1/src/tensorcode/cognition.py +311 -0
  19. tensorcode-0.1.0a1/src/tensorcode/context.py +97 -0
  20. tensorcode-0.1.0a1/src/tensorcode/control.py +291 -0
  21. tensorcode-0.1.0a1/src/tensorcode/cues.py +192 -0
  22. tensorcode-0.1.0a1/src/tensorcode/expectation.py +270 -0
  23. tensorcode-0.1.0a1/src/tensorcode/frames.py +232 -0
  24. tensorcode-0.1.0a1/src/tensorcode/language/__init__.py +36 -0
  25. tensorcode-0.1.0a1/src/tensorcode/language/chart.py +558 -0
  26. tensorcode-0.1.0a1/src/tensorcode/language/discourse.py +132 -0
  27. tensorcode-0.1.0a1/src/tensorcode/language/domains/__init__.py +0 -0
  28. tensorcode-0.1.0a1/src/tensorcode/language/domains/desktop.py +552 -0
  29. tensorcode-0.1.0a1/src/tensorcode/language/english.py +459 -0
  30. tensorcode-0.1.0a1/src/tensorcode/language/features.py +112 -0
  31. tensorcode-0.1.0a1/src/tensorcode/language/generate.py +574 -0
  32. tensorcode-0.1.0a1/src/tensorcode/language/grammar.py +893 -0
  33. tensorcode-0.1.0a1/src/tensorcode/language/semantics.py +349 -0
  34. tensorcode-0.1.0a1/src/tensorcode/learning/__init__.py +30 -0
  35. tensorcode-0.1.0a1/src/tensorcode/learning/certificate.py +148 -0
  36. tensorcode-0.1.0a1/src/tensorcode/learning/induce.py +304 -0
  37. tensorcode-0.1.0a1/src/tensorcode/learning/library.py +217 -0
  38. tensorcode-0.1.0a1/src/tensorcode/learning/literals.py +126 -0
  39. tensorcode-0.1.0a1/src/tensorcode/learning/verify.py +253 -0
  40. tensorcode-0.1.0a1/src/tensorcode/memory.py +303 -0
  41. tensorcode-0.1.0a1/src/tensorcode/metacognition.py +351 -0
  42. tensorcode-0.1.0a1/src/tensorcode/ops.py +207 -0
  43. tensorcode-0.1.0a1/src/tensorcode/outcomes.py +99 -0
  44. tensorcode-0.1.0a1/src/tensorcode/permanence.py +376 -0
  45. tensorcode-0.1.0a1/src/tensorcode/priming.py +191 -0
  46. tensorcode-0.1.0a1/src/tensorcode/py.typed +0 -0
  47. tensorcode-0.1.0a1/src/tensorcode/quantity.py +311 -0
  48. tensorcode-0.1.0a1/src/tensorcode/records.py +728 -0
  49. tensorcode-0.1.0a1/src/tensorcode/relation.py +771 -0
  50. tensorcode-0.1.0a1/src/tensorcode/runtime.py +471 -0
  51. tensorcode-0.1.0a1/src/tensorcode/semantics_bridge.py +308 -0
  52. tensorcode-0.1.0a1/src/tensorcode/social.py +380 -0
  53. tensorcode-0.1.0a1/src/tensorcode/temporal.py +189 -0
  54. tensorcode-0.1.0a1/src/tensorcode/wants.py +185 -0
@@ -0,0 +1,165 @@
1
+ # https://github.com/github/gitignore/blob/main/Python.gitignore
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/#use-with-ide
112
+ .pdm.toml
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ # generated demo data (Banking77 test messages)
165
+ examples/browser_agents/web/data/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2026 Jacob Valdez
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,196 @@
1
+ Metadata-Version: 2.5
2
+ Name: tensorcode
3
+ Version: 0.1.0a1
4
+ Summary: Typed cognitive operations with swappable implementations: rules, learned models, or general models, chosen by policy
5
+ Project-URL: Homepage, https://github.com/TensaCo/tensacode-py
6
+ Project-URL: Source, https://github.com/TensaCo/tensacode-py
7
+ Project-URL: Issues, https://github.com/TensaCo/tensacode-py/issues
8
+ Project-URL: Design, https://github.com/TensaCo/tensacode-py/tree/main/docs/revival
9
+ Author-email: Jacob Valdez <jacob.valdez@tensaco.ai>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,cascade,cognitive-architecture,neurosymbolic,typed-operations
13
+ Classifier: Development Status :: 2 - Pre-Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Provides-Extra: dev
27
+ Requires-Dist: numpy>=1.26; extra == 'dev'
28
+ Requires-Dist: pydantic>=2.5; extra == 'dev'
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Provides-Extra: learned
31
+ Requires-Dist: numpy>=1.26; extra == 'learned'
32
+ Requires-Dist: scikit-learn>=1.5; extra == 'learned'
33
+ Provides-Extra: learned-neural
34
+ Requires-Dist: torch>=2.1; extra == 'learned-neural'
35
+ Requires-Dist: transformers>=4.40; extra == 'learned-neural'
36
+ Provides-Extra: local-model
37
+ Requires-Dist: torch>=2.4; extra == 'local-model'
38
+ Requires-Dist: transformers>=4.45; extra == 'local-model'
39
+ Description-Content-Type: text/markdown
40
+
41
+ # TensorCode
42
+
43
+ **Typed cognitive operations with swappable implementations.** Your program says *what*
44
+ it needs (parse this, classify that, choose an action under these constraints, check this
45
+ claim). A policy decides *which* implementation answers: rules, a learned model, or a
46
+ general model. Every answer is validated against the operation's type, every abstention
47
+ is an explicit value, and every attempt is traced.
48
+
49
+ > **Status: pre-alpha (0.1.0a1).** The API will change. The core has no third-party
50
+ > dependencies. Nothing here calls a language model unless you bind one.
51
+
52
+ ```bash
53
+ pip install --pre tensorcode
54
+ ```
55
+
56
+ Python 3.11+.
57
+
58
+ ## Quick start
59
+
60
+ ```python
61
+ import enum
62
+ import tensorcode as tc
63
+ from tensorcode.backends.builtin import KeywordClassifier
64
+
65
+ class Intent(enum.Enum):
66
+ LOST_CARD = "lost_card"
67
+ REFUND = "refund"
68
+
69
+ print(tc.classify("I lost my card", Intent))
70
+ # Unknown(reason='no_implementation', ...) <- nothing bound: an explicit Unknown, not a guess
71
+
72
+ rules = KeywordClassifier(Intent, {
73
+ Intent.LOST_CARD: [r"\blost\b", r"\bstolen\b"],
74
+ Intent.REFUND: [r"\brefund\b"],
75
+ })
76
+
77
+ @tc.implementation("classify", name="fallback", version="1")
78
+ def ask_a_human(request):
79
+ return tc.Unknown("needs_human", request.subject)
80
+
81
+ with tc.use(tc.Runtime([rules, ask_a_human])) as rt:
82
+ print(tc.classify("I lost my card", Intent)) # Intent.LOST_CARD
83
+ print(tc.classify("where is my parcel?", Intent)) # Unknown(reason='needs_human', ...)
84
+ print(rt.trace.render())
85
+ ```
86
+
87
+ ```text
88
+ classify -> Intent.LOST_CARD [0.04 ms total, 0.01 ms backend]
89
+ - keyword-rules@1 answer
90
+ classify -> {'unknown': 'needs_human', ...} [0.03 ms total, 0.01 ms backend]
91
+ - keyword-rules@1 abstain: no_rule_matched
92
+ - fallback@1 abstain: needs_human, usd=? (unknown)
93
+ ```
94
+
95
+ The program never names a backend. Swap the rules for a scikit-learn classifier or a local
96
+ model by changing the `Runtime`, not the program.
97
+
98
+ ## Core ideas
99
+
100
+ **Operations fix the meaning.** Each facade validates its output and fails closed:
101
+
102
+ | Family | Operations |
103
+ | --- | --- |
104
+ | infer | `parse`, `classify`, `choose`, `rank` |
105
+ | check | `check`, `verify` |
106
+ | rewrite | `propose` (a `Patch`, inert until `Store.apply`) |
107
+ | act | `invoke` (returns a `Receipt`), `Plan`, `run_plan` |
108
+ | context | `pack`, `dedupe` |
109
+
110
+ `classify` estimates what *is true*. `choose` selects what *to do*, under an `Objective`
111
+ and hard `Constraint`s that TensorCode checks itself before any backend sees the options.
112
+
113
+ **Outcome values keep distinctions a caller must not collapse.**
114
+ - `Unknown` is not `False` and not a low-confidence guess. It raises if used as a boolean.
115
+ - `Verdict` has three states. `fails` and `unknown` are different.
116
+ - `Receipt` separates "did not happen" from "may have happened".
117
+ - `Score` says what kind of number it is. A similarity is not a probability, and a
118
+ probability must name the data it was calibrated on.
119
+
120
+ **The runtime binds implementations by policy.** An implementation declares `Traits`
121
+ (locality, egress, determinism, requirements) and a measured `Profile`. `Policy` filters
122
+ on hard constraints and orders a cascade; `Budget` caps cost and attempts across calls.
123
+ Unmeasured means unknown: a missing cost is never counted as zero, and a cost cap excludes
124
+ implementations whose cost is unknown.
125
+
126
+ **Records carry evidence.** `Store` holds entity and claim records with evidence, validity
127
+ intervals and scope, and detects conflicts between them.
128
+
129
+ ## Optional extras
130
+
131
+ | Extra | Installs | For |
132
+ | --- | --- | --- |
133
+ | `learned` | scikit-learn, numpy | `tensorcode.backends.linear` |
134
+ | `local-model` | torch, transformers | `tensorcode.backends.hf_local` |
135
+ | `learned-neural` | torch, transformers | `tensorcode.backends.neural` |
136
+
137
+ ## Examples
138
+
139
+ The examples live in this repository, not in the package. Run them from a checkout:
140
+
141
+ | Example | Command |
142
+ | --- | --- |
143
+ | Recovery after failed or ambiguous actions | `python -m examples.recovery.demo` |
144
+ | Knowledge store: ingest, conflicts, queries | `python -m examples.knowledge.demo` |
145
+ | Packing context into a token budget | `python -m examples.context_select.demo` |
146
+ | Support router (needs the Banking77 train CSV) | `python -m examples.support_router.demo --train banking77_train.csv` |
147
+ | Decision service with HTTP API and operator UI | `python -m examples.decisions.service` |
148
+ | Live browser agents, no model calls (needs `playwright`, `numpy`, `pillow`) | `python -m examples.browser_agents.live` |
149
+
150
+ Expected output is checked in beside each demo (`OUTPUT*.txt`).
151
+
152
+ ## What has been measured, honestly
153
+
154
+ The design notes in [`docs/revival/`](https://github.com/TensaCo/tensacode-py/blob/main/docs/revival/README.md) report measurements,
155
+ including the unflattering ones:
156
+
157
+ - A local zero-shot Qwen3-8B escalation tier **lowered** Banking77 selective accuracy from
158
+ 94.1% to 91.0%. Tiers should be admitted only by measured quality.
159
+ - Recovery logic based on explicit facts made 0 duplicate money movements in 5,000
160
+ simulated episodes, compared with 4.8% for naive retry. The simulator and its fault model
161
+ are the project's own, and with wrong facts about the target system duplicates return (0.9%).
162
+ - The [evidence audit](https://github.com/TensaCo/tensacode-py/blob/main/docs/revival/11-evidence-audit.md) found that 13 of the project's 19
163
+ headline results ran in environments it wrote **and** were graded by code it wrote. On
164
+ public open-domain benchmarks, the cascade did worse than plainly prompting the same
165
+ model on 3 of 4.
166
+
167
+ Treat the agent results as demonstrations, not benchmarks.
168
+
169
+ ## Repository layout
170
+
171
+ ```text
172
+ src/tensorcode/ the package
173
+ tests/ pytest suite (some tests use examples/ and eval/)
174
+ examples/ runnable programs and agents
175
+ eval/ evaluation scripts and result files (eval/results/*.json)
176
+ research/ experiments, including a civilization simulation
177
+ docs/revival/ design notes and measurements
178
+ ```
179
+
180
+ ## Development
181
+
182
+ ```bash
183
+ pip install -e ".[dev,learned]"
184
+ python -m pytest -q
185
+ ```
186
+
187
+ Evaluation scripts read downloaded datasets and trained artifacts from `$TENSORCODE_SCRATCH`
188
+ (default `~/.cache/tensorcode`). Tests that need those artifacts skip when they are absent.
189
+
190
+ The legacy 2023–2024 package (`tensacode`, with `Engine` and TCIR; never published) is
191
+ preserved at the git tag `legacy-2024-11`. It was never functional and is not compatible
192
+ with this one. The PyPI name `tensacode` is a placeholder that installs `tensorcode`.
193
+
194
+ ## License
195
+
196
+ [MIT](https://github.com/TensaCo/tensacode-py/blob/main/LICENSE)
@@ -0,0 +1,156 @@
1
+ # TensorCode
2
+
3
+ **Typed cognitive operations with swappable implementations.** Your program says *what*
4
+ it needs (parse this, classify that, choose an action under these constraints, check this
5
+ claim). A policy decides *which* implementation answers: rules, a learned model, or a
6
+ general model. Every answer is validated against the operation's type, every abstention
7
+ is an explicit value, and every attempt is traced.
8
+
9
+ > **Status: pre-alpha (0.1.0a1).** The API will change. The core has no third-party
10
+ > dependencies. Nothing here calls a language model unless you bind one.
11
+
12
+ ```bash
13
+ pip install --pre tensorcode
14
+ ```
15
+
16
+ Python 3.11+.
17
+
18
+ ## Quick start
19
+
20
+ ```python
21
+ import enum
22
+ import tensorcode as tc
23
+ from tensorcode.backends.builtin import KeywordClassifier
24
+
25
+ class Intent(enum.Enum):
26
+ LOST_CARD = "lost_card"
27
+ REFUND = "refund"
28
+
29
+ print(tc.classify("I lost my card", Intent))
30
+ # Unknown(reason='no_implementation', ...) <- nothing bound: an explicit Unknown, not a guess
31
+
32
+ rules = KeywordClassifier(Intent, {
33
+ Intent.LOST_CARD: [r"\blost\b", r"\bstolen\b"],
34
+ Intent.REFUND: [r"\brefund\b"],
35
+ })
36
+
37
+ @tc.implementation("classify", name="fallback", version="1")
38
+ def ask_a_human(request):
39
+ return tc.Unknown("needs_human", request.subject)
40
+
41
+ with tc.use(tc.Runtime([rules, ask_a_human])) as rt:
42
+ print(tc.classify("I lost my card", Intent)) # Intent.LOST_CARD
43
+ print(tc.classify("where is my parcel?", Intent)) # Unknown(reason='needs_human', ...)
44
+ print(rt.trace.render())
45
+ ```
46
+
47
+ ```text
48
+ classify -> Intent.LOST_CARD [0.04 ms total, 0.01 ms backend]
49
+ - keyword-rules@1 answer
50
+ classify -> {'unknown': 'needs_human', ...} [0.03 ms total, 0.01 ms backend]
51
+ - keyword-rules@1 abstain: no_rule_matched
52
+ - fallback@1 abstain: needs_human, usd=? (unknown)
53
+ ```
54
+
55
+ The program never names a backend. Swap the rules for a scikit-learn classifier or a local
56
+ model by changing the `Runtime`, not the program.
57
+
58
+ ## Core ideas
59
+
60
+ **Operations fix the meaning.** Each facade validates its output and fails closed:
61
+
62
+ | Family | Operations |
63
+ | --- | --- |
64
+ | infer | `parse`, `classify`, `choose`, `rank` |
65
+ | check | `check`, `verify` |
66
+ | rewrite | `propose` (a `Patch`, inert until `Store.apply`) |
67
+ | act | `invoke` (returns a `Receipt`), `Plan`, `run_plan` |
68
+ | context | `pack`, `dedupe` |
69
+
70
+ `classify` estimates what *is true*. `choose` selects what *to do*, under an `Objective`
71
+ and hard `Constraint`s that TensorCode checks itself before any backend sees the options.
72
+
73
+ **Outcome values keep distinctions a caller must not collapse.**
74
+ - `Unknown` is not `False` and not a low-confidence guess. It raises if used as a boolean.
75
+ - `Verdict` has three states. `fails` and `unknown` are different.
76
+ - `Receipt` separates "did not happen" from "may have happened".
77
+ - `Score` says what kind of number it is. A similarity is not a probability, and a
78
+ probability must name the data it was calibrated on.
79
+
80
+ **The runtime binds implementations by policy.** An implementation declares `Traits`
81
+ (locality, egress, determinism, requirements) and a measured `Profile`. `Policy` filters
82
+ on hard constraints and orders a cascade; `Budget` caps cost and attempts across calls.
83
+ Unmeasured means unknown: a missing cost is never counted as zero, and a cost cap excludes
84
+ implementations whose cost is unknown.
85
+
86
+ **Records carry evidence.** `Store` holds entity and claim records with evidence, validity
87
+ intervals and scope, and detects conflicts between them.
88
+
89
+ ## Optional extras
90
+
91
+ | Extra | Installs | For |
92
+ | --- | --- | --- |
93
+ | `learned` | scikit-learn, numpy | `tensorcode.backends.linear` |
94
+ | `local-model` | torch, transformers | `tensorcode.backends.hf_local` |
95
+ | `learned-neural` | torch, transformers | `tensorcode.backends.neural` |
96
+
97
+ ## Examples
98
+
99
+ The examples live in this repository, not in the package. Run them from a checkout:
100
+
101
+ | Example | Command |
102
+ | --- | --- |
103
+ | Recovery after failed or ambiguous actions | `python -m examples.recovery.demo` |
104
+ | Knowledge store: ingest, conflicts, queries | `python -m examples.knowledge.demo` |
105
+ | Packing context into a token budget | `python -m examples.context_select.demo` |
106
+ | Support router (needs the Banking77 train CSV) | `python -m examples.support_router.demo --train banking77_train.csv` |
107
+ | Decision service with HTTP API and operator UI | `python -m examples.decisions.service` |
108
+ | Live browser agents, no model calls (needs `playwright`, `numpy`, `pillow`) | `python -m examples.browser_agents.live` |
109
+
110
+ Expected output is checked in beside each demo (`OUTPUT*.txt`).
111
+
112
+ ## What has been measured, honestly
113
+
114
+ The design notes in [`docs/revival/`](https://github.com/TensaCo/tensacode-py/blob/main/docs/revival/README.md) report measurements,
115
+ including the unflattering ones:
116
+
117
+ - A local zero-shot Qwen3-8B escalation tier **lowered** Banking77 selective accuracy from
118
+ 94.1% to 91.0%. Tiers should be admitted only by measured quality.
119
+ - Recovery logic based on explicit facts made 0 duplicate money movements in 5,000
120
+ simulated episodes, compared with 4.8% for naive retry. The simulator and its fault model
121
+ are the project's own, and with wrong facts about the target system duplicates return (0.9%).
122
+ - The [evidence audit](https://github.com/TensaCo/tensacode-py/blob/main/docs/revival/11-evidence-audit.md) found that 13 of the project's 19
123
+ headline results ran in environments it wrote **and** were graded by code it wrote. On
124
+ public open-domain benchmarks, the cascade did worse than plainly prompting the same
125
+ model on 3 of 4.
126
+
127
+ Treat the agent results as demonstrations, not benchmarks.
128
+
129
+ ## Repository layout
130
+
131
+ ```text
132
+ src/tensorcode/ the package
133
+ tests/ pytest suite (some tests use examples/ and eval/)
134
+ examples/ runnable programs and agents
135
+ eval/ evaluation scripts and result files (eval/results/*.json)
136
+ research/ experiments, including a civilization simulation
137
+ docs/revival/ design notes and measurements
138
+ ```
139
+
140
+ ## Development
141
+
142
+ ```bash
143
+ pip install -e ".[dev,learned]"
144
+ python -m pytest -q
145
+ ```
146
+
147
+ Evaluation scripts read downloaded datasets and trained artifacts from `$TENSORCODE_SCRATCH`
148
+ (default `~/.cache/tensorcode`). Tests that need those artifacts skip when they are absent.
149
+
150
+ The legacy 2023–2024 package (`tensacode`, with `Engine` and TCIR; never published) is
151
+ preserved at the git tag `legacy-2024-11`. It was never functional and is not compatible
152
+ with this one. The PyPI name `tensacode` is a placeholder that installs `tensorcode`.
153
+
154
+ ## License
155
+
156
+ [MIT](https://github.com/TensaCo/tensacode-py/blob/main/LICENSE)
@@ -0,0 +1,54 @@
1
+ [project]
2
+ name = "tensorcode"
3
+ dynamic = ["version"]
4
+ description = "Typed cognitive operations with swappable implementations: rules, learned models, or general models, chosen by policy"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Jacob Valdez", email = "jacob.valdez@tensaco.ai" }]
9
+ requires-python = ">=3.11"
10
+ dependencies = [] # the core has no third-party dependencies
11
+ keywords = ["agents", "cognitive-architecture", "neurosymbolic", "typed-operations", "cascade"]
12
+ classifiers = [
13
+ "Development Status :: 2 - Pre-Alpha",
14
+ "Intended Audience :: Developers",
15
+ "Intended Audience :: Science/Research",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ "Typing :: Typed",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/TensaCo/tensacode-py"
29
+ Source = "https://github.com/TensaCo/tensacode-py"
30
+ Issues = "https://github.com/TensaCo/tensacode-py/issues"
31
+ Design = "https://github.com/TensaCo/tensacode-py/tree/main/docs/revival"
32
+
33
+ [project.optional-dependencies]
34
+ learned-neural = ["torch>=2.1", "transformers>=4.40"] # the trained language tier (src/tensorcode/backends/neural.py)
35
+ learned = ["scikit-learn>=1.5", "numpy>=1.26"]
36
+ local-model = ["torch>=2.4", "transformers>=4.45"]
37
+ dev = ["pytest>=8", "pydantic>=2.5", "numpy>=1.26"]
38
+
39
+ [build-system]
40
+ requires = ["hatchling>=1.27"]
41
+ build-backend = "hatchling.build"
42
+
43
+ [tool.hatch.version]
44
+ path = "src/tensorcode/__init__.py"
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["src/tensorcode"]
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = ["/src/tensorcode", "/README.md", "/LICENSE", "/pyproject.toml"] # tests need examples/ and eval/; they live in the repo
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests", "research"]
54
+ pythonpath = ["src", "."]
@@ -0,0 +1,84 @@
1
+ """TensorCode: typed cognitive operations with swappable implementations.
2
+
3
+ Pre-alpha. The facades exported here (``parse``, ``classify``, ``choose``, ``rank``,
4
+ ``check``, ``verify``, ``propose``, ``invoke``), the outcome values, records and the
5
+ runtime are the public API; submodules not re-exported here may change without notice.
6
+ """
7
+
8
+ __version__ = "0.1.0a1"
9
+
10
+ from .actions import Plan, RunnablePlan, Step, action, invoke, plan_order, run_plan
11
+ from .context import Packed, approx_tokens, dedupe, pack, shingle_similarity
12
+ from .ops import Constraint, Objective, check, choose, classify, parse, propose, rank, verify
13
+ from .outcomes import Receipt, Score, Unknown, Verdict
14
+ from .records import (
15
+ Claim,
16
+ Conflict,
17
+ Evidence,
18
+ Interval,
19
+ Opaque,
20
+ Patch,
21
+ Ref,
22
+ Retract,
23
+ SetField,
24
+ Store,
25
+ Tell,
26
+ TypeRegistry,
27
+ Var,
28
+ )
29
+ from .runtime import Budget, Output, Policy, Profile, Request, Runtime, Trace, Traits, implementation, use
30
+
31
+ from . import actions, records
32
+
33
+ __all__ = [
34
+ "Plan",
35
+ "Step",
36
+ "action",
37
+ "plan_order",
38
+ "RunnablePlan",
39
+ "invoke",
40
+ "run_plan",
41
+ "Packed",
42
+ "approx_tokens",
43
+ "dedupe",
44
+ "pack",
45
+ "shingle_similarity",
46
+ "Constraint",
47
+ "Objective",
48
+ "check",
49
+ "choose",
50
+ "classify",
51
+ "parse",
52
+ "propose",
53
+ "rank",
54
+ "verify",
55
+ "Receipt",
56
+ "Score",
57
+ "Unknown",
58
+ "Verdict",
59
+ "Claim",
60
+ "Conflict",
61
+ "Evidence",
62
+ "Interval",
63
+ "Opaque",
64
+ "Patch",
65
+ "Ref",
66
+ "Retract",
67
+ "SetField",
68
+ "Store",
69
+ "Tell",
70
+ "TypeRegistry",
71
+ "Var",
72
+ "Budget",
73
+ "Output",
74
+ "Policy",
75
+ "Profile",
76
+ "Request",
77
+ "Runtime",
78
+ "Trace",
79
+ "Traits",
80
+ "implementation",
81
+ "use",
82
+ "actions",
83
+ "records",
84
+ ]