agent-prompt-engineering 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.
- agent_prompt_engineering-0.1.0/PKG-INFO +122 -0
- agent_prompt_engineering-0.1.0/SKILL.md +112 -0
- agent_prompt_engineering-0.1.0/agent_prompt_engineering.egg-info/PKG-INFO +122 -0
- agent_prompt_engineering-0.1.0/agent_prompt_engineering.egg-info/SOURCES.txt +28 -0
- agent_prompt_engineering-0.1.0/agent_prompt_engineering.egg-info/dependency_links.txt +1 -0
- agent_prompt_engineering-0.1.0/agent_prompt_engineering.egg-info/requires.txt +2 -0
- agent_prompt_engineering-0.1.0/agent_prompt_engineering.egg-info/top_level.txt +1 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/__init__.py +65 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/cognition.py +149 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/gate.py +71 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/grammar.py +123 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/persona.py +61 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/prompt_engine.py +110 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/skillpack.py +75 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/template_mixins.py +137 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/agent.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/deity.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/egregore.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/progenitor.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/template.json +5 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/five_level/world.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/persona/output_format.json +6 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/persona/persona.json +6 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/persona/rules.json +6 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/persona/system.json +6 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/persona/template.json +5 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/simple_agent/agent.json +4 -0
- agent_prompt_engineering-0.1.0/prompt_engineering/templates/simple_agent/template.json +5 -0
- agent_prompt_engineering-0.1.0/pyproject.toml +24 -0
- agent_prompt_engineering-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-prompt-engineering
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic data->prompt builder + cognition chains + optional grammar gate — the shared base of the chaincompiler ecosystem.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: rulecatcher
|
|
9
|
+
Requires-Dist: agent-skilltree>=0.2.1
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
name: prompt-engineering
|
|
13
|
+
description: The Prompt Engineering System — a deterministic prompt builder. Give it a payload (a "block": attributes + methods + a render sequence) and it produces the SAME prompt every time. Compose blocks into stored "prompt templates". Use it to make system prompts, personas, rule blocks, few-shot blocks, or any prompt. No model call, no randomness.
|
|
14
|
+
when_to_use: Building or reusing prompts/personas/templates programmatically; you want the same spec to render the same prompt every time; making a new prompt template (folder of blocks).
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Prompt Engineering System
|
|
18
|
+
|
|
19
|
+
A skill (this `SKILL.md` + the code beside it) that turns **data → a prompt**, deterministically. The
|
|
20
|
+
model decides *what* spec to write; this engine guarantees *how* it renders — same inputs, same output,
|
|
21
|
+
every time. That reliability is the point: an agent reads this skill and uses it to make prompts/personas
|
|
22
|
+
the same way each time.
|
|
23
|
+
|
|
24
|
+
## Vocabulary
|
|
25
|
+
|
|
26
|
+
- **block** — one payload (`values` + `methods` + a `template_sequence`) that renders to a chunk of prompt
|
|
27
|
+
- **prompt template** — a stored, ordered set of blocks (a folder under `templates/`) that renders to one
|
|
28
|
+
full prompt
|
|
29
|
+
|
|
30
|
+
There is **no baked-in structure and no "levels."** You bring your own via blocks and templates.
|
|
31
|
+
|
|
32
|
+
## Use it (the package `prompt_engineering`)
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# pip install -e . (or add this skill dir to sys.path for in-place use)
|
|
36
|
+
from prompt_engineering import render, render_template, list_templates
|
|
37
|
+
|
|
38
|
+
# 1) render a single block from a payload
|
|
39
|
+
render({
|
|
40
|
+
"values": {"role": "Worldsmith", "domain": "otters"},
|
|
41
|
+
"methods": [
|
|
42
|
+
{"name": "format_title", "func": "return f'# {self.role}'", "add_to_sequence": True},
|
|
43
|
+
{"name": "format_intro", "func": "return f'You are the {self.role} of {self.domain}.'", "add_to_sequence": True},
|
|
44
|
+
],
|
|
45
|
+
}) # → "# Worldsmith\n\nYou are the Worldsmith of otters." (same payload → same prompt, always)
|
|
46
|
+
|
|
47
|
+
# 2) render a stored prompt template (its blocks, joined in order)
|
|
48
|
+
list_templates() # ['five_level', 'simple_agent']
|
|
49
|
+
render_template("five_level") # → one prompt with WORLD/EGREGORE/DEITY/PROGENITOR/AGENT sections
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or from the shell (see `scripts/` below): `python scripts/make_prompt.py --template five_level`.
|
|
53
|
+
|
|
54
|
+
> **Naming tip:** name block methods `format_*` so they don't shadow the `values` they read
|
|
55
|
+
> (a method `duty` would overwrite the value `duty`; `format_duty` reading `self.duty` is correct).
|
|
56
|
+
|
|
57
|
+
## Add a prompt template — DROP A FOLDER
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
templates/
|
|
61
|
+
{template_name}/
|
|
62
|
+
template.json # {name, description, blocks: ["block1.json", "block2.json", ...]}
|
|
63
|
+
{block}.json # the block payloads (any structure you want)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Create the folder, write `template.json`, drop in the block payloads. Nothing in the engine changes.
|
|
67
|
+
`list_templates()` / `render_template(name)` pick it up by convention.
|
|
68
|
+
|
|
69
|
+
## Resource files (referenced by relative path)
|
|
70
|
+
|
|
71
|
+
- `prompt_engineering/prompt_engine.py` — the API: `render`, `render_file`, `list_templates`, `load_template`,
|
|
72
|
+
`render_template`, `render_template_blocks`
|
|
73
|
+
- `prompt_engineering/template_mixins.py` — the engine internals (add attributes/methods from data; run a sequence)
|
|
74
|
+
- `examples/` — single-block payloads for different **prompt block types** (system, persona, rules,
|
|
75
|
+
few-shot, constraints, output-format) and full personas — read these to learn the block format
|
|
76
|
+
- `templates/five_level/` — the 5-level model **as a prompt template** (an example, not a default)
|
|
77
|
+
- `templates/simple_agent/` — a one-block template (proves the add-by-folder mechanic)
|
|
78
|
+
- `prompt_engineering/cognition.py` — the cognition-chain stack (attention chain / chain-of-reasoning / skill chain) on
|
|
79
|
+
the engine, + `validate_chain` (a shallow no-dep broken-detector)
|
|
80
|
+
- `prompt_engineering/gate.py` — the REAL gate: `gate(text, exemplars)` LEARNS the grammar from exemplar chains (you don't
|
|
81
|
+
hand-write the error rules) → violations + fixes + the `orthogonal`/`syntax_break` (steerable/fatal) verdict
|
|
82
|
+
- **`rulecatcher`** — the grammar learner/linter the gate runs on; now an installed dependency (D3, un-vendored)
|
|
83
|
+
- `prompt_engineering/persona.py` — `make_persona(spec)` / `make_persona_file(path)`: generate a full persona prompt
|
|
84
|
+
(block types + a cognition DSL block) from a small spec
|
|
85
|
+
- `examples/persona_*.json` — example persona systems (debugger, socratic, code-reviewer) with reasoning DSLs
|
|
86
|
+
- `scripts/make_prompt.py` — render a block/template from the command line
|
|
87
|
+
- `scripts/make_persona.py` — generate a persona prompt from a spec file
|
|
88
|
+
- `scripts/new_template_skill.py` — scaffold a NEW skill package for a prompt template
|
|
89
|
+
- `test_prompt_engine.py` · `test_cognition.py` · `test_persona.py` · `test_gate.py` — run to verify (all NO-API)
|
|
90
|
+
|
|
91
|
+
## Cognition chains & personas (the ACCC/CORCC/SCCC stack, rebuilt right)
|
|
92
|
+
|
|
93
|
+
`prompt_engineering/cognition.py` is the clean version of the old `*CC` "compiler-compilers": an **attention chain**, a
|
|
94
|
+
**chain-of-reasoning**, and a **skill chain** are just prompt templates composed on this engine (a CoR
|
|
95
|
+
*nests* an AC = block-nesting). **Rendering never touches a grammar engine or a DB.**
|
|
96
|
+
|
|
97
|
+
The **gate is a separate, optional layer** (`prompt_engineering/gate.py`, on the **`rulecatcher`** package). You don't
|
|
98
|
+
hand-write the error rules: `gate(text, exemplars)` LEARNS the grammar from the template's exemplar chains
|
|
99
|
+
(`next_kind` = shape, `next_token` = vocabulary), then lints a candidate → violations + fixes + the
|
|
100
|
+
`orthogonal` (in the language, wrong slot → **steerable**) vs `syntax_break` (foreign → **fatal**) verdict.
|
|
101
|
+
`rulecatcher` is an installed dependency (D3), so the real gate runs everywhere it's installed.
|
|
102
|
+
(`validate_chain` remains a shallow no-dep fallback.)
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from prompt_engineering import render_cor, gate, make_persona
|
|
106
|
+
|
|
107
|
+
render_cor("Debugger", ["Symptom", "Repro", "Hypothesis"], "Localize", "the root cause") # a CoR persona
|
|
108
|
+
gate("[Goal] ⇒ [Repro] ⇒ |Localize|", # learn from exemplars, then lint:
|
|
109
|
+
exemplars=["[Symptom] ⇒ [Repro] ⇒ |Localize|", "[Symptom] ⇒ [Bisect] ⇒ |RootCause|"])
|
|
110
|
+
# → {ok: False, verdict: 'orthogonal', violations: [{found:'Goal', candidates:['Symptom'], ...}]}
|
|
111
|
+
|
|
112
|
+
make_persona({ # a whole persona with a complex reasoning DSL, in one call
|
|
113
|
+
"name": "Ada", "role": "a senior debugger",
|
|
114
|
+
"reasoning": {"foci": ["Symptom", "Repro", "Bisect"], "held": "RootCause", "decision": "the minimal fix"},
|
|
115
|
+
"rules": ["Reproduce before theorizing."], "output": "A markdown report.",
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Why deterministic matters
|
|
120
|
+
|
|
121
|
+
`render` runs the `template_sequence` in order and joins the non-empty results — pure composition, no
|
|
122
|
+
model call. That's what lets an agent rely on it to produce prompts consistently across runs.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prompt-engineering
|
|
3
|
+
description: The Prompt Engineering System — a deterministic prompt builder. Give it a payload (a "block": attributes + methods + a render sequence) and it produces the SAME prompt every time. Compose blocks into stored "prompt templates". Use it to make system prompts, personas, rule blocks, few-shot blocks, or any prompt. No model call, no randomness.
|
|
4
|
+
when_to_use: Building or reusing prompts/personas/templates programmatically; you want the same spec to render the same prompt every time; making a new prompt template (folder of blocks).
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Prompt Engineering System
|
|
8
|
+
|
|
9
|
+
A skill (this `SKILL.md` + the code beside it) that turns **data → a prompt**, deterministically. The
|
|
10
|
+
model decides *what* spec to write; this engine guarantees *how* it renders — same inputs, same output,
|
|
11
|
+
every time. That reliability is the point: an agent reads this skill and uses it to make prompts/personas
|
|
12
|
+
the same way each time.
|
|
13
|
+
|
|
14
|
+
## Vocabulary
|
|
15
|
+
|
|
16
|
+
- **block** — one payload (`values` + `methods` + a `template_sequence`) that renders to a chunk of prompt
|
|
17
|
+
- **prompt template** — a stored, ordered set of blocks (a folder under `templates/`) that renders to one
|
|
18
|
+
full prompt
|
|
19
|
+
|
|
20
|
+
There is **no baked-in structure and no "levels."** You bring your own via blocks and templates.
|
|
21
|
+
|
|
22
|
+
## Use it (the package `prompt_engineering`)
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
# pip install -e . (or add this skill dir to sys.path for in-place use)
|
|
26
|
+
from prompt_engineering import render, render_template, list_templates
|
|
27
|
+
|
|
28
|
+
# 1) render a single block from a payload
|
|
29
|
+
render({
|
|
30
|
+
"values": {"role": "Worldsmith", "domain": "otters"},
|
|
31
|
+
"methods": [
|
|
32
|
+
{"name": "format_title", "func": "return f'# {self.role}'", "add_to_sequence": True},
|
|
33
|
+
{"name": "format_intro", "func": "return f'You are the {self.role} of {self.domain}.'", "add_to_sequence": True},
|
|
34
|
+
],
|
|
35
|
+
}) # → "# Worldsmith\n\nYou are the Worldsmith of otters." (same payload → same prompt, always)
|
|
36
|
+
|
|
37
|
+
# 2) render a stored prompt template (its blocks, joined in order)
|
|
38
|
+
list_templates() # ['five_level', 'simple_agent']
|
|
39
|
+
render_template("five_level") # → one prompt with WORLD/EGREGORE/DEITY/PROGENITOR/AGENT sections
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or from the shell (see `scripts/` below): `python scripts/make_prompt.py --template five_level`.
|
|
43
|
+
|
|
44
|
+
> **Naming tip:** name block methods `format_*` so they don't shadow the `values` they read
|
|
45
|
+
> (a method `duty` would overwrite the value `duty`; `format_duty` reading `self.duty` is correct).
|
|
46
|
+
|
|
47
|
+
## Add a prompt template — DROP A FOLDER
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
templates/
|
|
51
|
+
{template_name}/
|
|
52
|
+
template.json # {name, description, blocks: ["block1.json", "block2.json", ...]}
|
|
53
|
+
{block}.json # the block payloads (any structure you want)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Create the folder, write `template.json`, drop in the block payloads. Nothing in the engine changes.
|
|
57
|
+
`list_templates()` / `render_template(name)` pick it up by convention.
|
|
58
|
+
|
|
59
|
+
## Resource files (referenced by relative path)
|
|
60
|
+
|
|
61
|
+
- `prompt_engineering/prompt_engine.py` — the API: `render`, `render_file`, `list_templates`, `load_template`,
|
|
62
|
+
`render_template`, `render_template_blocks`
|
|
63
|
+
- `prompt_engineering/template_mixins.py` — the engine internals (add attributes/methods from data; run a sequence)
|
|
64
|
+
- `examples/` — single-block payloads for different **prompt block types** (system, persona, rules,
|
|
65
|
+
few-shot, constraints, output-format) and full personas — read these to learn the block format
|
|
66
|
+
- `templates/five_level/` — the 5-level model **as a prompt template** (an example, not a default)
|
|
67
|
+
- `templates/simple_agent/` — a one-block template (proves the add-by-folder mechanic)
|
|
68
|
+
- `prompt_engineering/cognition.py` — the cognition-chain stack (attention chain / chain-of-reasoning / skill chain) on
|
|
69
|
+
the engine, + `validate_chain` (a shallow no-dep broken-detector)
|
|
70
|
+
- `prompt_engineering/gate.py` — the REAL gate: `gate(text, exemplars)` LEARNS the grammar from exemplar chains (you don't
|
|
71
|
+
hand-write the error rules) → violations + fixes + the `orthogonal`/`syntax_break` (steerable/fatal) verdict
|
|
72
|
+
- **`rulecatcher`** — the grammar learner/linter the gate runs on; now an installed dependency (D3, un-vendored)
|
|
73
|
+
- `prompt_engineering/persona.py` — `make_persona(spec)` / `make_persona_file(path)`: generate a full persona prompt
|
|
74
|
+
(block types + a cognition DSL block) from a small spec
|
|
75
|
+
- `examples/persona_*.json` — example persona systems (debugger, socratic, code-reviewer) with reasoning DSLs
|
|
76
|
+
- `scripts/make_prompt.py` — render a block/template from the command line
|
|
77
|
+
- `scripts/make_persona.py` — generate a persona prompt from a spec file
|
|
78
|
+
- `scripts/new_template_skill.py` — scaffold a NEW skill package for a prompt template
|
|
79
|
+
- `test_prompt_engine.py` · `test_cognition.py` · `test_persona.py` · `test_gate.py` — run to verify (all NO-API)
|
|
80
|
+
|
|
81
|
+
## Cognition chains & personas (the ACCC/CORCC/SCCC stack, rebuilt right)
|
|
82
|
+
|
|
83
|
+
`prompt_engineering/cognition.py` is the clean version of the old `*CC` "compiler-compilers": an **attention chain**, a
|
|
84
|
+
**chain-of-reasoning**, and a **skill chain** are just prompt templates composed on this engine (a CoR
|
|
85
|
+
*nests* an AC = block-nesting). **Rendering never touches a grammar engine or a DB.**
|
|
86
|
+
|
|
87
|
+
The **gate is a separate, optional layer** (`prompt_engineering/gate.py`, on the **`rulecatcher`** package). You don't
|
|
88
|
+
hand-write the error rules: `gate(text, exemplars)` LEARNS the grammar from the template's exemplar chains
|
|
89
|
+
(`next_kind` = shape, `next_token` = vocabulary), then lints a candidate → violations + fixes + the
|
|
90
|
+
`orthogonal` (in the language, wrong slot → **steerable**) vs `syntax_break` (foreign → **fatal**) verdict.
|
|
91
|
+
`rulecatcher` is an installed dependency (D3), so the real gate runs everywhere it's installed.
|
|
92
|
+
(`validate_chain` remains a shallow no-dep fallback.)
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from prompt_engineering import render_cor, gate, make_persona
|
|
96
|
+
|
|
97
|
+
render_cor("Debugger", ["Symptom", "Repro", "Hypothesis"], "Localize", "the root cause") # a CoR persona
|
|
98
|
+
gate("[Goal] ⇒ [Repro] ⇒ |Localize|", # learn from exemplars, then lint:
|
|
99
|
+
exemplars=["[Symptom] ⇒ [Repro] ⇒ |Localize|", "[Symptom] ⇒ [Bisect] ⇒ |RootCause|"])
|
|
100
|
+
# → {ok: False, verdict: 'orthogonal', violations: [{found:'Goal', candidates:['Symptom'], ...}]}
|
|
101
|
+
|
|
102
|
+
make_persona({ # a whole persona with a complex reasoning DSL, in one call
|
|
103
|
+
"name": "Ada", "role": "a senior debugger",
|
|
104
|
+
"reasoning": {"foci": ["Symptom", "Repro", "Bisect"], "held": "RootCause", "decision": "the minimal fix"},
|
|
105
|
+
"rules": ["Reproduce before theorizing."], "output": "A markdown report.",
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Why deterministic matters
|
|
110
|
+
|
|
111
|
+
`render` runs the `template_sequence` in order and joins the non-empty results — pure composition, no
|
|
112
|
+
model call. That's what lets an agent rely on it to produce prompts consistently across runs.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-prompt-engineering
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Deterministic data->prompt builder + cognition chains + optional grammar gate — the shared base of the chaincompiler ecosystem.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: rulecatcher
|
|
9
|
+
Requires-Dist: agent-skilltree>=0.2.1
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
name: prompt-engineering
|
|
13
|
+
description: The Prompt Engineering System — a deterministic prompt builder. Give it a payload (a "block": attributes + methods + a render sequence) and it produces the SAME prompt every time. Compose blocks into stored "prompt templates". Use it to make system prompts, personas, rule blocks, few-shot blocks, or any prompt. No model call, no randomness.
|
|
14
|
+
when_to_use: Building or reusing prompts/personas/templates programmatically; you want the same spec to render the same prompt every time; making a new prompt template (folder of blocks).
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Prompt Engineering System
|
|
18
|
+
|
|
19
|
+
A skill (this `SKILL.md` + the code beside it) that turns **data → a prompt**, deterministically. The
|
|
20
|
+
model decides *what* spec to write; this engine guarantees *how* it renders — same inputs, same output,
|
|
21
|
+
every time. That reliability is the point: an agent reads this skill and uses it to make prompts/personas
|
|
22
|
+
the same way each time.
|
|
23
|
+
|
|
24
|
+
## Vocabulary
|
|
25
|
+
|
|
26
|
+
- **block** — one payload (`values` + `methods` + a `template_sequence`) that renders to a chunk of prompt
|
|
27
|
+
- **prompt template** — a stored, ordered set of blocks (a folder under `templates/`) that renders to one
|
|
28
|
+
full prompt
|
|
29
|
+
|
|
30
|
+
There is **no baked-in structure and no "levels."** You bring your own via blocks and templates.
|
|
31
|
+
|
|
32
|
+
## Use it (the package `prompt_engineering`)
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# pip install -e . (or add this skill dir to sys.path for in-place use)
|
|
36
|
+
from prompt_engineering import render, render_template, list_templates
|
|
37
|
+
|
|
38
|
+
# 1) render a single block from a payload
|
|
39
|
+
render({
|
|
40
|
+
"values": {"role": "Worldsmith", "domain": "otters"},
|
|
41
|
+
"methods": [
|
|
42
|
+
{"name": "format_title", "func": "return f'# {self.role}'", "add_to_sequence": True},
|
|
43
|
+
{"name": "format_intro", "func": "return f'You are the {self.role} of {self.domain}.'", "add_to_sequence": True},
|
|
44
|
+
],
|
|
45
|
+
}) # → "# Worldsmith\n\nYou are the Worldsmith of otters." (same payload → same prompt, always)
|
|
46
|
+
|
|
47
|
+
# 2) render a stored prompt template (its blocks, joined in order)
|
|
48
|
+
list_templates() # ['five_level', 'simple_agent']
|
|
49
|
+
render_template("five_level") # → one prompt with WORLD/EGREGORE/DEITY/PROGENITOR/AGENT sections
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or from the shell (see `scripts/` below): `python scripts/make_prompt.py --template five_level`.
|
|
53
|
+
|
|
54
|
+
> **Naming tip:** name block methods `format_*` so they don't shadow the `values` they read
|
|
55
|
+
> (a method `duty` would overwrite the value `duty`; `format_duty` reading `self.duty` is correct).
|
|
56
|
+
|
|
57
|
+
## Add a prompt template — DROP A FOLDER
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
templates/
|
|
61
|
+
{template_name}/
|
|
62
|
+
template.json # {name, description, blocks: ["block1.json", "block2.json", ...]}
|
|
63
|
+
{block}.json # the block payloads (any structure you want)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Create the folder, write `template.json`, drop in the block payloads. Nothing in the engine changes.
|
|
67
|
+
`list_templates()` / `render_template(name)` pick it up by convention.
|
|
68
|
+
|
|
69
|
+
## Resource files (referenced by relative path)
|
|
70
|
+
|
|
71
|
+
- `prompt_engineering/prompt_engine.py` — the API: `render`, `render_file`, `list_templates`, `load_template`,
|
|
72
|
+
`render_template`, `render_template_blocks`
|
|
73
|
+
- `prompt_engineering/template_mixins.py` — the engine internals (add attributes/methods from data; run a sequence)
|
|
74
|
+
- `examples/` — single-block payloads for different **prompt block types** (system, persona, rules,
|
|
75
|
+
few-shot, constraints, output-format) and full personas — read these to learn the block format
|
|
76
|
+
- `templates/five_level/` — the 5-level model **as a prompt template** (an example, not a default)
|
|
77
|
+
- `templates/simple_agent/` — a one-block template (proves the add-by-folder mechanic)
|
|
78
|
+
- `prompt_engineering/cognition.py` — the cognition-chain stack (attention chain / chain-of-reasoning / skill chain) on
|
|
79
|
+
the engine, + `validate_chain` (a shallow no-dep broken-detector)
|
|
80
|
+
- `prompt_engineering/gate.py` — the REAL gate: `gate(text, exemplars)` LEARNS the grammar from exemplar chains (you don't
|
|
81
|
+
hand-write the error rules) → violations + fixes + the `orthogonal`/`syntax_break` (steerable/fatal) verdict
|
|
82
|
+
- **`rulecatcher`** — the grammar learner/linter the gate runs on; now an installed dependency (D3, un-vendored)
|
|
83
|
+
- `prompt_engineering/persona.py` — `make_persona(spec)` / `make_persona_file(path)`: generate a full persona prompt
|
|
84
|
+
(block types + a cognition DSL block) from a small spec
|
|
85
|
+
- `examples/persona_*.json` — example persona systems (debugger, socratic, code-reviewer) with reasoning DSLs
|
|
86
|
+
- `scripts/make_prompt.py` — render a block/template from the command line
|
|
87
|
+
- `scripts/make_persona.py` — generate a persona prompt from a spec file
|
|
88
|
+
- `scripts/new_template_skill.py` — scaffold a NEW skill package for a prompt template
|
|
89
|
+
- `test_prompt_engine.py` · `test_cognition.py` · `test_persona.py` · `test_gate.py` — run to verify (all NO-API)
|
|
90
|
+
|
|
91
|
+
## Cognition chains & personas (the ACCC/CORCC/SCCC stack, rebuilt right)
|
|
92
|
+
|
|
93
|
+
`prompt_engineering/cognition.py` is the clean version of the old `*CC` "compiler-compilers": an **attention chain**, a
|
|
94
|
+
**chain-of-reasoning**, and a **skill chain** are just prompt templates composed on this engine (a CoR
|
|
95
|
+
*nests* an AC = block-nesting). **Rendering never touches a grammar engine or a DB.**
|
|
96
|
+
|
|
97
|
+
The **gate is a separate, optional layer** (`prompt_engineering/gate.py`, on the **`rulecatcher`** package). You don't
|
|
98
|
+
hand-write the error rules: `gate(text, exemplars)` LEARNS the grammar from the template's exemplar chains
|
|
99
|
+
(`next_kind` = shape, `next_token` = vocabulary), then lints a candidate → violations + fixes + the
|
|
100
|
+
`orthogonal` (in the language, wrong slot → **steerable**) vs `syntax_break` (foreign → **fatal**) verdict.
|
|
101
|
+
`rulecatcher` is an installed dependency (D3), so the real gate runs everywhere it's installed.
|
|
102
|
+
(`validate_chain` remains a shallow no-dep fallback.)
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from prompt_engineering import render_cor, gate, make_persona
|
|
106
|
+
|
|
107
|
+
render_cor("Debugger", ["Symptom", "Repro", "Hypothesis"], "Localize", "the root cause") # a CoR persona
|
|
108
|
+
gate("[Goal] ⇒ [Repro] ⇒ |Localize|", # learn from exemplars, then lint:
|
|
109
|
+
exemplars=["[Symptom] ⇒ [Repro] ⇒ |Localize|", "[Symptom] ⇒ [Bisect] ⇒ |RootCause|"])
|
|
110
|
+
# → {ok: False, verdict: 'orthogonal', violations: [{found:'Goal', candidates:['Symptom'], ...}]}
|
|
111
|
+
|
|
112
|
+
make_persona({ # a whole persona with a complex reasoning DSL, in one call
|
|
113
|
+
"name": "Ada", "role": "a senior debugger",
|
|
114
|
+
"reasoning": {"foci": ["Symptom", "Repro", "Bisect"], "held": "RootCause", "decision": "the minimal fix"},
|
|
115
|
+
"rules": ["Reproduce before theorizing."], "output": "A markdown report.",
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Why deterministic matters
|
|
120
|
+
|
|
121
|
+
`render` runs the `template_sequence` in order and joins the non-empty results — pure composition, no
|
|
122
|
+
model call. That's what lets an agent rely on it to produce prompts consistently across runs.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
SKILL.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
agent_prompt_engineering.egg-info/PKG-INFO
|
|
4
|
+
agent_prompt_engineering.egg-info/SOURCES.txt
|
|
5
|
+
agent_prompt_engineering.egg-info/dependency_links.txt
|
|
6
|
+
agent_prompt_engineering.egg-info/requires.txt
|
|
7
|
+
agent_prompt_engineering.egg-info/top_level.txt
|
|
8
|
+
prompt_engineering/__init__.py
|
|
9
|
+
prompt_engineering/cognition.py
|
|
10
|
+
prompt_engineering/gate.py
|
|
11
|
+
prompt_engineering/grammar.py
|
|
12
|
+
prompt_engineering/persona.py
|
|
13
|
+
prompt_engineering/prompt_engine.py
|
|
14
|
+
prompt_engineering/skillpack.py
|
|
15
|
+
prompt_engineering/template_mixins.py
|
|
16
|
+
prompt_engineering/templates/five_level/agent.json
|
|
17
|
+
prompt_engineering/templates/five_level/deity.json
|
|
18
|
+
prompt_engineering/templates/five_level/egregore.json
|
|
19
|
+
prompt_engineering/templates/five_level/progenitor.json
|
|
20
|
+
prompt_engineering/templates/five_level/template.json
|
|
21
|
+
prompt_engineering/templates/five_level/world.json
|
|
22
|
+
prompt_engineering/templates/persona/output_format.json
|
|
23
|
+
prompt_engineering/templates/persona/persona.json
|
|
24
|
+
prompt_engineering/templates/persona/rules.json
|
|
25
|
+
prompt_engineering/templates/persona/system.json
|
|
26
|
+
prompt_engineering/templates/persona/template.json
|
|
27
|
+
prompt_engineering/templates/simple_agent/agent.json
|
|
28
|
+
prompt_engineering/templates/simple_agent/template.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prompt_engineering
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
prompt_engineering — the deterministic prompt-engine base.
|
|
3
|
+
|
|
4
|
+
THE shared foundation of the chaincompiler ecosystem (rule: everyone imports DOWN from here).
|
|
5
|
+
Three layers, all stdlib except the optional `rulecatcher` dep behind the gate:
|
|
6
|
+
- prompt_engine + template_mixins : data -> prompt, deterministic (same input -> same output)
|
|
7
|
+
- cognition : attention-chain / chain-of-reasoning / skill-chain as templates
|
|
8
|
+
- gate (optional) : learned-grammar lint on the `rulecatcher` package
|
|
9
|
+
|
|
10
|
+
P1 (see chaincompiler/REBUILD-SPEC.md) — now folded in so accc/corcc/sccc import DOWN from here:
|
|
11
|
+
- grammar : the rulecatcher seam (learn / gate / grammar_lines / foreign_tokens), PERSISTENT scope
|
|
12
|
+
- skillpack: write_skill / slugify / skill_markdown (D4: skilltree-aware placement is the next step)
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from .prompt_engine import (
|
|
16
|
+
Template,
|
|
17
|
+
build_template,
|
|
18
|
+
render,
|
|
19
|
+
render_file,
|
|
20
|
+
templates_root,
|
|
21
|
+
list_templates,
|
|
22
|
+
load_template,
|
|
23
|
+
render_template,
|
|
24
|
+
render_template_blocks,
|
|
25
|
+
)
|
|
26
|
+
from .template_mixins import TemplateAttributeMixin, TemplateMethodMixin
|
|
27
|
+
from .cognition import (
|
|
28
|
+
chain_notation,
|
|
29
|
+
parse_chain,
|
|
30
|
+
validate_chain,
|
|
31
|
+
attention_block_payload,
|
|
32
|
+
cor_skeleton,
|
|
33
|
+
cor_payload,
|
|
34
|
+
skillchain_payload,
|
|
35
|
+
render_attention_chain,
|
|
36
|
+
render_cor,
|
|
37
|
+
render_skillchain,
|
|
38
|
+
)
|
|
39
|
+
from .persona import make_persona, make_persona_file
|
|
40
|
+
from .gate import gate
|
|
41
|
+
# the rulecatcher seam (PERSISTENT, connection-based) — moved down from chaincompiler.bridge (§4).
|
|
42
|
+
# NOTE: the persistent gate(connection, chain, *, scope) is intentionally NOT re-exported at top level
|
|
43
|
+
# (it would clash with the ephemeral gate(text, exemplars) above) — use `prompt_engineering.grammar.gate`.
|
|
44
|
+
from .grammar import learn, grammar_lines, foreign_tokens
|
|
45
|
+
# the skill-packager — moved down from chaincompiler.skillpack (§7); skilltree-aware (D4).
|
|
46
|
+
from .skillpack import slugify, skill_markdown, write_skill, cohere_skills
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
# deterministic prompt engine
|
|
50
|
+
"Template", "build_template", "render", "render_file", "templates_root",
|
|
51
|
+
"list_templates", "load_template", "render_template", "render_template_blocks",
|
|
52
|
+
"TemplateAttributeMixin", "TemplateMethodMixin",
|
|
53
|
+
# cognition chains
|
|
54
|
+
"chain_notation", "parse_chain", "validate_chain",
|
|
55
|
+
"attention_block_payload", "cor_skeleton", "cor_payload", "skillchain_payload",
|
|
56
|
+
"render_attention_chain", "render_cor", "render_skillchain",
|
|
57
|
+
# personas
|
|
58
|
+
"make_persona", "make_persona_file",
|
|
59
|
+
# optional grammar gate (ephemeral) + the persistent rulecatcher seam (grammar.py)
|
|
60
|
+
"gate", "learn", "grammar_lines", "foreign_tokens",
|
|
61
|
+
# skill-packager (skilltree-aware, D4)
|
|
62
|
+
"slugify", "skill_markdown", "write_skill", "cohere_skills",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""
|
|
2
|
+
cognition.py — the cognition-chain stack (ACCC / CORCC / SCCC) rebuilt the RIGHT way, on the prompt engine.
|
|
3
|
+
|
|
4
|
+
The old *CC packages buried prompt-making under a grammar-induction-and-gating tower (rulecatcher `learn`
|
|
5
|
+
→ a SQLite DB → `gate`). The clean version:
|
|
6
|
+
|
|
7
|
+
- an attention chain (AC), a chain-of-reasoning (CoR), and a skill chain (SC) are PROMPT TEMPLATES —
|
|
8
|
+
authored blocks composed deterministically on prompt_engine (a CoR NESTS an AC = block-nesting).
|
|
9
|
+
- the validator (the "tells you when an instance is broken" part) is DERIVED FROM THE TEMPLATE: you
|
|
10
|
+
author the shape (+ optional vocabulary) once, and validate_chain() checks conformance directly.
|
|
11
|
+
No induction, no DB. That is the rule-learner's real intent — "make your DSL out of templates, and it
|
|
12
|
+
tells you when it's broken" — without the machinery.
|
|
13
|
+
|
|
14
|
+
attention chain [A] ⇒ [B] ⇒ |Held| inner "how to think" scaffold
|
|
15
|
+
chain of reasoning a CoR nests an AC + a spoken paragraph that ends in a DECISION
|
|
16
|
+
skill chain [ac:x] ⇒ [cor:y] ⇒ [skill:z] ⇒ |Goal| resolved steps, rolled up
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import re
|
|
20
|
+
from typing import List, Optional, Tuple
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from .prompt_engine import render
|
|
24
|
+
except ImportError:
|
|
25
|
+
from prompt_engine import render
|
|
26
|
+
|
|
27
|
+
ARROW = "⇒"
|
|
28
|
+
_FOCUS = re.compile(r"\[([^\]]+)\]")
|
|
29
|
+
_HELD = re.compile(r"\|([^|]+)\|")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# ── notation ───────────────────────────────────────────────────────────────
|
|
33
|
+
def chain_notation(foci: List[str], held: Optional[str] = None) -> str:
|
|
34
|
+
s = f" {ARROW} ".join(f"[{f}]" for f in foci)
|
|
35
|
+
if held:
|
|
36
|
+
s += f" {ARROW} |{held}|"
|
|
37
|
+
return s
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_chain(text: str) -> Tuple[List[str], Optional[str]]:
|
|
41
|
+
foci = [m.group(1).strip() for m in _FOCUS.finditer(text)]
|
|
42
|
+
held = _HELD.search(text)
|
|
43
|
+
return foci, (held.group(1).strip() if held else None)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ── the validator: DERIVED FROM THE TEMPLATE (no induction, no DB) ──────────
|
|
47
|
+
def validate_chain(text: str, *, vocab: Optional[List[str]] = None,
|
|
48
|
+
require_held: bool = True, min_foci: int = 1) -> Tuple[bool, List[str]]:
|
|
49
|
+
"""The broken-detector. The template's shape (+ optional authored vocabulary) IS the grammar; this
|
|
50
|
+
checks conformance deterministically. Returns (ok, errors)."""
|
|
51
|
+
errors: List[str] = []
|
|
52
|
+
foci, held = parse_chain(text)
|
|
53
|
+
if len(foci) < min_foci:
|
|
54
|
+
errors.append(f"need >= {min_foci} focus block(s) [X]; found {len(foci)}")
|
|
55
|
+
if require_held and not held:
|
|
56
|
+
errors.append("missing terminal |Held| focus")
|
|
57
|
+
if vocab is not None:
|
|
58
|
+
allowed = set(vocab)
|
|
59
|
+
for f in foci:
|
|
60
|
+
if f not in allowed:
|
|
61
|
+
errors.append(f"focus '{f}' not in authored vocabulary {sorted(allowed)}")
|
|
62
|
+
if held and held not in allowed:
|
|
63
|
+
errors.append(f"held '{held}' not in authored vocabulary {sorted(allowed)}")
|
|
64
|
+
expected_arrows = max(0, len(foci) - 1) + (1 if held else 0)
|
|
65
|
+
if (foci or held) and text.count(ARROW) != expected_arrows:
|
|
66
|
+
errors.append(f"arrow count {text.count(ARROW)} != expected {expected_arrows} (malformed chain)")
|
|
67
|
+
return (not errors), errors
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ── builders: AC / CoR / SC as prompt_engine payloads (composed on the primitive) ──────────────────
|
|
71
|
+
def attention_block_payload(foci: List[str], held: Optional[str] = None) -> dict:
|
|
72
|
+
"""An attention chain as a block payload (the inner 'how to think' scaffold)."""
|
|
73
|
+
return {
|
|
74
|
+
"values": {"chain": chain_notation(foci, held), "foci_csv": ", ".join(foci), "held": held or ""},
|
|
75
|
+
"methods": [
|
|
76
|
+
{"name": "format_head", "func": "return 'This is an ATTENTION CHAIN — an inner template for how to think (a scaffold for a section or your reasoning). Not necessarily spoken.'", "add_to_sequence": True},
|
|
77
|
+
{"name": "format_chain", "func": "return '## Chain\\n```rune\\n' + self.chain + '\\n```'", "add_to_sequence": True},
|
|
78
|
+
{"name": "format_how", "func": "return 'Attend, in order, to: ' + self.foci_csv + (' — then hold |' + self.held + '|.' if self.held else '.')", "add_to_sequence": True},
|
|
79
|
+
],
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def cor_skeleton(moves: List[str], cues: Optional[dict] = None) -> str:
|
|
84
|
+
"""The CORCC fill-in paragraph skeleton: `[move: …cue…] → …` (one clause per move). `cues` maps a
|
|
85
|
+
move name to its cue phrase (defaults to the move name). The SINGLE source of the skeleton format —
|
|
86
|
+
corcc renders through this (§5 convergence)."""
|
|
87
|
+
cue_for = cues or {}
|
|
88
|
+
return " → ".join(f"[{m}: …{cue_for.get(m, m)}…]" for m in moves)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def cor_payload(name: str, foci: List[str], held: str, decision: str,
|
|
92
|
+
cues: Optional[dict] = None) -> dict:
|
|
93
|
+
"""A chain-of-reasoning persona. NESTS the attention chain (renders it on the primitive, embeds it)
|
|
94
|
+
= the CORCC-embeds-ACCC composition, done as block-nesting.
|
|
95
|
+
|
|
96
|
+
§5 feature parity (ported from corcc.paragraph): if `cues` is given — a phrase per move, either a
|
|
97
|
+
list aligned to `foci + [held]` or a `{move: cue}` dict — the payload ALSO renders the CORCC fill-in
|
|
98
|
+
SKELETON (`[move: …cue…] → …`) and a must-say directive, so a move only 'counts' when its cue phrase
|
|
99
|
+
surfaces. `cues=None` keeps the original behavior exactly (the skeleton/directive blocks render empty
|
|
100
|
+
and the engine drops them)."""
|
|
101
|
+
inner = render(attention_block_payload(foci, held)) # nest: render the AC, embed as a value
|
|
102
|
+
moves = list(foci) + [held]
|
|
103
|
+
skeleton = directive = ""
|
|
104
|
+
if cues:
|
|
105
|
+
cue_for = cues if isinstance(cues, dict) else dict(zip(moves, cues))
|
|
106
|
+
skeleton = cor_skeleton(moves, cue_for)
|
|
107
|
+
directive = (f"Say ONE paragraph that, in order, works {len(foci)} moves "
|
|
108
|
+
f"({', '.join(foci)}) and converges on {held}; surface each move's cue.")
|
|
109
|
+
return {
|
|
110
|
+
"values": {"name": name, "chain": chain_notation(foci, held), "decision": decision,
|
|
111
|
+
"inner": inner, "skeleton": skeleton, "directive": directive},
|
|
112
|
+
"methods": [
|
|
113
|
+
{"name": "format_head", "func": "return f'# Persona: {self.name}'", "add_to_sequence": True},
|
|
114
|
+
{"name": "format_outer", "func": "return '## Chain of reasoning (SAY this — a paragraph that ends in a decision)\\n```rune\\n' + self.chain + '\\n```\\nWork the moves in order; converge on: ' + self.decision + '.'", "add_to_sequence": True},
|
|
115
|
+
{"name": "format_skeleton", "func": "return ('## Say it like this (fill in each cue)\\n' + self.skeleton) if self.skeleton else ''", "add_to_sequence": True},
|
|
116
|
+
{"name": "format_directive", "func": "return self.directive if self.directive else ''", "add_to_sequence": True},
|
|
117
|
+
{"name": "format_inner", "func": "return '## Inner attention chain (use silently to generate the above)\\n' + self.inner", "add_to_sequence": True},
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def skillchain_payload(steps: List[Tuple[str, str]], goal: str) -> dict:
|
|
123
|
+
"""A skill chain: ordered [kind:ref] steps (ac|cor|skill) converging on a goal."""
|
|
124
|
+
steps_md = "\n".join(f"{i}. [{kind}:{ref}]" for i, (kind, ref) in enumerate(steps, 1))
|
|
125
|
+
return {
|
|
126
|
+
"values": {"goal": goal, "steps_md": steps_md},
|
|
127
|
+
"methods": [
|
|
128
|
+
{"name": "format_head", "func": "return 'This is a SKILL CHAIN — resolve each step in order, then converge on the goal.'", "add_to_sequence": True},
|
|
129
|
+
{"name": "format_steps", "func": "return '## Steps\\n' + self.steps_md", "add_to_sequence": True},
|
|
130
|
+
{"name": "format_goal", "func": "return '## Goal\\n|' + self.goal + '|'", "add_to_sequence": True},
|
|
131
|
+
],
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def render_attention_chain(foci, held=None):
|
|
136
|
+
return render(attention_block_payload(foci, held))
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def render_cor(name, foci, held, decision, cues=None):
|
|
140
|
+
return render(cor_payload(name, foci, held, decision, cues=cues))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def render_skillchain(steps, goal):
|
|
144
|
+
return render(skillchain_payload(steps, goal))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
__all__ = ["chain_notation", "parse_chain", "validate_chain",
|
|
148
|
+
"attention_block_payload", "cor_payload", "skillchain_payload",
|
|
149
|
+
"render_attention_chain", "render_cor", "render_skillchain", "ARROW"]
|