personakit 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.
- personakit-0.1.0/.gitignore +31 -0
- personakit-0.1.0/CHANGELOG.md +26 -0
- personakit-0.1.0/LICENSE +21 -0
- personakit-0.1.0/PKG-INFO +281 -0
- personakit-0.1.0/README.md +233 -0
- personakit-0.1.0/pyproject.toml +97 -0
- personakit-0.1.0/src/personakit/__init__.py +76 -0
- personakit-0.1.0/src/personakit/agent.py +224 -0
- personakit-0.1.0/src/personakit/errors.py +33 -0
- personakit-0.1.0/src/personakit/examples/__init__.py +12 -0
- personakit-0.1.0/src/personakit/examples/contract_reviewer.py +111 -0
- personakit-0.1.0/src/personakit/examples/falls_nurse.py +170 -0
- personakit-0.1.0/src/personakit/examples/math_tutor.py +35 -0
- personakit-0.1.0/src/personakit/loaders.py +62 -0
- personakit-0.1.0/src/personakit/matching.py +90 -0
- personakit-0.1.0/src/personakit/prompt_builder.py +267 -0
- personakit-0.1.0/src/personakit/providers/__init__.py +33 -0
- personakit-0.1.0/src/personakit/providers/anthropic.py +110 -0
- personakit-0.1.0/src/personakit/providers/base.py +55 -0
- personakit-0.1.0/src/personakit/providers/mock.py +66 -0
- personakit-0.1.0/src/personakit/providers/openai.py +118 -0
- personakit-0.1.0/src/personakit/py.typed +0 -0
- personakit-0.1.0/src/personakit/registry.py +69 -0
- personakit-0.1.0/src/personakit/result.py +116 -0
- personakit-0.1.0/src/personakit/specialist.py +329 -0
- personakit-0.1.0/src/personakit/testing.py +35 -0
- personakit-0.1.0/src/personakit/tools.py +170 -0
- personakit-0.1.0/tests/__init__.py +0 -0
- personakit-0.1.0/tests/test_agent.py +108 -0
- personakit-0.1.0/tests/test_loaders.py +48 -0
- personakit-0.1.0/tests/test_matching.py +47 -0
- personakit-0.1.0/tests/test_prompt_builder.py +46 -0
- personakit-0.1.0/tests/test_specialist.py +82 -0
- personakit-0.1.0/tests/test_tools.py +61 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
build/
|
|
2
|
+
dist/
|
|
3
|
+
*.egg-info/
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.pyc
|
|
6
|
+
*.pyo
|
|
7
|
+
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
env/
|
|
11
|
+
.python-version
|
|
12
|
+
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
.coverage.*
|
|
16
|
+
htmlcov/
|
|
17
|
+
coverage.xml
|
|
18
|
+
|
|
19
|
+
.mypy_cache/
|
|
20
|
+
.ruff_cache/
|
|
21
|
+
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
*.swp
|
|
25
|
+
|
|
26
|
+
.DS_Store
|
|
27
|
+
Thumbs.db
|
|
28
|
+
|
|
29
|
+
.env
|
|
30
|
+
.pypirc
|
|
31
|
+
*.pem
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
|
|
6
|
+
project follows [Semantic Versioning](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] — 2026-04-24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Specialist` — declarative agent definition with persona, frameworks, probes,
|
|
14
|
+
red flags, recommendation themes, priorities, taxonomies, and focus areas.
|
|
15
|
+
- `Probe`, `Framework`, `RedFlag`, `Theme`, `Severity`, `FocusAreas` primitives.
|
|
16
|
+
- `Agent` runtime with async `analyze()` and `chat()` entry points.
|
|
17
|
+
- Red flag matching in two phases: deterministic regex/keyword pre-match and
|
|
18
|
+
LLM semantic post-match. Results are merged and de-duplicated.
|
|
19
|
+
- `PromptBuilder` — deterministic translation from `Specialist` to an XML-style
|
|
20
|
+
system prompt plus an auto-derived JSON output schema.
|
|
21
|
+
- Provider adapters: `OpenAIProvider`, `AnthropicProvider`, `MockProvider`.
|
|
22
|
+
- `SpecialistRegistry` for multi-specialist applications.
|
|
23
|
+
- YAML / JSON / dict loaders — authorable by non-coders.
|
|
24
|
+
- Opt-in `@tool` decorator and `ToolBox` — zero coupling when unused.
|
|
25
|
+
- Testing helpers: `MockProvider`, structural assertions.
|
|
26
|
+
- Bundled examples: falls prevention nurse, contract reviewer, math tutor.
|
personakit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Majidul Islam
|
|
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,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: personakit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Declarative specialist agents for LLMs — persona, frameworks, probes, red flags, and citations as first-class concepts.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Majidul17068/personakit
|
|
6
|
+
Project-URL: Repository, https://github.com/Majidul17068/personakit
|
|
7
|
+
Project-URL: Issues, https://github.com/Majidul17068/personakit/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Majidul17068/personakit/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Majidul Islam <contact.majidul.islam@gmail.com>
|
|
10
|
+
Maintainer-email: Majidul Islam <contact.majidul.islam@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agent,ai,anthropic,llm,openai,persona,prompt-engineering,specialist
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: httpx>=0.25
|
|
28
|
+
Requires-Dist: pydantic>=2.5
|
|
29
|
+
Provides-Extra: all
|
|
30
|
+
Requires-Dist: anthropic>=0.20; extra == 'all'
|
|
31
|
+
Requires-Dist: openai>=1.0; extra == 'all'
|
|
32
|
+
Requires-Dist: pyyaml>=6.0; extra == 'all'
|
|
33
|
+
Provides-Extra: anthropic
|
|
34
|
+
Requires-Dist: anthropic>=0.20; extra == 'anthropic'
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest>=7.4; extra == 'dev'
|
|
40
|
+
Requires-Dist: pyyaml>=6.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: ruff>=0.3; extra == 'dev'
|
|
42
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
43
|
+
Provides-Extra: openai
|
|
44
|
+
Requires-Dist: openai>=1.0; extra == 'openai'
|
|
45
|
+
Provides-Extra: yaml
|
|
46
|
+
Requires-Dist: pyyaml>=6.0; extra == 'yaml'
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# personakit
|
|
50
|
+
|
|
51
|
+
**Declarative specialist agents for LLMs.** Encode a role's expertise —
|
|
52
|
+
persona, frameworks, probes, red flags, recommendation themes — as data.
|
|
53
|
+
Get a production agent that produces structured, cited, safety-aware output.
|
|
54
|
+
|
|
55
|
+
> Created by **[Majidul Islam](https://github.com/Majidul17068)**.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install personakit[openai]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Why
|
|
64
|
+
|
|
65
|
+
LangChain is for wiring LLM calls. CrewAI is for orchestrating agent teams.
|
|
66
|
+
LangGraph is for branching control flow.
|
|
67
|
+
|
|
68
|
+
**personakit is for encoding specialist expertise declaratively.** A nurse, a
|
|
69
|
+
lawyer, an analyst, or a PM can author a specialist in Python or YAML and hand
|
|
70
|
+
it to engineers. No prompt engineering, no chain wiring.
|
|
71
|
+
|
|
72
|
+
The distinctive pieces:
|
|
73
|
+
|
|
74
|
+
| Concept | What it gives you |
|
|
75
|
+
|---|---|
|
|
76
|
+
| **Specialist** | A frozen dataclass — the entire agent definition |
|
|
77
|
+
| **Framework** | Body of knowledge + citation key, enforced in output |
|
|
78
|
+
| **Probe** | Diagnostic question; becomes a field in the structured response |
|
|
79
|
+
| **RedFlag** | Trigger → action → citation; matched deterministically AND semantically |
|
|
80
|
+
| **Theme** | User-selectable recommendation category |
|
|
81
|
+
| **Priority** | Always-on checks reported as met / unmet / unknown |
|
|
82
|
+
| **Tool (optional)** | `@tool` decorator; opt-in for external memory or API calls |
|
|
83
|
+
|
|
84
|
+
Core has just two runtime deps: **pydantic** and **httpx**.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Quickstart
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import asyncio
|
|
92
|
+
from personakit import Agent, Specialist, Framework, Probe, RedFlag, Severity, Theme
|
|
93
|
+
|
|
94
|
+
specialist = Specialist(
|
|
95
|
+
name="contract_reviewer",
|
|
96
|
+
display_name="M&A Contract Reviewer",
|
|
97
|
+
persona="You are a senior M&A attorney. Flag risks. Propose redlines.",
|
|
98
|
+
frameworks=[Framework(name="UCC"), Framework(name="English contract law")],
|
|
99
|
+
probes=[
|
|
100
|
+
Probe(question="What's the governing jurisdiction?"),
|
|
101
|
+
Probe(question="Is there an unlimited liability clause?",
|
|
102
|
+
value_type="boolean", weight="high"),
|
|
103
|
+
],
|
|
104
|
+
red_flags=[
|
|
105
|
+
RedFlag(
|
|
106
|
+
trigger="Unlimited liability",
|
|
107
|
+
severity=Severity.CRITICAL,
|
|
108
|
+
action="Negotiate a cap — 12 months' fees is market standard.",
|
|
109
|
+
patterns=[r"unlimited liability", r"uncapped"],
|
|
110
|
+
),
|
|
111
|
+
],
|
|
112
|
+
themes=[Theme(name="Liability & indemnities"), Theme(name="IP & licensing")],
|
|
113
|
+
constraints=["Never give conclusive legal advice"],
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
agent = Agent(specialist=specialist, model="gpt-4o-mini")
|
|
117
|
+
|
|
118
|
+
async def main():
|
|
119
|
+
result = await agent.analyze(
|
|
120
|
+
"The service provider accepts unlimited liability for indirect damages."
|
|
121
|
+
)
|
|
122
|
+
print(result.pretty())
|
|
123
|
+
for rf in result.red_flags_triggered:
|
|
124
|
+
print(f"[{rf.severity.value.upper()}] {rf.trigger} -> {rf.action}")
|
|
125
|
+
|
|
126
|
+
asyncio.run(main())
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## YAML authoring — hand off to domain experts
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
name: falls_prevention_nurse
|
|
133
|
+
persona: You have 20+ years of UK care home experience...
|
|
134
|
+
frameworks: [NICE NG161, NICE CG176, Morse Fall Scale]
|
|
135
|
+
probes:
|
|
136
|
+
- Did the resident strike their head?
|
|
137
|
+
- Is the resident on anticoagulants?
|
|
138
|
+
red_flags:
|
|
139
|
+
- trigger: Head contact in an anticoagulated resident
|
|
140
|
+
severity: urgent
|
|
141
|
+
action: GP/111 contact within 2 hours; CT head may be required.
|
|
142
|
+
citation: "NICE CG176 §1.4.11"
|
|
143
|
+
match: semantic
|
|
144
|
+
themes: [Neurological observation, GP contact, Medication review]
|
|
145
|
+
citations_required: true
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from personakit import Specialist, Agent
|
|
150
|
+
|
|
151
|
+
spec = Specialist.from_yaml("falls_nurse.yaml")
|
|
152
|
+
agent = Agent(specialist=spec, model="claude-sonnet-4-6")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Red flags — the distinctive feature
|
|
156
|
+
|
|
157
|
+
Every RedFlag is a **trigger → severity → action → citation** contract:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
RedFlag(
|
|
161
|
+
trigger="Loss of consciousness",
|
|
162
|
+
severity=Severity.URGENT,
|
|
163
|
+
action="Call 999. Document LOC duration.",
|
|
164
|
+
citation="NICE CG176",
|
|
165
|
+
match=MatchMode.BOTH, # regex AND semantic
|
|
166
|
+
patterns=[r"\bLOC\b", r"unconscious"],
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Two-phase matching:
|
|
171
|
+
|
|
172
|
+
1. **Deterministic pre-match** (regex / keywords) — fast, offline, quotable.
|
|
173
|
+
2. **Semantic post-match** (LLM) — catches paraphrase and context.
|
|
174
|
+
|
|
175
|
+
Results are merged and de-duplicated. Deterministic evidence always wins.
|
|
176
|
+
|
|
177
|
+
## Structured output — derived from the Specialist
|
|
178
|
+
|
|
179
|
+
You never write a JSON schema by hand. The probes, red flags, and themes *are*
|
|
180
|
+
the schema:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
result = await agent.analyze(case_text)
|
|
184
|
+
|
|
185
|
+
result.summary # narrative summary
|
|
186
|
+
result.probes_answered # {probe_key: value_or_null}
|
|
187
|
+
result.probes_unanswered # list[Probe] — feeds interview mode
|
|
188
|
+
result.red_flags_triggered # list[TriggeredRedFlag] with evidence
|
|
189
|
+
result.recommendations # themed list with citations
|
|
190
|
+
result.citations_used # frameworks referenced
|
|
191
|
+
result.priorities_status # per-priority met / unmet / unknown
|
|
192
|
+
result.has_urgent # convenience flag
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Tools — opt-in, for external memory
|
|
196
|
+
|
|
197
|
+
Core is tool-free. When you want a tool, decorate a function and attach:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from personakit.tools import tool
|
|
201
|
+
|
|
202
|
+
@tool
|
|
203
|
+
def lookup_patient(patient_id: str) -> dict:
|
|
204
|
+
"""Fetch a patient record from the EHR."""
|
|
205
|
+
return ehr.get(patient_id)
|
|
206
|
+
|
|
207
|
+
agent_with_memory = agent.with_tools([lookup_patient])
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Providers that support tool calling (OpenAI, Anthropic) see the schema
|
|
211
|
+
automatically. Providers that don't, ignore it.
|
|
212
|
+
|
|
213
|
+
## Registry — for apps with many specialists
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from personakit import SpecialistRegistry
|
|
217
|
+
|
|
218
|
+
registry = SpecialistRegistry.from_directory("personas/")
|
|
219
|
+
clinical = registry.by_domain("healthcare.clinical")
|
|
220
|
+
fall_nurse = registry.get("falls_prevention_nurse")
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Bundled examples
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from personakit.examples import (
|
|
227
|
+
FALLS_PREVENTION_NURSE, # clinical — rich
|
|
228
|
+
CONTRACT_REVIEWER, # legal
|
|
229
|
+
MATH_TUTOR, # education — minimal shape
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Providers
|
|
234
|
+
|
|
235
|
+
| Extra | Install | Default model |
|
|
236
|
+
|---|---|---|
|
|
237
|
+
| `personakit[openai]` | `openai>=1.0` | `gpt-4o-mini` |
|
|
238
|
+
| `personakit[anthropic]` | `anthropic>=0.20` | `claude-sonnet-4-6` |
|
|
239
|
+
| `personakit[yaml]` | `pyyaml>=6.0` | — |
|
|
240
|
+
| `personakit[all]` | all of the above | — |
|
|
241
|
+
|
|
242
|
+
The `MockProvider` is always available for offline testing:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from personakit.testing import MockProvider
|
|
246
|
+
provider = MockProvider(responses={"summary": "...", ...})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Testing helpers
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from personakit.testing import assert_triggered, assert_cited
|
|
253
|
+
|
|
254
|
+
result = await agent.analyze("Patient on warfarin, fell and struck head.")
|
|
255
|
+
assert_triggered(result, "head_contact_in_an_anticoagulated_resident")
|
|
256
|
+
assert_cited(result, "NICE CG176")
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Design principles
|
|
260
|
+
|
|
261
|
+
1. **Specialist is pure data.** No behaviour, no side effects, serializable.
|
|
262
|
+
2. **Schema is derived.** Probes, red flags, and themes *are* the output contract.
|
|
263
|
+
3. **Deterministic where possible, semantic where needed.** Red flags run both.
|
|
264
|
+
4. **Tools are opt-in.** Core has zero coupling to tool calling.
|
|
265
|
+
5. **Minimal dependencies.** `pydantic` + `httpx` for the core. Everything else is an extra.
|
|
266
|
+
6. **Domain-neutral.** Healthcare, legal, finance, education, support, product. One library.
|
|
267
|
+
7. **Provider-agnostic.** Same Specialist, any model.
|
|
268
|
+
|
|
269
|
+
## Status
|
|
270
|
+
|
|
271
|
+
Early alpha — API may evolve. See `CHANGELOG.md` for release notes.
|
|
272
|
+
|
|
273
|
+
## Author
|
|
274
|
+
|
|
275
|
+
**Majidul Islam** — [@Majidul17068](https://github.com/Majidul17068)
|
|
276
|
+
|
|
277
|
+
personakit is an independent open-source project. Contributions welcome.
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
MIT © 2026 Majidul Islam.
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# personakit
|
|
2
|
+
|
|
3
|
+
**Declarative specialist agents for LLMs.** Encode a role's expertise —
|
|
4
|
+
persona, frameworks, probes, red flags, recommendation themes — as data.
|
|
5
|
+
Get a production agent that produces structured, cited, safety-aware output.
|
|
6
|
+
|
|
7
|
+
> Created by **[Majidul Islam](https://github.com/Majidul17068)**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install personakit[openai]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
LangChain is for wiring LLM calls. CrewAI is for orchestrating agent teams.
|
|
18
|
+
LangGraph is for branching control flow.
|
|
19
|
+
|
|
20
|
+
**personakit is for encoding specialist expertise declaratively.** A nurse, a
|
|
21
|
+
lawyer, an analyst, or a PM can author a specialist in Python or YAML and hand
|
|
22
|
+
it to engineers. No prompt engineering, no chain wiring.
|
|
23
|
+
|
|
24
|
+
The distinctive pieces:
|
|
25
|
+
|
|
26
|
+
| Concept | What it gives you |
|
|
27
|
+
|---|---|
|
|
28
|
+
| **Specialist** | A frozen dataclass — the entire agent definition |
|
|
29
|
+
| **Framework** | Body of knowledge + citation key, enforced in output |
|
|
30
|
+
| **Probe** | Diagnostic question; becomes a field in the structured response |
|
|
31
|
+
| **RedFlag** | Trigger → action → citation; matched deterministically AND semantically |
|
|
32
|
+
| **Theme** | User-selectable recommendation category |
|
|
33
|
+
| **Priority** | Always-on checks reported as met / unmet / unknown |
|
|
34
|
+
| **Tool (optional)** | `@tool` decorator; opt-in for external memory or API calls |
|
|
35
|
+
|
|
36
|
+
Core has just two runtime deps: **pydantic** and **httpx**.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import asyncio
|
|
44
|
+
from personakit import Agent, Specialist, Framework, Probe, RedFlag, Severity, Theme
|
|
45
|
+
|
|
46
|
+
specialist = Specialist(
|
|
47
|
+
name="contract_reviewer",
|
|
48
|
+
display_name="M&A Contract Reviewer",
|
|
49
|
+
persona="You are a senior M&A attorney. Flag risks. Propose redlines.",
|
|
50
|
+
frameworks=[Framework(name="UCC"), Framework(name="English contract law")],
|
|
51
|
+
probes=[
|
|
52
|
+
Probe(question="What's the governing jurisdiction?"),
|
|
53
|
+
Probe(question="Is there an unlimited liability clause?",
|
|
54
|
+
value_type="boolean", weight="high"),
|
|
55
|
+
],
|
|
56
|
+
red_flags=[
|
|
57
|
+
RedFlag(
|
|
58
|
+
trigger="Unlimited liability",
|
|
59
|
+
severity=Severity.CRITICAL,
|
|
60
|
+
action="Negotiate a cap — 12 months' fees is market standard.",
|
|
61
|
+
patterns=[r"unlimited liability", r"uncapped"],
|
|
62
|
+
),
|
|
63
|
+
],
|
|
64
|
+
themes=[Theme(name="Liability & indemnities"), Theme(name="IP & licensing")],
|
|
65
|
+
constraints=["Never give conclusive legal advice"],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
agent = Agent(specialist=specialist, model="gpt-4o-mini")
|
|
69
|
+
|
|
70
|
+
async def main():
|
|
71
|
+
result = await agent.analyze(
|
|
72
|
+
"The service provider accepts unlimited liability for indirect damages."
|
|
73
|
+
)
|
|
74
|
+
print(result.pretty())
|
|
75
|
+
for rf in result.red_flags_triggered:
|
|
76
|
+
print(f"[{rf.severity.value.upper()}] {rf.trigger} -> {rf.action}")
|
|
77
|
+
|
|
78
|
+
asyncio.run(main())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## YAML authoring — hand off to domain experts
|
|
82
|
+
|
|
83
|
+
```yaml
|
|
84
|
+
name: falls_prevention_nurse
|
|
85
|
+
persona: You have 20+ years of UK care home experience...
|
|
86
|
+
frameworks: [NICE NG161, NICE CG176, Morse Fall Scale]
|
|
87
|
+
probes:
|
|
88
|
+
- Did the resident strike their head?
|
|
89
|
+
- Is the resident on anticoagulants?
|
|
90
|
+
red_flags:
|
|
91
|
+
- trigger: Head contact in an anticoagulated resident
|
|
92
|
+
severity: urgent
|
|
93
|
+
action: GP/111 contact within 2 hours; CT head may be required.
|
|
94
|
+
citation: "NICE CG176 §1.4.11"
|
|
95
|
+
match: semantic
|
|
96
|
+
themes: [Neurological observation, GP contact, Medication review]
|
|
97
|
+
citations_required: true
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from personakit import Specialist, Agent
|
|
102
|
+
|
|
103
|
+
spec = Specialist.from_yaml("falls_nurse.yaml")
|
|
104
|
+
agent = Agent(specialist=spec, model="claude-sonnet-4-6")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Red flags — the distinctive feature
|
|
108
|
+
|
|
109
|
+
Every RedFlag is a **trigger → severity → action → citation** contract:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
RedFlag(
|
|
113
|
+
trigger="Loss of consciousness",
|
|
114
|
+
severity=Severity.URGENT,
|
|
115
|
+
action="Call 999. Document LOC duration.",
|
|
116
|
+
citation="NICE CG176",
|
|
117
|
+
match=MatchMode.BOTH, # regex AND semantic
|
|
118
|
+
patterns=[r"\bLOC\b", r"unconscious"],
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Two-phase matching:
|
|
123
|
+
|
|
124
|
+
1. **Deterministic pre-match** (regex / keywords) — fast, offline, quotable.
|
|
125
|
+
2. **Semantic post-match** (LLM) — catches paraphrase and context.
|
|
126
|
+
|
|
127
|
+
Results are merged and de-duplicated. Deterministic evidence always wins.
|
|
128
|
+
|
|
129
|
+
## Structured output — derived from the Specialist
|
|
130
|
+
|
|
131
|
+
You never write a JSON schema by hand. The probes, red flags, and themes *are*
|
|
132
|
+
the schema:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
result = await agent.analyze(case_text)
|
|
136
|
+
|
|
137
|
+
result.summary # narrative summary
|
|
138
|
+
result.probes_answered # {probe_key: value_or_null}
|
|
139
|
+
result.probes_unanswered # list[Probe] — feeds interview mode
|
|
140
|
+
result.red_flags_triggered # list[TriggeredRedFlag] with evidence
|
|
141
|
+
result.recommendations # themed list with citations
|
|
142
|
+
result.citations_used # frameworks referenced
|
|
143
|
+
result.priorities_status # per-priority met / unmet / unknown
|
|
144
|
+
result.has_urgent # convenience flag
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Tools — opt-in, for external memory
|
|
148
|
+
|
|
149
|
+
Core is tool-free. When you want a tool, decorate a function and attach:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from personakit.tools import tool
|
|
153
|
+
|
|
154
|
+
@tool
|
|
155
|
+
def lookup_patient(patient_id: str) -> dict:
|
|
156
|
+
"""Fetch a patient record from the EHR."""
|
|
157
|
+
return ehr.get(patient_id)
|
|
158
|
+
|
|
159
|
+
agent_with_memory = agent.with_tools([lookup_patient])
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Providers that support tool calling (OpenAI, Anthropic) see the schema
|
|
163
|
+
automatically. Providers that don't, ignore it.
|
|
164
|
+
|
|
165
|
+
## Registry — for apps with many specialists
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from personakit import SpecialistRegistry
|
|
169
|
+
|
|
170
|
+
registry = SpecialistRegistry.from_directory("personas/")
|
|
171
|
+
clinical = registry.by_domain("healthcare.clinical")
|
|
172
|
+
fall_nurse = registry.get("falls_prevention_nurse")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Bundled examples
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from personakit.examples import (
|
|
179
|
+
FALLS_PREVENTION_NURSE, # clinical — rich
|
|
180
|
+
CONTRACT_REVIEWER, # legal
|
|
181
|
+
MATH_TUTOR, # education — minimal shape
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Providers
|
|
186
|
+
|
|
187
|
+
| Extra | Install | Default model |
|
|
188
|
+
|---|---|---|
|
|
189
|
+
| `personakit[openai]` | `openai>=1.0` | `gpt-4o-mini` |
|
|
190
|
+
| `personakit[anthropic]` | `anthropic>=0.20` | `claude-sonnet-4-6` |
|
|
191
|
+
| `personakit[yaml]` | `pyyaml>=6.0` | — |
|
|
192
|
+
| `personakit[all]` | all of the above | — |
|
|
193
|
+
|
|
194
|
+
The `MockProvider` is always available for offline testing:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from personakit.testing import MockProvider
|
|
198
|
+
provider = MockProvider(responses={"summary": "...", ...})
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Testing helpers
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from personakit.testing import assert_triggered, assert_cited
|
|
205
|
+
|
|
206
|
+
result = await agent.analyze("Patient on warfarin, fell and struck head.")
|
|
207
|
+
assert_triggered(result, "head_contact_in_an_anticoagulated_resident")
|
|
208
|
+
assert_cited(result, "NICE CG176")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Design principles
|
|
212
|
+
|
|
213
|
+
1. **Specialist is pure data.** No behaviour, no side effects, serializable.
|
|
214
|
+
2. **Schema is derived.** Probes, red flags, and themes *are* the output contract.
|
|
215
|
+
3. **Deterministic where possible, semantic where needed.** Red flags run both.
|
|
216
|
+
4. **Tools are opt-in.** Core has zero coupling to tool calling.
|
|
217
|
+
5. **Minimal dependencies.** `pydantic` + `httpx` for the core. Everything else is an extra.
|
|
218
|
+
6. **Domain-neutral.** Healthcare, legal, finance, education, support, product. One library.
|
|
219
|
+
7. **Provider-agnostic.** Same Specialist, any model.
|
|
220
|
+
|
|
221
|
+
## Status
|
|
222
|
+
|
|
223
|
+
Early alpha — API may evolve. See `CHANGELOG.md` for release notes.
|
|
224
|
+
|
|
225
|
+
## Author
|
|
226
|
+
|
|
227
|
+
**Majidul Islam** — [@Majidul17068](https://github.com/Majidul17068)
|
|
228
|
+
|
|
229
|
+
personakit is an independent open-source project. Contributions welcome.
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
MIT © 2026 Majidul Islam.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "personakit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Declarative specialist agents for LLMs — persona, frameworks, probes, red flags, and citations as first-class concepts."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Majidul Islam", email = "contact.majidul.islam@gmail.com" }]
|
|
13
|
+
maintainers = [{ name = "Majidul Islam", email = "contact.majidul.islam@gmail.com" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"llm",
|
|
16
|
+
"agent",
|
|
17
|
+
"persona",
|
|
18
|
+
"specialist",
|
|
19
|
+
"prompt-engineering",
|
|
20
|
+
"openai",
|
|
21
|
+
"anthropic",
|
|
22
|
+
"ai",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 3 - Alpha",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.10",
|
|
31
|
+
"Programming Language :: Python :: 3.11",
|
|
32
|
+
"Programming Language :: Python :: 3.12",
|
|
33
|
+
"Programming Language :: Python :: 3.13",
|
|
34
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
35
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
dependencies = [
|
|
39
|
+
"pydantic>=2.5",
|
|
40
|
+
"httpx>=0.25",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
openai = ["openai>=1.0"]
|
|
45
|
+
anthropic = ["anthropic>=0.20"]
|
|
46
|
+
yaml = ["pyyaml>=6.0"]
|
|
47
|
+
all = ["personakit[openai,anthropic,yaml]"]
|
|
48
|
+
dev = [
|
|
49
|
+
"pytest>=7.4",
|
|
50
|
+
"pytest-asyncio>=0.23",
|
|
51
|
+
"pytest-cov>=4.1",
|
|
52
|
+
"ruff>=0.3",
|
|
53
|
+
"mypy>=1.8",
|
|
54
|
+
"pyyaml>=6.0",
|
|
55
|
+
"types-PyYAML>=6.0",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[project.urls]
|
|
59
|
+
Homepage = "https://github.com/Majidul17068/personakit"
|
|
60
|
+
Repository = "https://github.com/Majidul17068/personakit"
|
|
61
|
+
Issues = "https://github.com/Majidul17068/personakit/issues"
|
|
62
|
+
Changelog = "https://github.com/Majidul17068/personakit/blob/main/CHANGELOG.md"
|
|
63
|
+
|
|
64
|
+
[tool.hatch.build.targets.wheel]
|
|
65
|
+
packages = ["src/personakit"]
|
|
66
|
+
|
|
67
|
+
[tool.hatch.build.targets.sdist]
|
|
68
|
+
include = ["src/personakit", "tests", "README.md", "LICENSE", "CHANGELOG.md"]
|
|
69
|
+
|
|
70
|
+
[tool.ruff]
|
|
71
|
+
line-length = 100
|
|
72
|
+
target-version = "py310"
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E", "F", "I", "UP", "B", "SIM", "ANN", "RUF"]
|
|
76
|
+
ignore = ["ANN401"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.per-file-ignores]
|
|
79
|
+
"tests/*" = ["ANN"]
|
|
80
|
+
"src/personakit/examples/*" = ["E501"]
|
|
81
|
+
|
|
82
|
+
[tool.mypy]
|
|
83
|
+
python_version = "3.10"
|
|
84
|
+
strict = true
|
|
85
|
+
warn_unused_ignores = true
|
|
86
|
+
warn_redundant_casts = true
|
|
87
|
+
disallow_untyped_defs = true
|
|
88
|
+
disallow_any_generics = true
|
|
89
|
+
|
|
90
|
+
[[tool.mypy.overrides]]
|
|
91
|
+
module = ["openai.*", "anthropic.*", "yaml.*"]
|
|
92
|
+
ignore_missing_imports = true
|
|
93
|
+
|
|
94
|
+
[tool.pytest.ini_options]
|
|
95
|
+
asyncio_mode = "auto"
|
|
96
|
+
testpaths = ["tests"]
|
|
97
|
+
addopts = "-ra --strict-markers"
|