cogno-cortex 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.
@@ -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,158 @@
1
+ Metadata-Version: 2.4
2
+ Name: cogno-cortex
3
+ Version: 0.1.0
4
+ Summary: The in-process skills framework for the Cogno stack — author skills as BaseTool + manifest, rank them against NER tags, execute via a provider bus, discover from disk, and bridge to cogno-anima's tool contract via CortexDispatcher. The framework, not the skills; infra-agnostic.
5
+ Author: Vinicius Vale
6
+ Maintainer: Sudoers AI
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/sudoers-ai/cogno-cortex
9
+ Project-URL: Repository, https://github.com/sudoers-ai/cogno-cortex
10
+ Project-URL: Issues, https://github.com/sudoers-ai/cogno-cortex/issues
11
+ Keywords: skills,tools,agents,function-calling,cogno,llm
12
+ Classifier: Development Status :: 3 - Alpha
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 :: Software Development :: Libraries
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pydantic>=2.0
25
+ Requires-Dist: cogno-anima<0.2,>=0.1
26
+ Requires-Dist: cogno-synapse<0.2,>=0.1
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.5; extra == "dev"
32
+ Requires-Dist: mypy>=1.8; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # cogno-cortex
36
+
37
+ **The in-process skills framework for the Cogno stack.**
38
+
39
+ A *skill* is a richer thing than a tool: a `BaseTool` implementation **+** a
40
+ `SkillManifest` (tags, policy flags, instructions) for discovery and ranking.
41
+ cortex is the layer that authors, discovers, ranks and executes skills — and then
42
+ **bridges them to a plain tool** via `CortexDispatcher`, so the EGO / `cogno-soma`
43
+ see ordinary tools and never know what a "skill" is.
44
+
45
+ cortex ships the **framework, not the skills** (like `cogno-persona` ships the
46
+ store, not the personas). It is infra-agnostic: in-process execution only; shell /
47
+ http / remote providers are a host seam.
48
+
49
+ ```
50
+ SKILL.md + BaseTool ─▶ SkillRegistry.rank(NER tags) ─▶ CortexDispatcher
51
+ │ (implements
52
+ ▼ cogno-anima's
53
+ soma.run_turn(dispatcher=…) → EGO
54
+ ToolDispatcher)
55
+ ```
56
+
57
+ ## Install
58
+
59
+ ```bash
60
+ pip install cogno-cortex # pulls cogno-anima + cogno-synapse + pydantic
61
+ ```
62
+
63
+ > The sibling cogno libs are not on PyPI yet — install them from git first
64
+ > (`cogno-homeo`, `cogno-synapse`, `cogno-anima`); see `.github/workflows/ci.yml`.
65
+
66
+ ## Author a skill
67
+
68
+ ```python
69
+ from cogno_cortex import BaseTool, SkillResult, ToolContext
70
+
71
+ class MathTool(BaseTool):
72
+ a: float
73
+ op: str # the Pydantic fields ARE the tool arguments
74
+ b: float
75
+
76
+ @property
77
+ def name(self): return "math"
78
+ @property
79
+ def description(self): return "Basic arithmetic."
80
+
81
+ async def run(self, ctx: ToolContext) -> SkillResult:
82
+ val = {"+": self.a + self.b, "*": self.a * self.b}[self.op]
83
+ return SkillResult(skill_name=self.name, payload=val)
84
+ ```
85
+
86
+ Pair it with a `SKILL.md` (frontmatter: `name`, `description`, `tags`, `priority`,
87
+ `mutating`, `destructive` + operational instructions in the body) in a directory,
88
+ and `discover()` loads it.
89
+
90
+ ## Wire it to the EGO
91
+
92
+ ```python
93
+ from cogno_cortex import (SkillRegistry, SkillBus, LocalProvider,
94
+ CortexDispatcher, discover, register_all)
95
+
96
+ registry, bus = SkillRegistry(), SkillBus()
97
+ bus.register_provider(LocalProvider())
98
+ register_all(discover("./skills"), registry, bus)
99
+
100
+ chosen = registry.rank(ctx.intent.domains + ctx.intent.mandatory_tags) # NER-driven
101
+ dispatcher = CortexDispatcher(registry, bus, names=chosen, backend=llm_backend)
102
+
103
+ # hand it straight to cogno-soma:
104
+ await pipe.run_turn(ctx, cfg, dispatcher=dispatcher)
105
+ ```
106
+
107
+ `CortexDispatcher` implements cogno-anima's `ToolDispatcher` **and**
108
+ `ToolPolicyDispatcher`: `tools_schema()` renders the chosen manifests; `execute()`
109
+ runs the skill and maps `SkillResult → ToolResult`; `is_mutating` / `requires_confirmation`
110
+ read the manifest flags so the EGO's read-only mask + confirmation gate work for
111
+ skills too.
112
+
113
+ ## Skills + MCP + native tools together
114
+
115
+ A persona may draw tools from several sources at once. Each source is a
116
+ `ToolDispatcher`; merge them with `cogno_anima.tools.CompositeDispatcher`:
117
+
118
+ ```python
119
+ from cogno_anima.tools import CompositeDispatcher
120
+ dispatcher = CompositeDispatcher([cortex_dispatcher, mcp_dispatcher, native_dispatcher])
121
+ ```
122
+
123
+ The `ToolDispatcher` contract is the unifier — skill / MCP / native are just
124
+ sources behind it. The persona declares modules **by name**; the host resolves each
125
+ to a source and composes.
126
+
127
+ ## What stays at the host
128
+
129
+ The concrete skills (shell/web/browser/...), shell/http/remote **providers**
130
+ (subprocess/network + security), persona selection, metering (`cogno-meter`), RBAC.
131
+ cortex is the framework; the host plugs providers via the `SkillProvider` Protocol.
132
+
133
+ ## The Cogno ecosystem
134
+
135
+ `cogno-cortex` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
136
+ small, composable, Apache-2.0 libraries that together form a complete
137
+ conversational-agent platform. Each library owns a single concern and stays
138
+ infra-agnostic; a **host** assembles them into a running agent:
139
+
140
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
141
+
142
+ The open-source libraries are the organs; the **host is the body** that joins
143
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
144
+ private product layer, but it holds no special powers: everything it does rides
145
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
146
+ you can assemble a body of your own.
147
+
148
+ ## Development
149
+
150
+ ```bash
151
+ pip install -e ".[dev]"
152
+ pytest tests/unit -q # fast, no network
153
+ pytest tests/integration -q # real EGO over Ollama, auto-skips if absent
154
+ ruff check cogno_cortex tests && mypy cogno_cortex
155
+ python examples/host_min.py # offline demo: discover → rank → bridge → execute
156
+ ```
157
+
158
+ Apache-2.0.
@@ -0,0 +1,124 @@
1
+ # cogno-cortex
2
+
3
+ **The in-process skills framework for the Cogno stack.**
4
+
5
+ A *skill* is a richer thing than a tool: a `BaseTool` implementation **+** a
6
+ `SkillManifest` (tags, policy flags, instructions) for discovery and ranking.
7
+ cortex is the layer that authors, discovers, ranks and executes skills — and then
8
+ **bridges them to a plain tool** via `CortexDispatcher`, so the EGO / `cogno-soma`
9
+ see ordinary tools and never know what a "skill" is.
10
+
11
+ cortex ships the **framework, not the skills** (like `cogno-persona` ships the
12
+ store, not the personas). It is infra-agnostic: in-process execution only; shell /
13
+ http / remote providers are a host seam.
14
+
15
+ ```
16
+ SKILL.md + BaseTool ─▶ SkillRegistry.rank(NER tags) ─▶ CortexDispatcher
17
+ │ (implements
18
+ ▼ cogno-anima's
19
+ soma.run_turn(dispatcher=…) → EGO
20
+ ToolDispatcher)
21
+ ```
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install cogno-cortex # pulls cogno-anima + cogno-synapse + pydantic
27
+ ```
28
+
29
+ > The sibling cogno libs are not on PyPI yet — install them from git first
30
+ > (`cogno-homeo`, `cogno-synapse`, `cogno-anima`); see `.github/workflows/ci.yml`.
31
+
32
+ ## Author a skill
33
+
34
+ ```python
35
+ from cogno_cortex import BaseTool, SkillResult, ToolContext
36
+
37
+ class MathTool(BaseTool):
38
+ a: float
39
+ op: str # the Pydantic fields ARE the tool arguments
40
+ b: float
41
+
42
+ @property
43
+ def name(self): return "math"
44
+ @property
45
+ def description(self): return "Basic arithmetic."
46
+
47
+ async def run(self, ctx: ToolContext) -> SkillResult:
48
+ val = {"+": self.a + self.b, "*": self.a * self.b}[self.op]
49
+ return SkillResult(skill_name=self.name, payload=val)
50
+ ```
51
+
52
+ Pair it with a `SKILL.md` (frontmatter: `name`, `description`, `tags`, `priority`,
53
+ `mutating`, `destructive` + operational instructions in the body) in a directory,
54
+ and `discover()` loads it.
55
+
56
+ ## Wire it to the EGO
57
+
58
+ ```python
59
+ from cogno_cortex import (SkillRegistry, SkillBus, LocalProvider,
60
+ CortexDispatcher, discover, register_all)
61
+
62
+ registry, bus = SkillRegistry(), SkillBus()
63
+ bus.register_provider(LocalProvider())
64
+ register_all(discover("./skills"), registry, bus)
65
+
66
+ chosen = registry.rank(ctx.intent.domains + ctx.intent.mandatory_tags) # NER-driven
67
+ dispatcher = CortexDispatcher(registry, bus, names=chosen, backend=llm_backend)
68
+
69
+ # hand it straight to cogno-soma:
70
+ await pipe.run_turn(ctx, cfg, dispatcher=dispatcher)
71
+ ```
72
+
73
+ `CortexDispatcher` implements cogno-anima's `ToolDispatcher` **and**
74
+ `ToolPolicyDispatcher`: `tools_schema()` renders the chosen manifests; `execute()`
75
+ runs the skill and maps `SkillResult → ToolResult`; `is_mutating` / `requires_confirmation`
76
+ read the manifest flags so the EGO's read-only mask + confirmation gate work for
77
+ skills too.
78
+
79
+ ## Skills + MCP + native tools together
80
+
81
+ A persona may draw tools from several sources at once. Each source is a
82
+ `ToolDispatcher`; merge them with `cogno_anima.tools.CompositeDispatcher`:
83
+
84
+ ```python
85
+ from cogno_anima.tools import CompositeDispatcher
86
+ dispatcher = CompositeDispatcher([cortex_dispatcher, mcp_dispatcher, native_dispatcher])
87
+ ```
88
+
89
+ The `ToolDispatcher` contract is the unifier — skill / MCP / native are just
90
+ sources behind it. The persona declares modules **by name**; the host resolves each
91
+ to a source and composes.
92
+
93
+ ## What stays at the host
94
+
95
+ The concrete skills (shell/web/browser/...), shell/http/remote **providers**
96
+ (subprocess/network + security), persona selection, metering (`cogno-meter`), RBAC.
97
+ cortex is the framework; the host plugs providers via the `SkillProvider` Protocol.
98
+
99
+ ## The Cogno ecosystem
100
+
101
+ `cogno-cortex` is one organ of **[Cogno](https://github.com/sudoers-ai)** — a family of
102
+ small, composable, Apache-2.0 libraries that together form a complete
103
+ conversational-agent platform. Each library owns a single concern and stays
104
+ infra-agnostic; a **host** assembles them into a running agent:
105
+
106
+ ![The Cogno ecosystem](docs/assets/cogno-ecosystem.svg)
107
+
108
+ The open-source libraries are the organs; the **host is the body** that joins
109
+ them. Our reference host — `cogno-host`, with its `cogno-ui` dashboard — is the
110
+ private product layer, but it holds no special powers: everything it does rides
111
+ on the public seams documented in each library's `docs/HOST_INTEGRATION.md`, so
112
+ you can assemble a body of your own.
113
+
114
+ ## Development
115
+
116
+ ```bash
117
+ pip install -e ".[dev]"
118
+ pytest tests/unit -q # fast, no network
119
+ pytest tests/integration -q # real EGO over Ollama, auto-skips if absent
120
+ ruff check cogno_cortex tests && mypy cogno_cortex
121
+ python examples/host_min.py # offline demo: discover → rank → bridge → execute
122
+ ```
123
+
124
+ Apache-2.0.
@@ -0,0 +1,46 @@
1
+ """cogno-cortex — the in-process skills framework for the Cogno stack.
2
+
3
+ Skills are authored as ``BaseTool`` subclasses + ``SkillManifest`` metadata,
4
+ ranked against NER tags by ``SkillRegistry``, executed by ``SkillBus`` (via a
5
+ ``SkillProvider`` — ``LocalProvider`` ships), and discovered from disk by the
6
+ loader. ``CortexDispatcher`` bridges them to cogno-anima's ``ToolDispatcher`` so the
7
+ EGO / cogno-soma see skills as ordinary tools — merge with MCP/native sources via
8
+ ``cogno_anima.tools.CompositeDispatcher``.
9
+ """
10
+
11
+ from cogno_cortex.base import BasePromptTool, BaseTool, ToolContext
12
+ from cogno_cortex.bus import (
13
+ LocalProvider,
14
+ SkillBus,
15
+ SkillNotFoundError,
16
+ SkillProvider,
17
+ )
18
+ from cogno_cortex.dispatcher import CortexDispatcher
19
+ from cogno_cortex.loader import (
20
+ discover,
21
+ load_skill_dir,
22
+ parse_frontmatter,
23
+ register_all,
24
+ )
25
+ from cogno_cortex.registry import SkillRegistry
26
+ from cogno_cortex.types import SkillManifest, SkillResult
27
+
28
+ __all__ = [
29
+ "BaseTool",
30
+ "BasePromptTool",
31
+ "ToolContext",
32
+ "SkillManifest",
33
+ "SkillResult",
34
+ "SkillRegistry",
35
+ "SkillBus",
36
+ "SkillProvider",
37
+ "LocalProvider",
38
+ "SkillNotFoundError",
39
+ "CortexDispatcher",
40
+ "discover",
41
+ "load_skill_dir",
42
+ "register_all",
43
+ "parse_frontmatter",
44
+ ]
45
+
46
+ __version__ = "0.1.0"
@@ -0,0 +1,98 @@
1
+ """Skill authoring contracts: ``BaseTool`` / ``BasePromptTool`` / ``ToolContext``.
2
+
3
+ A skill is a ``BaseTool`` subclass: its Pydantic fields ARE the tool's arguments,
4
+ and ``run(context)`` executes it, returning a :class:`SkillResult`. ``ToolContext``
5
+ carries the injected LLM backend + free-form metadata (the host passes domains,
6
+ constraints, the user query, etc.) — note it carries NO pipeline/DB handle: a skill
7
+ is infra-agnostic, exactly like the rest of the stack.
8
+
9
+ Ported from the parent ``cogno.skills.base``; the ``PipelineContext`` coupling of
10
+ the parent's ``ToolContext`` is replaced by a plain ``metadata`` dict.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from abc import ABC, abstractmethod
16
+ from typing import Any
17
+
18
+ from pydantic import BaseModel, ConfigDict
19
+
20
+ from cogno_cortex.types import SkillResult
21
+
22
+
23
+ class ToolContext(BaseModel):
24
+ """Execution context passed to a skill's ``run()``.
25
+
26
+ Attributes:
27
+ backend: an injected ``cogno_synapse.LLMBackend`` (typed ``Any`` to avoid a
28
+ hard import + circulars); ``None`` for skills that need no LLM.
29
+ trace_id: optional correlation id for observability.
30
+ metadata: extra context from the host (domains, constraints, user query, ...).
31
+ """
32
+
33
+ backend: Any = None
34
+ trace_id: str = ""
35
+ metadata: dict[str, Any] = {}
36
+ model_config = ConfigDict(arbitrary_types_allowed=True)
37
+
38
+
39
+ class BaseTool(BaseModel, ABC):
40
+ """Abstract base for all skills. Subclasses declare arguments as Pydantic fields.
41
+
42
+ Example::
43
+
44
+ class MathTool(BaseTool):
45
+ a: float
46
+ op: str
47
+ b: float
48
+
49
+ @property
50
+ def name(self) -> str: return "math"
51
+
52
+ @property
53
+ def description(self) -> str: return "Basic arithmetic."
54
+
55
+ async def run(self, context: ToolContext) -> SkillResult:
56
+ ...
57
+ """
58
+
59
+ model_config = ConfigDict(arbitrary_types_allowed=True)
60
+
61
+ @property
62
+ @abstractmethod
63
+ def name(self) -> str:
64
+ """Unique skill name (must match the ``SkillManifest.name``)."""
65
+
66
+ @property
67
+ @abstractmethod
68
+ def description(self) -> str:
69
+ """Human-readable description of what this skill does."""
70
+
71
+ @abstractmethod
72
+ async def run(self, context: ToolContext) -> SkillResult:
73
+ """Execute the skill and return a :class:`SkillResult`."""
74
+
75
+ @classmethod
76
+ def args_schema(cls) -> dict[str, Any]:
77
+ """JSON-Schema for this skill's arguments (its Pydantic fields)."""
78
+ return cls.model_json_schema()
79
+
80
+
81
+ class BasePromptTool(BaseTool):
82
+ """Convenience base for LLM-driven skills: ``run`` formats a prompt + calls the backend."""
83
+
84
+ @property
85
+ @abstractmethod
86
+ def prompt_template(self) -> str:
87
+ """A ``str.format`` template with ``{field_name}`` placeholders."""
88
+
89
+ async def run(self, context: ToolContext) -> SkillResult:
90
+ formatted = self.prompt_template.format(**self.model_dump())
91
+ response = await context.backend.generate("You are a specialized tool assistant.", formatted)
92
+ text = response[0] if isinstance(response, tuple) else response
93
+ usage: dict[str, int] = {}
94
+ if isinstance(response, tuple) and len(response) >= 3:
95
+ usage = {"tokens_in": response[1], "tokens_out": response[2]}
96
+ return SkillResult(
97
+ skill_name=self.name, payload=text, status="success",
98
+ evidence=[f"prompt tool '{self.name}' executed"], usage=usage)