deepclause-sdk 0.3.0 → 0.6.0
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.
- package/README.md +148 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +154 -28
- package/dist/agent.js.map +1 -1
- package/dist/cli/config.d.ts +150 -140
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +3 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/login.d.ts +2 -1
- package/dist/cli/login.d.ts.map +1 -1
- package/dist/cli/login.js +15 -2
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/repl.d.ts +54 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +467 -53
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -0
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/set-backend.d.ts +2 -2
- package/dist/cli/set-backend.d.ts.map +1 -1
- package/dist/cli/set-backend.js +54 -8
- package/dist/cli/set-backend.js.map +1 -1
- package/dist/cli/work.d.ts +16 -0
- package/dist/cli/work.d.ts.map +1 -0
- package/dist/cli/work.js +45 -0
- package/dist/cli/work.js.map +1 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/prolog-src/deepclause_mi.pl +2596 -268
- package/dist/prolog-src/deepclause_strings.pl +36 -3
- package/dist/repl/agent.d.ts +12 -0
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +40 -16
- package/dist/repl/agent.js.map +1 -1
- package/dist/repl/auth.d.ts +6 -3
- package/dist/repl/auth.d.ts.map +1 -1
- package/dist/repl/auth.js +55 -5
- package/dist/repl/auth.js.map +1 -1
- package/dist/repl/backend.d.ts +24 -0
- package/dist/repl/backend.d.ts.map +1 -1
- package/dist/repl/backend.js +292 -12
- package/dist/repl/backend.js.map +1 -1
- package/dist/repl/compaction.d.ts +2 -0
- package/dist/repl/compaction.d.ts.map +1 -1
- package/dist/repl/compaction.js +9 -0
- package/dist/repl/compaction.js.map +1 -1
- package/dist/repl/event-history.d.ts +4 -0
- package/dist/repl/event-history.d.ts.map +1 -0
- package/dist/repl/event-history.js +33 -0
- package/dist/repl/event-history.js.map +1 -0
- package/dist/repl/harness-tools.d.ts +26 -18
- package/dist/repl/harness-tools.d.ts.map +1 -1
- package/dist/repl/harness-tools.js +103 -34
- package/dist/repl/harness-tools.js.map +1 -1
- package/dist/repl/history.d.ts +75 -3
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +155 -4
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +33 -5
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +30 -0
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/reference.d.ts +31 -0
- package/dist/repl/reference.d.ts.map +1 -0
- package/dist/repl/reference.js +143 -0
- package/dist/repl/reference.js.map +1 -0
- package/dist/repl/render.d.ts +3 -1
- package/dist/repl/render.d.ts.map +1 -1
- package/dist/repl/render.js +17 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +166 -23
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +980 -188
- package/dist/repl/session.js.map +1 -1
- package/dist/repl/tui/autocomplete.d.ts.map +1 -1
- package/dist/repl/tui/autocomplete.js +5 -1
- package/dist/repl/tui/autocomplete.js.map +1 -1
- package/dist/repl/tui/renderer.d.ts +2 -1
- package/dist/repl/tui/renderer.d.ts.map +1 -1
- package/dist/repl/tui/renderer.js +20 -3
- package/dist/repl/tui/renderer.js.map +1 -1
- package/dist/repl/tui/status-bar.d.ts +5 -2
- package/dist/repl/tui/status-bar.d.ts.map +1 -1
- package/dist/repl/tui/status-bar.js +8 -3
- package/dist/repl/tui/status-bar.js.map +1 -1
- package/dist/repl/tui/tool-pane.d.ts +1 -1
- package/dist/repl/tui/tool-pane.d.ts.map +1 -1
- package/dist/repl/tui/tool-pane.js +13 -7
- package/dist/repl/tui/tool-pane.js.map +1 -1
- package/dist/repl/tui/work-view.d.ts +10 -0
- package/dist/repl/tui/work-view.d.ts.map +1 -0
- package/dist/repl/tui/work-view.js +28 -0
- package/dist/repl/tui/work-view.js.map +1 -0
- package/dist/runner.d.ts +7 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +81 -23
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +10 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +265 -2943
- package/dist/system/assets/docs/DML_AUTHORING.md +81 -295
- package/dist/system/assets/docs/DML_BASICS.md +93 -0
- package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
- package/dist/system/assets/docs/DML_FORMS.md +94 -728
- package/dist/system/assets/docs/DML_MEDIA.md +63 -0
- package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
- package/dist/system/assets/docs/DML_PYTHON.md +74 -0
- package/dist/system/assets/docs/DML_REFERENCE.md +224 -1912
- package/dist/system/assets/docs/DML_SHELL.md +107 -0
- package/dist/system/assets/docs/DML_TASKS.md +112 -0
- package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
- package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
- package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
- package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
- package/dist/system/assets/index.d.ts +1 -1
- package/dist/system/assets/index.d.ts.map +1 -1
- package/dist/system/assets/index.js +7 -0
- package/dist/system/assets/index.js.map +1 -1
- package/dist/system/environment.d.ts +1 -1
- package/dist/system/environment.d.ts.map +1 -1
- package/dist/system/environment.js +10 -6
- package/dist/system/environment.js.map +1 -1
- package/dist/system/runtime/shell-manager.d.ts +1 -1
- package/dist/system/runtime/shell-manager.d.ts.map +1 -1
- package/dist/types.d.ts +62 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/work/index.d.ts +82 -0
- package/dist/work/index.d.ts.map +1 -0
- package/dist/work/index.js +232 -0
- package/dist/work/index.js.map +1 -0
- package/package.json +12 -3
- package/src/prolog-src/deepclause_mi.pl +2596 -268
- package/src/prolog-src/deepclause_strings.pl +36 -3
|
@@ -1,266 +1,342 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Runnable canonical examples
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Generated from scripts/canonical-examples.mjs; do not hand-copy into the system prompt.
|
|
4
|
+
Pick ONE matching section. Each skill binds its outputs; agent_main is only used
|
|
5
|
+
for the explicitly custom conversation. Host-dependent examples list prerequisites.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
with thin guards between them. §4–§7 (facts, pure logic, judgments, CLP) are the
|
|
8
|
-
exception — reach for them only when the task is genuinely data- or
|
|
9
|
-
logic-shaped, not as the default style. DML is the orchestration layer over model
|
|
10
|
-
calls, not the logic library (`DML_AUTHORING.md` §0). For file work, shell out
|
|
11
|
-
(`exec(bash(...))`) instead of reading files into DML (§2).
|
|
7
|
+
## work-agent
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
with an empty body). Keep both terse.
|
|
9
|
+
**Default Work agent with a tool and workflow**
|
|
10
|
+
|
|
11
|
+
The default conversation is supplied by shell/1. A custom persona does not need a DML chat loop. Inputs precede outputs; tools are not directly run from the sidebar.
|
|
12
|
+
|
|
13
|
+
Requires: Work host; title workflow requires a text model. The character-count test is pure DML.
|
|
19
14
|
|
|
20
15
|
```prolog
|
|
21
|
-
|
|
16
|
+
length_of(Text, N) :- string_length(Text, N).
|
|
17
|
+
title(Text, Label) :- prompt("Give a short title for: {Text}", string(Label)).
|
|
18
|
+
shell(_{
|
|
19
|
+
kind: agent, system: "You are a concise writing assistant.", host_tools: [],
|
|
20
|
+
tools: [_{name: "text_length", goal: "length_of", description: "Count characters.",
|
|
21
|
+
inputs: [_{name: "Text", type: string}], outputs: [_{name: "N", type: integer}]}],
|
|
22
|
+
workflows: [_{name: "Create title", goal: "title",
|
|
23
|
+
inputs: [_{name: "Text", type: string}], outputs: [_{name: "Label", type: string}]}],
|
|
24
|
+
welcome: "Ask about text, or create a title."
|
|
25
|
+
}).
|
|
22
26
|
```
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
Test goal: `length_of("Ada", N), write(N)`. Expected: `3`.
|
|
29
|
+
|
|
30
|
+
Failure/cancel check: Do not replace output binding with answer/1 or add a custom conversation loop.
|
|
31
|
+
|
|
32
|
+
## basic-relation
|
|
33
|
+
|
|
34
|
+
**Arguments, arithmetic and a deterministic branch**
|
|
35
|
+
|
|
36
|
+
N is an input; Label is an output. is/2 evaluates arithmetic, = binds a returned value. A failed input guard is not an exception.
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
`make_directory_path("scripts"), write_file("scripts/count_words.py", "…")`),
|
|
28
|
-
link it with `script_file/2`, and define a predicate for it. `tool/2` is only an
|
|
29
|
-
annotation that exposes an existing predicate to `task/N`; keep it a one-line
|
|
30
|
-
delegation so the predicate is also callable from `execute` / `/goal`:
|
|
38
|
+
Requires: No host tools or model.
|
|
31
39
|
|
|
32
40
|
```prolog
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
script_file(count_words, Script),
|
|
38
|
-
format(atom(Cmd), "python3 '~w' '~w'", [Script, File]),
|
|
39
|
-
exec(bash(command: Cmd), Result),
|
|
40
|
-
get_dict(stdout, Result, Count).
|
|
41
|
-
|
|
42
|
-
% The annotation exposing it to the nested agent (delegation only).
|
|
43
|
-
tool(count_words(File, Count), "Count words in a workspace file.") :-
|
|
44
|
-
count_words(File, Count).
|
|
41
|
+
size_label(N, Label) :-
|
|
42
|
+
integer(N), N >= 0,
|
|
43
|
+
Twice is N * 2,
|
|
44
|
+
( Twice > 10 -> Label = large ; Label = small ).
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
command. `script_file/2` is just a fact (the exporter bundles the file); the
|
|
49
|
-
write lands on disk immediately, so `bash` can run the script in the same turn.
|
|
47
|
+
Test goal: `size_label(2, Label), write(Label)`. Expected: `small`.
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
Failure/cancel check: size_label(-1, _) has zero solutions; catch/3 does not catch a false guard.
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
## typed-pipeline
|
|
52
|
+
|
|
53
|
+
**Fresh typed transformation and explicit data flow**
|
|
54
|
+
|
|
55
|
+
Each prompt includes its input. No tool or previous-memory dependency. Reject empty intermediate data before the next semantic step.
|
|
56
|
+
|
|
57
|
+
Requires: Text model; tests supply deterministic typed completions.
|
|
55
58
|
|
|
56
59
|
```prolog
|
|
57
|
-
|
|
60
|
+
brief(Text, Report) :-
|
|
61
|
+
prompt("Extract the central claim from: {Text}", string(Claim)),
|
|
62
|
+
Claim \== "",
|
|
63
|
+
prompt("Explain this claim using only the source {Text}: {Claim}", string(Report)).
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Test goal: `brief("A source document", Report), write(Report)`. Expected: `A grounded summary.`.
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
task("Route this support message to exactly one of billing, orders, or account. Message: {Message}. Store the choice in Team.", Team).
|
|
68
|
+
Failure/cancel check: An empty Claim fails before generating a report.
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
## task-tools
|
|
71
|
+
|
|
72
|
+
**A scoped task calls one declared capability**
|
|
73
|
+
|
|
74
|
+
Host tools, nested tool/N annotations and shell tools are different surfaces. This task may only call length_of; the real predicate remains callable directly.
|
|
75
|
+
|
|
76
|
+
Requires: Text model with tool calling; test checks the capability really executes.
|
|
77
|
+
|
|
78
|
+
```prolog
|
|
79
|
+
length_of(Text, N) :- string_length(Text, N).
|
|
80
|
+
tool(length_of(Text, N), "Count characters.", [string]) :- length_of(Text, N).
|
|
81
|
+
inspect(Text, Reply) :-
|
|
82
|
+
with_tools([length_of], task("Call length_of for {Text}; report the observed count.", string(Reply))).
|
|
66
83
|
```
|
|
67
84
|
|
|
68
|
-
|
|
85
|
+
Test goal: `inspect("Ada", Reply), write(Reply)`. Expected: `3 characters`.
|
|
86
|
+
|
|
87
|
+
Failure/cancel check: Naming length_of in prose without registering its annotation would not expose it.
|
|
88
|
+
|
|
89
|
+
## task-memory
|
|
90
|
+
|
|
91
|
+
**Task memory accumulates; a fresh prompt does not inherit it**
|
|
92
|
+
|
|
93
|
+
Task memory is DML harness memory, not the authoring chat. The tasks share a fresh group, then a separate prompt receives only explicitly supplied data.
|
|
94
|
+
|
|
95
|
+
Requires: Text model; tests inspect actual request memory, not only returned strings.
|
|
69
96
|
|
|
70
97
|
```prolog
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
memory_demo(Out) :-
|
|
99
|
+
with_fresh_memory(with_tools([], (
|
|
100
|
+
task("Return marker alpha.", string(First)),
|
|
101
|
+
task("Report the earlier marker. Explicit value: {First}", string(Second))
|
|
102
|
+
))),
|
|
103
|
+
prompt("Report only this explicit result: {Second}", string(Out)).
|
|
76
104
|
```
|
|
77
105
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
106
|
+
Test goal: `memory_demo(Out), write(Out)`. Expected: `Memory scopes checked.`.
|
|
107
|
+
|
|
108
|
+
Failure/cancel check: Do not assume a prompt sees a prior task or a nested tool inherits the Work transcript.
|
|
109
|
+
|
|
110
|
+
## judgment-routing
|
|
111
|
+
|
|
112
|
+
**A constrained semantic choice with explicit evidence**
|
|
113
|
+
|
|
114
|
+
Choose returns one option atom; deterministic branching follows it. A semantic judgment is not proof that an external action was performed.
|
|
115
|
+
|
|
116
|
+
Requires: Configured judgment backend (the test uses the session model with a deterministic judge response).
|
|
81
117
|
|
|
82
118
|
```prolog
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(
|
|
86
|
-
->
|
|
87
|
-
;
|
|
119
|
+
route(Message, Team) :-
|
|
120
|
+
choose(Message, "Which team handles this?", [billing, orders, account], Choice),
|
|
121
|
+
( Choice == billing -> Team = billing
|
|
122
|
+
; Choice == orders -> Team = orders
|
|
123
|
+
; Team = account
|
|
88
124
|
).
|
|
89
125
|
```
|
|
90
126
|
|
|
91
|
-
|
|
127
|
+
Test goal: `route("I was charged twice", Team), write(Team)`. Expected: `billing`.
|
|
92
128
|
|
|
93
|
-
|
|
129
|
+
Failure/cancel check: Unknown evidence is not a reason to claim that a real refund happened.
|
|
130
|
+
|
|
131
|
+
## schema-output
|
|
132
|
+
|
|
133
|
+
**A declared schema rather than guessed dict keys**
|
|
134
|
+
|
|
135
|
+
The schema is an output contract, not merely a suggested JSON shape. Missing required fields and invalid types fail validation.
|
|
136
|
+
|
|
137
|
+
Requires: Text model; deterministic schema-aware test output.
|
|
94
138
|
|
|
95
139
|
```prolog
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
140
|
+
schema(person, [field(name, string, required), field(age, integer, default(0))]).
|
|
141
|
+
extract_person(Text, Person) :-
|
|
142
|
+
prompt("Extract a person from: {Text}", schema(person, Person)).
|
|
143
|
+
```
|
|
100
144
|
|
|
101
|
-
|
|
145
|
+
Test goal: `extract_person("Ada, age 36", Person), get_dict(name, Person, Name), write(Name)`. Expected: `Ada`.
|
|
102
146
|
|
|
103
|
-
|
|
104
|
-
|
|
147
|
+
Failure/cancel check: Missing name must not be silently converted to an empty string.
|
|
148
|
+
|
|
149
|
+
## python-files
|
|
150
|
+
|
|
151
|
+
**Python, files and argv**
|
|
152
|
+
|
|
153
|
+
Write/link the helper during authoring, not on each run. Script link normalise_py is distinct from the normalise/2 predicate. run_script checks exit status and parses JSON.
|
|
154
|
+
|
|
155
|
+
Requires: Python host capability (or a compatible script execution embedding). Files below are fixtures to create before calling the skill.
|
|
156
|
+
|
|
157
|
+
```prolog
|
|
158
|
+
script_file(normalise_py, "scripts/normalise.py").
|
|
159
|
+
normalise(Path, Text) :-
|
|
160
|
+
run_script(normalise_py, [Path], Data),
|
|
161
|
+
get_dict(text, Data, Text).
|
|
105
162
|
```
|
|
106
163
|
|
|
164
|
+
Test goal: `normalise("canonical/input.txt", Text), write(Text)`. Expected: `HELLO`.
|
|
165
|
+
|
|
166
|
+
Failure/cancel check: A missing input file produces a script_failed error; no model fills the missing text.
|
|
167
|
+
|
|
168
|
+
Fixture `canonical/input.txt` (create before run):
|
|
169
|
+
|
|
107
170
|
```text
|
|
108
|
-
|
|
109
|
-
X = bob ; X = carol ; X = dave ; X = eve
|
|
171
|
+
hello
|
|
110
172
|
```
|
|
111
173
|
|
|
112
|
-
|
|
174
|
+
Fixture `scripts/normalise.py` (create before run):
|
|
113
175
|
|
|
114
|
-
```
|
|
115
|
-
|
|
176
|
+
```python
|
|
177
|
+
import json, sys
|
|
178
|
+
from pathlib import Path
|
|
179
|
+
print(json.dumps({'text': Path(sys.argv[1]).read_text().upper()}))
|
|
180
|
+
```
|
|
116
181
|
|
|
117
|
-
|
|
118
|
-
list_to_set(List, Items),
|
|
119
|
-
findall(Item-N, (member(Item, Items), aggregate_all(count, member(Item, List), N)), Counts).
|
|
182
|
+
## swarm
|
|
120
183
|
|
|
121
|
-
|
|
122
|
-
tally([a,b,a,c,a], C),
|
|
123
|
-
C == [a-3, b-1, c-1].
|
|
124
|
-
```
|
|
184
|
+
**Bounded parallel mapping with visible failures**
|
|
125
185
|
|
|
126
|
-
|
|
127
|
-
update or add its test and run it (`execute` during a turn, or `/goal`).
|
|
186
|
+
Results preserve input order. Every item has its own process; failed items remain visible. Use pmap only if any failure should fail the whole batch.
|
|
128
187
|
|
|
129
|
-
|
|
188
|
+
Requires: Process-capable session; no model.
|
|
130
189
|
|
|
131
190
|
```prolog
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
urgent(Message) :-
|
|
136
|
-
holds(Message, "Is this urgent?").
|
|
191
|
+
double(N, R) :- R is N * 2.
|
|
192
|
+
parallel_values(Items, Results) :- swarm(double, Items, Results, 2).
|
|
137
193
|
```
|
|
138
194
|
|
|
139
|
-
|
|
140
|
-
|
|
195
|
+
Test goal: `parallel_values([1,2,3], Results), write(Results)`. Expected: `[ok(2),ok(4),ok(6)]`.
|
|
196
|
+
|
|
197
|
+
Failure/cancel check: Inspect failed items rather than assuming all results succeeded.
|
|
198
|
+
|
|
199
|
+
## spawn-python
|
|
141
200
|
|
|
142
|
-
|
|
201
|
+
**Spawn a worker and return by message**
|
|
202
|
+
|
|
203
|
+
Create required files before spawn. Child output variables do not bind the parent; send a result, receive it with a bound, then reap the worker.
|
|
204
|
+
|
|
205
|
+
Requires: Python and process host. Test fixture canonical/input.txt exists before spawn.
|
|
143
206
|
|
|
144
207
|
```prolog
|
|
145
|
-
|
|
208
|
+
read_in_worker(Path, Out) :-
|
|
209
|
+
self(Me), spawn(file_worker(Path, Me), Pid),
|
|
210
|
+
receive(done(Out), 30000), wait(Pid, _).
|
|
211
|
+
file_worker(Path, Parent) :-
|
|
212
|
+
exec(python(code: "from pathlib import Path\nimport sys\nprint(Path(sys.argv[1]).read_text().upper())", argv: [Path]), R),
|
|
213
|
+
get_dict(exitCode, R, 0), get_dict(stdout, R, Out),
|
|
214
|
+
send(Parent, done(Out)).
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Test goal: `read_in_worker("canonical/input.txt", Out), write(Out)`. Expected: `HELLO`.
|
|
218
|
+
|
|
219
|
+
Failure/cancel check: A failed worker may never send; the receive is bounded. Inspect the worker and stop/reap it after a timeout.
|
|
146
220
|
|
|
147
|
-
|
|
221
|
+
Fixture `canonical/input.txt` (create before run):
|
|
148
222
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
X + Y #= Total,
|
|
152
|
-
X #< Y,
|
|
153
|
-
label([X, Y]).
|
|
223
|
+
```text
|
|
224
|
+
hello
|
|
154
225
|
```
|
|
155
226
|
|
|
156
|
-
|
|
157
|
-
|
|
227
|
+
## service
|
|
228
|
+
|
|
229
|
+
**A stateful service with correlated replies**
|
|
230
|
+
|
|
231
|
+
A service is for message-driven state, not a single model call. Registered names survive across turns while the process is alive. Stop/reap test services.
|
|
158
232
|
|
|
159
|
-
|
|
233
|
+
Requires: Process-capable session.
|
|
160
234
|
|
|
161
235
|
```prolog
|
|
162
|
-
|
|
236
|
+
service_demo(Text) :-
|
|
237
|
+
serve(counter, counter_loop(0), Pid),
|
|
238
|
+
service_call(counter, bump, First, 5000),
|
|
239
|
+
service_call(counter, bump, Second, 5000),
|
|
240
|
+
service_call(counter, read, Final, 5000),
|
|
241
|
+
service_cast(counter, stop), wait(Pid, _),
|
|
242
|
+
format(string(Text), "~w ~w ~w", [First, Second, Final]).
|
|
243
|
+
counter_loop(Count) :-
|
|
244
|
+
receive(Msg),
|
|
245
|
+
( Msg = request(From, Ref, read)
|
|
246
|
+
-> send(From, reply(Ref, Count)), counter_loop(Count)
|
|
247
|
+
; Msg = request(From, Ref, bump)
|
|
248
|
+
-> Next is Count + 1, send(From, reply(Ref, Next)), counter_loop(Next)
|
|
249
|
+
; Msg = stop -> true
|
|
250
|
+
; counter_loop(Count)
|
|
251
|
+
).
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Test goal: `service_demo(Text), write(Text)`. Expected: `1 2 2`.
|
|
255
|
+
|
|
256
|
+
Failure/cancel check: Duplicate service names are rejected; callers use bounded service_call timeouts.
|
|
257
|
+
|
|
258
|
+
## vision
|
|
259
|
+
|
|
260
|
+
**Vision input is not display or generation**
|
|
261
|
+
|
|
262
|
+
Attach a workspace reference, then use a vision task. A fresh prompt does not read the attached image. Display is a separate output operation.
|
|
163
263
|
|
|
264
|
+
Requires: Vision-capable model and supported image file; tests provide a tiny PNG and assert media is actually in the model request.
|
|
265
|
+
|
|
266
|
+
```prolog
|
|
164
267
|
describe_image(Path, Text) :-
|
|
165
|
-
read_media(Path, Image),
|
|
166
|
-
|
|
167
|
-
|
|
268
|
+
read_media(Path, Image), attach_media(Image),
|
|
269
|
+
with_tools([], task("Describe only the attached image.", string(Text))).
|
|
270
|
+
show_image_file(Path) :- output(media(Path)).
|
|
168
271
|
```
|
|
169
272
|
|
|
170
|
-
|
|
171
|
-
the workspace at call time, only PNG/JPEG/GIF/WebP are accepted, and they never
|
|
172
|
-
enter clauses or memory. Judgments stay text-only.
|
|
273
|
+
Test goal: `describe_image("canonical/pixel.png", Text), write(Text)`. Expected: `An observed image.`.
|
|
173
274
|
|
|
174
|
-
|
|
275
|
+
Failure/cancel check: A text-only model cannot analyse pixels. Image generation additionally needs a configured image backend.
|
|
175
276
|
|
|
176
|
-
|
|
177
|
-
text. Forms are always available — no directive, nothing to import.
|
|
277
|
+
Binary fixture: provide a valid supported image before running (test suite includes one).
|
|
178
278
|
|
|
179
|
-
|
|
180
|
-
form tools and describe what you need:
|
|
279
|
+
## fixed-form
|
|
181
280
|
|
|
182
|
-
|
|
183
|
-
|
|
281
|
+
**Fixed foreground form with a cancellation branch**
|
|
282
|
+
|
|
283
|
+
Known fields need no model. The host enforces hard validation; a refused submit is not delivered. Never save on cancel or unavailable.
|
|
284
|
+
|
|
285
|
+
Requires: Foreground form host. Browser disposable execute/process workers do not render forms.
|
|
184
286
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
287
|
+
```prolog
|
|
288
|
+
claim_form(Values) :-
|
|
289
|
+
form(_{title: "Quick check-in", fields: [_{name: name, type: string, required: true}]}, F),
|
|
290
|
+
await_form(F, Change), close_form(F),
|
|
291
|
+
( Change.action == submit -> Change.values = Values ; Values = _{} ).
|
|
190
292
|
```
|
|
191
293
|
|
|
192
|
-
|
|
193
|
-
`wait_for_form_change(formId)` → `{action, values}`, `close_form(formId)`.
|
|
294
|
+
Test goal: `claim_form(V), get_dict(name, V, Name), format(string(S), "Hello ~w", [Name]), write(S)`. Expected: `Hello Ada`.
|
|
194
295
|
|
|
195
|
-
|
|
296
|
+
Failure/cancel check: Cancel/unavailable returns an empty dict; a caller must not create a record from it.
|
|
196
297
|
|
|
197
|
-
|
|
198
|
-
doc(claim_form/1, "Collect an expense claim. claim_form(-Values) returns the entered values.").
|
|
298
|
+
## dynamic-form
|
|
199
299
|
|
|
200
|
-
|
|
201
|
-
form(_{ title: "New expense claim",
|
|
202
|
-
fields: [ _{name: vendor, type: string, required: true},
|
|
203
|
-
_{name: amount, type: integer, required: true, minimum: 0},
|
|
204
|
-
_{name: notes, widget: textarea} ] }, F),
|
|
205
|
-
await_form(F, Change),
|
|
206
|
-
close_form(F),
|
|
207
|
-
( Change.action == submit % an atom: submit, cancel
|
|
208
|
-
-> Change.values = Values
|
|
209
|
-
; Values = _{}
|
|
210
|
-
).
|
|
300
|
+
**Context-dependent fields designed by a scoped task**
|
|
211
301
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
302
|
+
The nested model designs the form, waits for actual values and closes it. Result/finish machinery is internal, not a user tool annotation.
|
|
303
|
+
|
|
304
|
+
Requires: Foreground form host and text model with tools.
|
|
305
|
+
|
|
306
|
+
```prolog
|
|
307
|
+
collect_details(Context, Summary) :-
|
|
308
|
+
with_tools([render_form, wait_for_form_change, close_form],
|
|
309
|
+
task("Collect {Context} using a form, wait for the user action, close the form, and report only what they entered.", string(Summary))).
|
|
218
310
|
```
|
|
219
311
|
|
|
220
|
-
|
|
221
|
-
branch. A field's `type` defaults to `string`, and the host owns validation.
|
|
222
|
-
`Change.action` is an **atom** (`submit`, `cancel`) — compare with `==`, never
|
|
223
|
-
against `"submit"`. `current_predicate(form/2)` reports `no` even when forms work
|
|
224
|
-
(it is a host handler, like `exec/2`). See `reference("forms")` and
|
|
225
|
-
`sdk-examples/forms.dml`.
|
|
312
|
+
Test goal: `collect_details("name and favorite color", Summary), write(Summary)`. Expected: `Ada likes blue.`.
|
|
226
313
|
|
|
227
|
-
|
|
314
|
+
Failure/cancel check: A form rendered without a real submission is not evidence that intake completed.
|
|
228
315
|
|
|
229
|
-
|
|
230
|
-
primitives: `input/1` (the next message, no prompt) and `chat/1` (one traditional
|
|
231
|
-
agent turn — tools, no `finish`, no nudging; it ends when the model stops calling
|
|
232
|
-
tools). Run it as the foreground goal, not inside `execute`.
|
|
316
|
+
## custom-intake
|
|
233
317
|
|
|
234
|
-
|
|
235
|
-
doc(agent_main/0, "Chat assistant that can add. Run with /goal agent_main.").
|
|
318
|
+
**Custom staged conversation (advanced, not the default)**
|
|
236
319
|
|
|
237
|
-
|
|
238
|
-
system("You are a concise assistant. Use add/3 when asked for arithmetic."),
|
|
239
|
-
loop.
|
|
320
|
+
Only use a custom loop for a required protocol. This example validates project intake BEFORE allowing conversation. A normal assistant with a persona/tools uses shell/1 instead.
|
|
240
321
|
|
|
241
|
-
|
|
242
|
-
input(A), % the person's next message; fails when there is none
|
|
243
|
-
chat(A), % one turn: tools, then it replies and stops
|
|
244
|
-
loop.
|
|
322
|
+
Requires: Foreground conversation/input host and text model; file fixture exists. First input is the required project name, followed by chat messages.
|
|
245
323
|
|
|
246
|
-
|
|
247
|
-
|
|
324
|
+
```prolog
|
|
325
|
+
agent_main :-
|
|
326
|
+
input("Project name?", Project), Project \== "",
|
|
327
|
+
system("You are a concise assistant for project {Project}."),
|
|
328
|
+
conversation.
|
|
329
|
+
conversation :- input(Message), chat(Message), conversation.
|
|
330
|
+
read_text(Path, Text) :- read_file(Path, Text).
|
|
331
|
+
tool(read_text(Path, Text), "Read a workspace text file.", [string]) :- read_text(Path, Text).
|
|
248
332
|
```
|
|
249
333
|
|
|
250
|
-
|
|
251
|
-
post-process it, and a failed turn is reported without ending the conversation.
|
|
252
|
-
Memory carries the conversation, so each turn sees what was said. A turn may open
|
|
253
|
-
a **form** (§9), which is how structured input fits inside a conversation.
|
|
334
|
+
Test goal: `agent_main`. Expected: `I remember the earlier turn.`.
|
|
254
335
|
|
|
255
|
-
|
|
256
|
-
`next/1` dispatch, and a worker's message wakes the conversation:
|
|
336
|
+
Failure/cancel check: An empty project fails before chat starts; no custom loop should be added for ordinary conversation.
|
|
257
337
|
|
|
258
|
-
|
|
259
|
-
loop(Me) :- next(Item), handle(Me, Item), loop(Me).
|
|
338
|
+
Fixture `canonical/input.txt` (create before run):
|
|
260
339
|
|
|
261
|
-
|
|
262
|
-
|
|
340
|
+
```text
|
|
341
|
+
hello
|
|
263
342
|
```
|
|
264
|
-
|
|
265
|
-
The `message(Term)` comes from `send(Me, mail(M))` in a spawned worker. See
|
|
266
|
-
[`docs/DML_CONVERSATION.md`](../../../../docs/DML_CONVERSATION.md) §5.
|