cogno-anima 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 (38) hide show
  1. cogno_anima-0.1.0/LICENSE +201 -0
  2. cogno_anima-0.1.0/PKG-INFO +247 -0
  3. cogno_anima-0.1.0/README.md +209 -0
  4. cogno_anima-0.1.0/cogno_anima/__init__.py +110 -0
  5. cogno_anima-0.1.0/cogno_anima/errors.py +70 -0
  6. cogno_anima-0.1.0/cogno_anima/metakeys.py +43 -0
  7. cogno_anima-0.1.0/cogno_anima/prompt_templates/ner/system.txt +285 -0
  8. cogno_anima-0.1.0/cogno_anima/prompt_templates/ner/user.txt +21 -0
  9. cogno_anima-0.1.0/cogno_anima/prompt_templates/noumeno/system.txt +94 -0
  10. cogno_anima-0.1.0/cogno_anima/prompt_templates/noumeno/user.txt +5 -0
  11. cogno_anima-0.1.0/cogno_anima/prompts.py +34 -0
  12. cogno_anima-0.1.0/cogno_anima/routing/__init__.py +19 -0
  13. cogno_anima-0.1.0/cogno_anima/routing/attention.py +68 -0
  14. cogno_anima-0.1.0/cogno_anima/routing/goal.py +264 -0
  15. cogno_anima-0.1.0/cogno_anima/routing/intention.py +122 -0
  16. cogno_anima-0.1.0/cogno_anima/security/detector.py +175 -0
  17. cogno_anima-0.1.0/cogno_anima/security/pii.py +120 -0
  18. cogno_anima-0.1.0/cogno_anima/stages/__init__.py +17 -0
  19. cogno_anima-0.1.0/cogno_anima/stages/base.py +12 -0
  20. cogno_anima-0.1.0/cogno_anima/stages/drift.py +395 -0
  21. cogno_anima-0.1.0/cogno_anima/stages/ego.py +492 -0
  22. cogno_anima-0.1.0/cogno_anima/stages/id.py +297 -0
  23. cogno_anima-0.1.0/cogno_anima/stages/ner.py +601 -0
  24. cogno_anima-0.1.0/cogno_anima/stages/noumeno.py +227 -0
  25. cogno_anima-0.1.0/cogno_anima/stages/superego.py +524 -0
  26. cogno_anima-0.1.0/cogno_anima/tools/__init__.py +4 -0
  27. cogno_anima-0.1.0/cogno_anima/tools/base.py +78 -0
  28. cogno_anima-0.1.0/cogno_anima/tools/composite.py +80 -0
  29. cogno_anima-0.1.0/cogno_anima/types.py +430 -0
  30. cogno_anima-0.1.0/cogno_anima/utils.py +157 -0
  31. cogno_anima-0.1.0/cogno_anima/vocab.py +77 -0
  32. cogno_anima-0.1.0/cogno_anima.egg-info/PKG-INFO +247 -0
  33. cogno_anima-0.1.0/cogno_anima.egg-info/SOURCES.txt +36 -0
  34. cogno_anima-0.1.0/cogno_anima.egg-info/dependency_links.txt +1 -0
  35. cogno_anima-0.1.0/cogno_anima.egg-info/requires.txt +14 -0
  36. cogno_anima-0.1.0/cogno_anima.egg-info/top_level.txt +1 -0
  37. cogno_anima-0.1.0/pyproject.toml +85 -0
  38. cogno_anima-0.1.0/setup.cfg +4 -0
@@ -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
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding 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 Sudoers AI
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.
@@ -0,0 +1,247 @@
1
+ Metadata-Version: 2.4
2
+ Name: cogno-anima
3
+ Version: 0.1.0
4
+ Summary: Infrastructure-agnostic cognitive pipeline core (NOUMENO/NER/ID/EGO/SUPEREGO + Drift)
5
+ Author: Vinicius Vale
6
+ Maintainer: Sudoers AI
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/sudoers-ai/cogno-anima
9
+ Project-URL: Repository, https://github.com/sudoers-ai/cogno-anima
10
+ Project-URL: Issues, https://github.com/sudoers-ai/cogno-anima/issues
11
+ Keywords: llm,nlp,cognitive-architecture,agents,function-calling,pii,ollama
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pydantic>=2.0
26
+ Requires-Dist: langdetect>=1.0.9
27
+ Requires-Dist: cogno-synapse<0.2,>=0.1
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
32
+ Requires-Dist: hypothesis>=6.0; extra == "dev"
33
+ Requires-Dist: ruff>=0.5; extra == "dev"
34
+ Requires-Dist: mypy>=1.8; extra == "dev"
35
+ Provides-Extra: llm
36
+ Requires-Dist: cogno-synapse[llm]<0.2,>=0.1; extra == "llm"
37
+ Dynamic: license-file
38
+
39
+ # 🧠 cogno-anima
40
+
41
+ **The infrastructure-agnostic cognitive pipeline at the heart of [Cogno](https://github.com/sudoers-ai).**
42
+
43
+ `cogno-anima` is a modular, dependency-light library that turns raw user input
44
+ into a routed, grounded, persona-voiced response — decoupled from any database,
45
+ message bus, or proprietary infra. It is the brain; the host — your application —
46
+ is the body that carries it.
47
+
48
+ ![SECRETARY demo — the full pipeline booking an appointment on a free local model](docs/assets/secretary-demo.gif)
49
+
50
+ *The whole stack, live on a free 8B local model: NOUMENO rewrites Portuguese to
51
+ canonical English, the ID routes, the EGO calls real scheduling tools (and
52
+ self-corrects around a weekend), the judge approves, the voice replies in the
53
+ persona. Run it yourself in ~15 minutes — see
54
+ [Try it](#try-it--a-complete-agent-in-15-minutes) · quality numbers in
55
+ [BENCHMARKS.md](BENCHMARKS.md).*
56
+
57
+ ```
58
+ NOUMENO → NER → ID → EGO → SUPEREGO (+ Drift, woven through)
59
+ │ │ │ │ │
60
+ rewrite intent route execute voice
61
+ to EN + PII + goal (tools) + judge
62
+ ```
63
+
64
+ - **NOUMENO** — perception: slang/normalization, language resolution, rewrite to canonical English, epistemological drift.
65
+ - **NER** — semantic analysis: intent, sentiment, entities, PII (detected deterministically, never trusted from the LLM), domains — all coerced to a closed vocabulary.
66
+ - **ID** — strategic router & continuity (heuristic, no LLM): goal lifecycle, BDI intentions, attention, safety gate, drift.
67
+ - **EGO** — executor: runs an agent loop and dispatches tools (native function calling *or* a `<TOOL_CALL>` text fallback). It gathers data; it does **not** write the reply.
68
+ - **SUPEREGO** — locutor: scope guard + judge (goal↔execution) + **writes** the final response in the persona's voice, grounded in the EGO's data.
69
+ - **Drift** — pure, no I/O: epistemological → ontological → situational → execution → synthesis → cumulative, emitting a `drift_action` signal.
70
+
71
+ ## Philosophy: the core signals, the host decides
72
+
73
+ `cogno-anima` deliberately ships **no business rules and no infrastructure**. It is
74
+ built on a few hard contracts:
75
+
76
+ - **Infra-agnostic** — no DB, no MCP, no queue. Tool execution is delegated to a host-injected `ToolDispatcher` ("EGO = brain, dispatcher = hands"). Persistence, transactions, rollback/outbox and atomicity are **host** concerns.
77
+ - **Never trust the LLM** — PII risk, routing, vocabularies and drift are computed deterministically; the LLM's self-assessment is ignored.
78
+ - **Signals, not exceptions** — the core emits `drift_action`, `blocked`, `interrupted`, `needs_handoff`, `stop_reason`; the host turns those into actions (retry, escalate, hand off to a human).
79
+ - **Stateless across turns** — all cross-turn state rides in `ctx.metadata` (e.g. `id_state`), a serializable dict the host persists — safe for multi-worker setups.
80
+ - **Errors propagate** — backends raise on transport/auth failure instead of degrading silently; a `FallbackBackend` is how you opt into failover.
81
+
82
+ What stays in the **host**: persona/MCP binding, RBAC, model ladders, the
83
+ retry/correction *loop*, session splitting, the real human handoff, billing,
84
+ semantic cache, and persistence. See **[docs/HOST_INTEGRATION.md](docs/HOST_INTEGRATION.md)**
85
+ for how to wire the core into a host, `CLAUDE.md` for the full boundary map, and
86
+ `cognobench/pipeline.py` (`ReferencePipeline`) for a reference orchestrator.
87
+
88
+ ## Try it — a complete agent in 15 minutes
89
+
90
+ The fastest way to *feel* the pipeline is the SECRETARY demo in
91
+ [`cogno-praxis`](https://github.com/sudoers-ai/cogno-praxis): the full
92
+ cognitive loop over local Ollama, with a real scheduling vertical served as an
93
+ MCP subprocess — free, offline, any language in:
94
+
95
+ ```bash
96
+ ollama pull qwen3:8b && ollama pull nomic-embed-text # the download IS most of the 15 min
97
+
98
+ pip install "git+https://github.com/sudoers-ai/cogno-homeo" \
99
+ "git+https://github.com/sudoers-ai/cogno-synapse" \
100
+ "git+https://github.com/sudoers-ai/cogno-anima" \
101
+ "git+https://github.com/sudoers-ai/cogno-soma" \
102
+ "cogno-mcp[mcp] @ git+https://github.com/sudoers-ai/cogno-mcp"
103
+
104
+ git clone https://github.com/sudoers-ai/cogno-praxis && cd cogno-praxis
105
+ pip install -e .
106
+ python examples/secretary_demo.py --trace # --trace shows each cognitive stage live
107
+ ```
108
+
109
+ (PyPI packages are coming; the git chain above is the interim install.)
110
+
111
+ ## Install
112
+
113
+ ```bash
114
+ pip install -e . # core (pydantic, langdetect, httpx)
115
+ pip install -e ".[dev]" # + test/lint/type-check tooling
116
+
117
+ # Optional cloud backends (SDKs are lazy-imported — install only what you use):
118
+ pip install "cogno-anima[openai]" # also: anthropic | groq | gemini | bedrock | llm (all)
119
+ ```
120
+
121
+ Local inference uses [Ollama](https://ollama.com) (`mistral:latest` for the
122
+ cognitive stages, `nomic-embed-text:latest` for embeddings) by default.
123
+
124
+ ## Quickstart (perception + routing)
125
+
126
+ The first three stages need only an `LLMBackend` + an `Embedder` — no dispatcher,
127
+ no DB:
128
+
129
+ ```python
130
+ import asyncio
131
+ from cogno_anima.types import PipelineContext
132
+ from cogno_synapse import OllamaBackend, OllamaEmbedder, CachingEmbedder
133
+ from cogno_anima.stages.noumeno import Noumeno
134
+ from cogno_anima.stages.ner import IntentAnalyzer
135
+ from cogno_anima.stages.id import IDStage
136
+
137
+ async def main():
138
+ llm = OllamaBackend(model="mistral:latest", temperature=0.0, format="json")
139
+ embedder = CachingEmbedder(OllamaEmbedder(model="nomic-embed-text"))
140
+
141
+ ctx = PipelineContext(user_input="quanto tá o meu saldo?")
142
+ ctx = await Noumeno(embedder).process(ctx, llm)
143
+ ctx = await IntentAnalyzer().process(ctx, llm)
144
+ ctx = await IDStage().process(ctx, embedder)
145
+
146
+ print(ctx.noumeno.rewritten) # "what is my balance?"
147
+ print(ctx.intent.intent_class) # INFORMATION_REQUEST
148
+ print(ctx.id_result.triad_route) # EGO (tool gateway)
149
+ print(ctx.total_tokens) # LLM + embedding cost
150
+
151
+ asyncio.run(main())
152
+ ```
153
+
154
+ To run the **full** pipeline (EGO tool dispatch + SUPEREGO voicing + the
155
+ correction loop), you provide a `ToolDispatcher`, persona prompts, and the
156
+ orchestration glue. A complete, runnable reference lives in
157
+ `cognobench/pipeline.py: ReferencePipeline`.
158
+
159
+ ## LLM & embedder backends
160
+
161
+ Stages depend only on three runtime-checkable `Protocol`s defined in the sibling
162
+ [`cogno-synapse`](https://github.com/sudoers-ai/cogno-synapse) lib
163
+ (`cogno_synapse.base`): `LLMBackend`, the optional `ToolCallingBackend` (native
164
+ function calling), and `Embedder`. Anything matching the shape works. (`cogno-anima`
165
+ re-exports them, so `from cogno_anima import LLMBackend` keeps working.)
166
+
167
+ - **Local**: `OllamaBackend`, `OllamaEmbedder` (+ `CachingEmbedder` adds a bounded LRU + token accounting to any embedder).
168
+ - **Cloud**: OpenAI, Anthropic, Groq, Gemini, Bedrock — each implements native function calling.
169
+ - **OpenAI-compatible** (DeepSeek, Moonshot/Kimi, xAI/Grok, OpenRouter, Together, Fireworks): reuse `OpenAIBackend` via its `base_url`, selected by `create_backend("deepseek:deepseek-chat")`.
170
+ - **Failover**: `FallbackBackend([...])` tries each in order; first success wins.
171
+
172
+ ```python
173
+ from cogno_synapse import create_backend
174
+ backend = create_backend("openai:gpt-4o-mini") # or "deepseek:deepseek-chat", "qwen3:8b", …
175
+ ```
176
+
177
+ ## CognoBench
178
+
179
+ A self-contained, dependency-light cognitive benchmark (`cognobench/`), kept
180
+ decoupled from the library, scoring each stage end-to-end against a real model:
181
+
182
+ ```bash
183
+ python3 cognobench.py # all dimensions vs local Ollama
184
+ python3 cognobench.py --only ner --limit 3 # one dimension, few cases
185
+ python3 cognobench.py --only conversations # broad multi-turn e2e simulation
186
+ python3 cognobench.py --stub --limit 3 # fast plumbing smoke (no model)
187
+ ```
188
+
189
+ Dimensions: `noumeno · ner · id · ego · superego · drift · conversations`. Hard
190
+ invariants are enforced; model-dependent "soft" checks are recalibratable with
191
+ `--calibrate`. The benchmark is **not** shipped in the wheel.
192
+
193
+ **Consolidated scoreboard — quality per cognitive function × model, and where
194
+ small models break: [BENCHMARKS.md](BENCHMARKS.md).**
195
+
196
+ ## The Cogno ecosystem
197
+
198
+ `cogno-anima` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
199
+ small, composable, Apache-2.0 libraries that together form a complete
200
+ conversational-agent platform. Each library owns a single concern and stays
201
+ infra-agnostic; a **host** assembles them into a running agent:
202
+
203
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
204
+
205
+ The open-source libraries are the organs; the **host is the body** that joins
206
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
207
+ private product layer, but it holds no special powers: everything it does rides
208
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
209
+ you can assemble a body of your own.
210
+
211
+ ## Testing
212
+
213
+ ```bash
214
+ python3 -m pytest # everything
215
+ python3 -m pytest tests/unit # fast, no network (stubs)
216
+ python3 -m pytest tests/integration # real Ollama; auto-skips if unavailable
217
+ ```
218
+
219
+ Unit tests run on a coverage gate (`--cov-fail-under=85`) and use the
220
+ `StubBackend`/`StubEmbedder` doubles in `tests/conftest.py`. Integration tests
221
+ use real models at `temperature=0.0` for determinism.
222
+
223
+ ## Inspiration
224
+
225
+ Cogno models a conversational agent on a coarse map of **human perception and the
226
+ psyche** rather than on a flat prompt→response call. The stage names are the map:
227
+
228
+ - **NOUMENO** — after Kant's *noumenon*: the raw thing-in-itself is normalized into
229
+ a *perceived* phenomenon (canonical English) before the mind reasons over it.
230
+ - **ID · EGO · SUPEREGO** — Freud's structural model of the psyche: the **ID** as the
231
+ strategic drive/router, the **EGO** as the executor mediating with the outside world
232
+ (tools), the **SUPEREGO** as the internalized judge and voice of limits.
233
+ - **Aristotelian** intent tags — the categories/causal analysis borrowed from Aristotle.
234
+ - **Drift** — an epistemological check on how far perception has strayed from the input.
235
+
236
+ It is an engineering metaphor, not a claim of psychological fidelity — but the analogy
237
+ is load-bearing: it is *why* perception, drive, execution and conscience are separate,
238
+ deterministically-gated stages instead of one prompt.
239
+
240
+ ## Credits
241
+
242
+ Created by **Vinicius Vale** — [Sudoers](https://github.com/sudoers-ai).
243
+ Contributions welcome under the Apache-2.0 license below.
244
+
245
+ ## License
246
+
247
+ Licensed under the [Apache License 2.0](LICENSE).
@@ -0,0 +1,209 @@
1
+ # 🧠 cogno-anima
2
+
3
+ **The infrastructure-agnostic cognitive pipeline at the heart of [Cogno](https://github.com/sudoers-ai).**
4
+
5
+ `cogno-anima` is a modular, dependency-light library that turns raw user input
6
+ into a routed, grounded, persona-voiced response — decoupled from any database,
7
+ message bus, or proprietary infra. It is the brain; the host — your application —
8
+ is the body that carries it.
9
+
10
+ ![SECRETARY demo — the full pipeline booking an appointment on a free local model](docs/assets/secretary-demo.gif)
11
+
12
+ *The whole stack, live on a free 8B local model: NOUMENO rewrites Portuguese to
13
+ canonical English, the ID routes, the EGO calls real scheduling tools (and
14
+ self-corrects around a weekend), the judge approves, the voice replies in the
15
+ persona. Run it yourself in ~15 minutes — see
16
+ [Try it](#try-it--a-complete-agent-in-15-minutes) · quality numbers in
17
+ [BENCHMARKS.md](BENCHMARKS.md).*
18
+
19
+ ```
20
+ NOUMENO → NER → ID → EGO → SUPEREGO (+ Drift, woven through)
21
+ │ │ │ │ │
22
+ rewrite intent route execute voice
23
+ to EN + PII + goal (tools) + judge
24
+ ```
25
+
26
+ - **NOUMENO** — perception: slang/normalization, language resolution, rewrite to canonical English, epistemological drift.
27
+ - **NER** — semantic analysis: intent, sentiment, entities, PII (detected deterministically, never trusted from the LLM), domains — all coerced to a closed vocabulary.
28
+ - **ID** — strategic router & continuity (heuristic, no LLM): goal lifecycle, BDI intentions, attention, safety gate, drift.
29
+ - **EGO** — executor: runs an agent loop and dispatches tools (native function calling *or* a `<TOOL_CALL>` text fallback). It gathers data; it does **not** write the reply.
30
+ - **SUPEREGO** — locutor: scope guard + judge (goal↔execution) + **writes** the final response in the persona's voice, grounded in the EGO's data.
31
+ - **Drift** — pure, no I/O: epistemological → ontological → situational → execution → synthesis → cumulative, emitting a `drift_action` signal.
32
+
33
+ ## Philosophy: the core signals, the host decides
34
+
35
+ `cogno-anima` deliberately ships **no business rules and no infrastructure**. It is
36
+ built on a few hard contracts:
37
+
38
+ - **Infra-agnostic** — no DB, no MCP, no queue. Tool execution is delegated to a host-injected `ToolDispatcher` ("EGO = brain, dispatcher = hands"). Persistence, transactions, rollback/outbox and atomicity are **host** concerns.
39
+ - **Never trust the LLM** — PII risk, routing, vocabularies and drift are computed deterministically; the LLM's self-assessment is ignored.
40
+ - **Signals, not exceptions** — the core emits `drift_action`, `blocked`, `interrupted`, `needs_handoff`, `stop_reason`; the host turns those into actions (retry, escalate, hand off to a human).
41
+ - **Stateless across turns** — all cross-turn state rides in `ctx.metadata` (e.g. `id_state`), a serializable dict the host persists — safe for multi-worker setups.
42
+ - **Errors propagate** — backends raise on transport/auth failure instead of degrading silently; a `FallbackBackend` is how you opt into failover.
43
+
44
+ What stays in the **host**: persona/MCP binding, RBAC, model ladders, the
45
+ retry/correction *loop*, session splitting, the real human handoff, billing,
46
+ semantic cache, and persistence. See **[docs/HOST_INTEGRATION.md](docs/HOST_INTEGRATION.md)**
47
+ for how to wire the core into a host, `CLAUDE.md` for the full boundary map, and
48
+ `cognobench/pipeline.py` (`ReferencePipeline`) for a reference orchestrator.
49
+
50
+ ## Try it — a complete agent in 15 minutes
51
+
52
+ The fastest way to *feel* the pipeline is the SECRETARY demo in
53
+ [`cogno-praxis`](https://github.com/sudoers-ai/cogno-praxis): the full
54
+ cognitive loop over local Ollama, with a real scheduling vertical served as an
55
+ MCP subprocess — free, offline, any language in:
56
+
57
+ ```bash
58
+ ollama pull qwen3:8b && ollama pull nomic-embed-text # the download IS most of the 15 min
59
+
60
+ pip install "git+https://github.com/sudoers-ai/cogno-homeo" \
61
+ "git+https://github.com/sudoers-ai/cogno-synapse" \
62
+ "git+https://github.com/sudoers-ai/cogno-anima" \
63
+ "git+https://github.com/sudoers-ai/cogno-soma" \
64
+ "cogno-mcp[mcp] @ git+https://github.com/sudoers-ai/cogno-mcp"
65
+
66
+ git clone https://github.com/sudoers-ai/cogno-praxis && cd cogno-praxis
67
+ pip install -e .
68
+ python examples/secretary_demo.py --trace # --trace shows each cognitive stage live
69
+ ```
70
+
71
+ (PyPI packages are coming; the git chain above is the interim install.)
72
+
73
+ ## Install
74
+
75
+ ```bash
76
+ pip install -e . # core (pydantic, langdetect, httpx)
77
+ pip install -e ".[dev]" # + test/lint/type-check tooling
78
+
79
+ # Optional cloud backends (SDKs are lazy-imported — install only what you use):
80
+ pip install "cogno-anima[openai]" # also: anthropic | groq | gemini | bedrock | llm (all)
81
+ ```
82
+
83
+ Local inference uses [Ollama](https://ollama.com) (`mistral:latest` for the
84
+ cognitive stages, `nomic-embed-text:latest` for embeddings) by default.
85
+
86
+ ## Quickstart (perception + routing)
87
+
88
+ The first three stages need only an `LLMBackend` + an `Embedder` — no dispatcher,
89
+ no DB:
90
+
91
+ ```python
92
+ import asyncio
93
+ from cogno_anima.types import PipelineContext
94
+ from cogno_synapse import OllamaBackend, OllamaEmbedder, CachingEmbedder
95
+ from cogno_anima.stages.noumeno import Noumeno
96
+ from cogno_anima.stages.ner import IntentAnalyzer
97
+ from cogno_anima.stages.id import IDStage
98
+
99
+ async def main():
100
+ llm = OllamaBackend(model="mistral:latest", temperature=0.0, format="json")
101
+ embedder = CachingEmbedder(OllamaEmbedder(model="nomic-embed-text"))
102
+
103
+ ctx = PipelineContext(user_input="quanto tá o meu saldo?")
104
+ ctx = await Noumeno(embedder).process(ctx, llm)
105
+ ctx = await IntentAnalyzer().process(ctx, llm)
106
+ ctx = await IDStage().process(ctx, embedder)
107
+
108
+ print(ctx.noumeno.rewritten) # "what is my balance?"
109
+ print(ctx.intent.intent_class) # INFORMATION_REQUEST
110
+ print(ctx.id_result.triad_route) # EGO (tool gateway)
111
+ print(ctx.total_tokens) # LLM + embedding cost
112
+
113
+ asyncio.run(main())
114
+ ```
115
+
116
+ To run the **full** pipeline (EGO tool dispatch + SUPEREGO voicing + the
117
+ correction loop), you provide a `ToolDispatcher`, persona prompts, and the
118
+ orchestration glue. A complete, runnable reference lives in
119
+ `cognobench/pipeline.py: ReferencePipeline`.
120
+
121
+ ## LLM & embedder backends
122
+
123
+ Stages depend only on three runtime-checkable `Protocol`s defined in the sibling
124
+ [`cogno-synapse`](https://github.com/sudoers-ai/cogno-synapse) lib
125
+ (`cogno_synapse.base`): `LLMBackend`, the optional `ToolCallingBackend` (native
126
+ function calling), and `Embedder`. Anything matching the shape works. (`cogno-anima`
127
+ re-exports them, so `from cogno_anima import LLMBackend` keeps working.)
128
+
129
+ - **Local**: `OllamaBackend`, `OllamaEmbedder` (+ `CachingEmbedder` adds a bounded LRU + token accounting to any embedder).
130
+ - **Cloud**: OpenAI, Anthropic, Groq, Gemini, Bedrock — each implements native function calling.
131
+ - **OpenAI-compatible** (DeepSeek, Moonshot/Kimi, xAI/Grok, OpenRouter, Together, Fireworks): reuse `OpenAIBackend` via its `base_url`, selected by `create_backend("deepseek:deepseek-chat")`.
132
+ - **Failover**: `FallbackBackend([...])` tries each in order; first success wins.
133
+
134
+ ```python
135
+ from cogno_synapse import create_backend
136
+ backend = create_backend("openai:gpt-4o-mini") # or "deepseek:deepseek-chat", "qwen3:8b", …
137
+ ```
138
+
139
+ ## CognoBench
140
+
141
+ A self-contained, dependency-light cognitive benchmark (`cognobench/`), kept
142
+ decoupled from the library, scoring each stage end-to-end against a real model:
143
+
144
+ ```bash
145
+ python3 cognobench.py # all dimensions vs local Ollama
146
+ python3 cognobench.py --only ner --limit 3 # one dimension, few cases
147
+ python3 cognobench.py --only conversations # broad multi-turn e2e simulation
148
+ python3 cognobench.py --stub --limit 3 # fast plumbing smoke (no model)
149
+ ```
150
+
151
+ Dimensions: `noumeno · ner · id · ego · superego · drift · conversations`. Hard
152
+ invariants are enforced; model-dependent "soft" checks are recalibratable with
153
+ `--calibrate`. The benchmark is **not** shipped in the wheel.
154
+
155
+ **Consolidated scoreboard — quality per cognitive function × model, and where
156
+ small models break: [BENCHMARKS.md](BENCHMARKS.md).**
157
+
158
+ ## The Cogno ecosystem
159
+
160
+ `cogno-anima` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
161
+ small, composable, Apache-2.0 libraries that together form a complete
162
+ conversational-agent platform. Each library owns a single concern and stays
163
+ infra-agnostic; a **host** assembles them into a running agent:
164
+
165
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
166
+
167
+ The open-source libraries are the organs; the **host is the body** that joins
168
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
169
+ private product layer, but it holds no special powers: everything it does rides
170
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
171
+ you can assemble a body of your own.
172
+
173
+ ## Testing
174
+
175
+ ```bash
176
+ python3 -m pytest # everything
177
+ python3 -m pytest tests/unit # fast, no network (stubs)
178
+ python3 -m pytest tests/integration # real Ollama; auto-skips if unavailable
179
+ ```
180
+
181
+ Unit tests run on a coverage gate (`--cov-fail-under=85`) and use the
182
+ `StubBackend`/`StubEmbedder` doubles in `tests/conftest.py`. Integration tests
183
+ use real models at `temperature=0.0` for determinism.
184
+
185
+ ## Inspiration
186
+
187
+ Cogno models a conversational agent on a coarse map of **human perception and the
188
+ psyche** rather than on a flat prompt→response call. The stage names are the map:
189
+
190
+ - **NOUMENO** — after Kant's *noumenon*: the raw thing-in-itself is normalized into
191
+ a *perceived* phenomenon (canonical English) before the mind reasons over it.
192
+ - **ID · EGO · SUPEREGO** — Freud's structural model of the psyche: the **ID** as the
193
+ strategic drive/router, the **EGO** as the executor mediating with the outside world
194
+ (tools), the **SUPEREGO** as the internalized judge and voice of limits.
195
+ - **Aristotelian** intent tags — the categories/causal analysis borrowed from Aristotle.
196
+ - **Drift** — an epistemological check on how far perception has strayed from the input.
197
+
198
+ It is an engineering metaphor, not a claim of psychological fidelity — but the analogy
199
+ is load-bearing: it is *why* perception, drive, execution and conscience are separate,
200
+ deterministically-gated stages instead of one prompt.
201
+
202
+ ## Credits
203
+
204
+ Created by **Vinicius Vale** — [Sudoers](https://github.com/sudoers-ai).
205
+ Contributions welcome under the Apache-2.0 license below.
206
+
207
+ ## License
208
+
209
+ Licensed under the [Apache License 2.0](LICENSE).