deepclause-sdk 0.0.1
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 +446 -0
- package/dist/agent.d.ts +44 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +518 -0
- package/dist/agent.js.map +1 -0
- package/dist/cli/commands.d.ts +37 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +105 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/compile.d.ts +88 -0
- package/dist/cli/compile.d.ts.map +1 -0
- package/dist/cli/compile.js +362 -0
- package/dist/cli/compile.js.map +1 -0
- package/dist/cli/config.d.ts +265 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +272 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +287 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/mcp.d.ts +56 -0
- package/dist/cli/mcp.d.ts.map +1 -0
- package/dist/cli/mcp.js +138 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/cli/prompt.d.ts +20 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +669 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/run.d.ts +33 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +429 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/search.d.ts +25 -0
- package/dist/cli/search.d.ts.map +1 -0
- package/dist/cli/search.js +125 -0
- package/dist/cli/search.js.map +1 -0
- package/dist/cli/tools.d.ts +36 -0
- package/dist/cli/tools.d.ts.map +1 -0
- package/dist/cli/tools.js +204 -0
- package/dist/cli/tools.js.map +1 -0
- package/dist/cli/tui/index.d.ts +22 -0
- package/dist/cli/tui/index.d.ts.map +1 -0
- package/dist/cli/tui/index.js +29 -0
- package/dist/cli/tui/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/prolog/bridge.d.ts +21 -0
- package/dist/prolog/bridge.d.ts.map +1 -0
- package/dist/prolog/bridge.js +226 -0
- package/dist/prolog/bridge.js.map +1 -0
- package/dist/prolog/loader.d.ts +40 -0
- package/dist/prolog/loader.d.ts.map +1 -0
- package/dist/prolog/loader.js +133 -0
- package/dist/prolog/loader.js.map +1 -0
- package/dist/prolog-src/deepclause_memory.pl +45 -0
- package/dist/prolog-src/deepclause_mi.pl +1978 -0
- package/dist/prolog-src/deepclause_mi.pl.bak +570 -0
- package/dist/prolog-src/deepclause_strings.pl +89 -0
- package/dist/runner.d.ts +143 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +1095 -0
- package/dist/runner.js.map +1 -0
- package/dist/sdk.d.ts +9 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +131 -0
- package/dist/sdk.js.map +1 -0
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +138 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +79 -0
- package/src/prolog-src/deepclause_memory.pl +45 -0
- package/src/prolog-src/deepclause_mi.pl +1978 -0
- package/src/prolog-src/deepclause_mi.pl.bak +570 -0
- package/src/prolog-src/deepclause_strings.pl +89 -0
- package/vendor/swipl-wasm/LICENSE.txt +41 -0
- package/vendor/swipl-wasm/dist/bin/index.js +25 -0
- package/vendor/swipl-wasm/dist/common.d.ts +88 -0
- package/vendor/swipl-wasm/dist/generateImage.d.ts +6 -0
- package/vendor/swipl-wasm/dist/generateImage.js +76 -0
- package/vendor/swipl-wasm/dist/index.d.ts +2 -0
- package/vendor/swipl-wasm/dist/index.js +1 -0
- package/vendor/swipl-wasm/dist/loadImage.d.ts +2 -0
- package/vendor/swipl-wasm/dist/loadImage.js +10 -0
- package/vendor/swipl-wasm/dist/loadImageDefault.d.ts +2 -0
- package/vendor/swipl-wasm/dist/loadImageDefault.js +11 -0
- package/vendor/swipl-wasm/dist/strToBuffer.d.ts +8 -0
- package/vendor/swipl-wasm/dist/strToBuffer.js +41 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-bundle-no-data.d.ts +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-bundle-no-data.js +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-bundle.d.ts +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-bundle.js +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-web.d.ts +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-web.data +0 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-web.js +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-web.wasm +0 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-win.js +1 -0
- package/vendor/swipl-wasm/dist/swipl/swipl-win.wasm +0 -0
- package/vendor/swipl-wasm/dist/swipl/swipl.d.ts +2 -0
- package/vendor/swipl-wasm/dist/swipl/swipl.js +1 -0
- package/vendor/swipl-wasm/dist/swipl/swipl.wasm +0 -0
- package/vendor/swipl-wasm/dist/swipl-node.d.ts +2 -0
- package/vendor/swipl-wasm/dist/swipl-node.js +17 -0
- package/vendor/swipl-wasm/package.json +129 -0
package/README.md
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
# DeepClause
|
|
2
|
+
|
|
3
|
+
Compile markdown specs into Prolog agents. Guaranteed execution semantics for agentic workflows.
|
|
4
|
+
|
|
5
|
+
## What This Is
|
|
6
|
+
|
|
7
|
+
AI skills and tools are everywhere—but most are just prompts. When a prompt fails, you tweak it. When you need branching logic, you write wrapper code. When you want retry behavior, you build it yourself.
|
|
8
|
+
|
|
9
|
+
DeepClause takes a different approach: **compile task descriptions into Prolog-based programs** that handle control flow, error recovery, and tool orchestration automatically.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Markdown description → compile → Logic program (DML) → run → Output
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Sandboxed by Default
|
|
16
|
+
|
|
17
|
+
Everything runs in WebAssembly—no native code execution, no container setup required:
|
|
18
|
+
|
|
19
|
+
- **[AgentVM](https://github.com/deepclause/agentvm)**: A lightweight WASM-based Linux environment for shell commands, file operations, and Python/Node execution
|
|
20
|
+
- **Prolog runtime**: The logic engine itself runs in WASM (SWI-Prolog compiled to WebAssembly)
|
|
21
|
+
|
|
22
|
+
This means that DML tools and agents can execute arbitrary shell commands without escaping to your host system.
|
|
23
|
+
|
|
24
|
+
## Beyond Markdown: Why Logic Programming?
|
|
25
|
+
|
|
26
|
+
Markdown skills are great for simple, linear workflows. But real-world tasks often need:
|
|
27
|
+
|
|
28
|
+
- **Branching logic** - Try approach A, fall back to B if it fails
|
|
29
|
+
- **Iteration** - Process a list of items one by one
|
|
30
|
+
- **State management** - Isolate context between sub-tasks
|
|
31
|
+
- **Error recovery** - Handle failures gracefully
|
|
32
|
+
- **Composition** - Build complex skills from simpler ones
|
|
33
|
+
|
|
34
|
+
When you give markdown instructions to a typical agentic loop, there's no guarantee these requirements will actually be followed—the LLM might ignore the fallback logic or skip items in a list.
|
|
35
|
+
|
|
36
|
+
By compiling to Prolog, you get **guaranteed execution semantics**: backtracking ensures fallbacks happen, recursion processes every item, and unification binds variables correctly. You define *what* should happen—the runtime guarantees *how*.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Spec-Driven Development That Compiles
|
|
41
|
+
|
|
42
|
+
[Spec-driven development](https://martinfowler.com/articles/exploring-gen-ai/sdd-3-tools.html) proposes writing specifications before code, with the spec becoming the source of truth. Current SDD tools (Kiro, spec-kit, Tessl) generate elaborate markdown artifacts that are then fed to coding agents—but the output is still non-deterministic, and you end up reviewing both specs *and* generated code.
|
|
43
|
+
|
|
44
|
+
DeepClause offers a different approach: **specs that compile to actual programs**.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Your spec
|
|
48
|
+
cat > api-client.md << 'EOF'
|
|
49
|
+
# API Client Generator
|
|
50
|
+
Generate a TypeScript API client from an OpenAPI spec URL.
|
|
51
|
+
|
|
52
|
+
## Arguments
|
|
53
|
+
- SpecUrl: URL to an OpenAPI/Swagger JSON specification
|
|
54
|
+
|
|
55
|
+
## Behavior
|
|
56
|
+
- Fetch the OpenAPI spec from SpecUrl
|
|
57
|
+
- Extract endpoints and types
|
|
58
|
+
- Generate typed client code
|
|
59
|
+
- Write to output file
|
|
60
|
+
EOF
|
|
61
|
+
|
|
62
|
+
# Compile it once
|
|
63
|
+
deepclause compile api-client.md
|
|
64
|
+
|
|
65
|
+
# Run it deterministically, forever
|
|
66
|
+
deepclause run api-client.dml "https://api.example.com/openapi.json"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The compiled `.dml` is inspectable logic—you can see exactly what it does:
|
|
70
|
+
|
|
71
|
+
```prolog
|
|
72
|
+
tool(fetch_spec(Url, Spec), "Fetch OpenAPI specification") :-
|
|
73
|
+
exec(web_fetch(url: Url), Spec).
|
|
74
|
+
|
|
75
|
+
agent_main(SpecUrl) :-
|
|
76
|
+
system("You are an API client generator..."),
|
|
77
|
+
fetch_spec(SpecUrl, Spec),
|
|
78
|
+
task("Extract endpoints from: {Spec}", Endpoints),
|
|
79
|
+
task("Generate TypeScript client for: {Endpoints}", Code),
|
|
80
|
+
exec(vm_exec(command: "cat > client.ts"), Code),
|
|
81
|
+
answer("Generated client.ts").
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Unlike traditional SDD where specs guide but don't control, DeepClause specs **become** the executable. The spec *is* the code—just at a higher abstraction level.
|
|
85
|
+
|
|
86
|
+
## Quick Start
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Install
|
|
90
|
+
npm install -g deepclause-sdk
|
|
91
|
+
|
|
92
|
+
# Set API key (or ANTHROPIC_API_KEY, GOOGLE_API_KEY, etc.)
|
|
93
|
+
export OPENAI_API_KEY="sk-..."
|
|
94
|
+
|
|
95
|
+
# Initialize in your project
|
|
96
|
+
deepclause init
|
|
97
|
+
|
|
98
|
+
# Configure the model for compilation
|
|
99
|
+
deepclause set-model openai/gpt-4o
|
|
100
|
+
|
|
101
|
+
# Create a task description
|
|
102
|
+
cat > .deepclause/tools/explain.md << 'EOF'
|
|
103
|
+
# Code Explainer
|
|
104
|
+
|
|
105
|
+
Explain what a piece of code does in plain English.
|
|
106
|
+
|
|
107
|
+
## Arguments
|
|
108
|
+
- Code: The source code to explain
|
|
109
|
+
|
|
110
|
+
## Behavior
|
|
111
|
+
- Break down the code into logical sections
|
|
112
|
+
- Explain each section's purpose
|
|
113
|
+
- Note any potential issues
|
|
114
|
+
EOF
|
|
115
|
+
|
|
116
|
+
# Compile to executable DML
|
|
117
|
+
deepclause compile .deepclause/tools/explain.md
|
|
118
|
+
|
|
119
|
+
# Run it
|
|
120
|
+
deepclause run .deepclause/tools/explain.dml "function fib(n) { return n < 2 ? n : fib(n-1) + fib(n-2) }"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Use Cases
|
|
124
|
+
|
|
125
|
+
### Coding agents building their own tools
|
|
126
|
+
|
|
127
|
+
AI coding assistants can compile task descriptions on the fly:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Agent writes a task description
|
|
131
|
+
cat > .deepclause/tools/api-docs.md << 'EOF'
|
|
132
|
+
# API Documentation Lookup
|
|
133
|
+
Search for API documentation and summarize usage patterns.
|
|
134
|
+
|
|
135
|
+
## Arguments
|
|
136
|
+
- Query: The API or library name to look up
|
|
137
|
+
|
|
138
|
+
## Tools needed
|
|
139
|
+
- web_search
|
|
140
|
+
|
|
141
|
+
## Behavior
|
|
142
|
+
- Search for official documentation
|
|
143
|
+
- Summarize usage patterns and examples
|
|
144
|
+
EOF
|
|
145
|
+
|
|
146
|
+
# Compile it
|
|
147
|
+
deepclause compile .deepclause/tools/api-docs.md
|
|
148
|
+
|
|
149
|
+
# Use it whenever needed
|
|
150
|
+
deepclause run .deepclause/tools/api-docs.dml "Stripe PaymentIntent"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The compiled `.dml` files are deterministic—same input, same execution path. The agent builds up a library of reliable tools.
|
|
154
|
+
|
|
155
|
+
### Automation pipelines
|
|
156
|
+
|
|
157
|
+
Chain compiled programs together:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
deepclause run review-code.dml src/handler.ts > review.md
|
|
161
|
+
deepclause run summarize.dml review.md
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Shareable, versionable task logic
|
|
165
|
+
|
|
166
|
+
Check `.dml` files into version control. The logic is inspectable—you can see exactly what the program does, not just what prompt it sends.
|
|
167
|
+
|
|
168
|
+
## Example Task Descriptions
|
|
169
|
+
|
|
170
|
+
### Web Research
|
|
171
|
+
```markdown
|
|
172
|
+
# Web Research
|
|
173
|
+
Search the web and synthesize findings into a report.
|
|
174
|
+
|
|
175
|
+
## Arguments
|
|
176
|
+
- Question: The research question to investigate
|
|
177
|
+
|
|
178
|
+
## Tools needed
|
|
179
|
+
- web_search
|
|
180
|
+
|
|
181
|
+
## Behavior
|
|
182
|
+
- Search for 3-5 authoritative sources on the Question
|
|
183
|
+
- Extract key findings from each
|
|
184
|
+
- Write a summary with inline citations
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Code Review
|
|
188
|
+
```markdown
|
|
189
|
+
# Code Review
|
|
190
|
+
Review code for bugs, security issues, and style.
|
|
191
|
+
|
|
192
|
+
## Arguments
|
|
193
|
+
- FilePath: Path to the file to review
|
|
194
|
+
|
|
195
|
+
## Tools needed
|
|
196
|
+
- vm_exec (to read files)
|
|
197
|
+
|
|
198
|
+
## Behavior
|
|
199
|
+
- Read the file at FilePath
|
|
200
|
+
- Check for common bugs and anti-patterns
|
|
201
|
+
- Identify security concerns
|
|
202
|
+
- Suggest improvements
|
|
203
|
+
- Be concise and actionable
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Data Analysis
|
|
207
|
+
```markdown
|
|
208
|
+
# CSV Analyzer
|
|
209
|
+
Analyze a CSV file and describe its contents.
|
|
210
|
+
|
|
211
|
+
## Arguments
|
|
212
|
+
- FilePath: Path to the CSV file to analyze
|
|
213
|
+
|
|
214
|
+
## Tools needed
|
|
215
|
+
- vm_exec (to run Python)
|
|
216
|
+
|
|
217
|
+
## Behavior
|
|
218
|
+
- Load the CSV at FilePath with pandas
|
|
219
|
+
- Describe the schema (columns, types, row count)
|
|
220
|
+
- Identify interesting patterns
|
|
221
|
+
- Generate summary statistics
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Available Tools
|
|
225
|
+
|
|
226
|
+
Skills can use these built-in tools:
|
|
227
|
+
|
|
228
|
+
| Tool | Description |
|
|
229
|
+
|------|-------------|
|
|
230
|
+
| `web_search` | Search the web (requires `BRAVE_API_KEY`) |
|
|
231
|
+
| `news_search` | Search recent news |
|
|
232
|
+
| `vm_exec` | Run shell commands in a sandbox |
|
|
233
|
+
| `ask_user` | Prompt the user for input |
|
|
234
|
+
|
|
235
|
+
Configure tools in `.deepclause/config.json`.
|
|
236
|
+
|
|
237
|
+
## CLI Reference
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
deepclause init # Set up .deepclause/ folder
|
|
241
|
+
deepclause compile <file.md> # Compile Markdown to DML
|
|
242
|
+
deepclause compile-all <dir> # Compile all .md files in directory
|
|
243
|
+
deepclause run <file.dml> [args] # Execute a compiled skill
|
|
244
|
+
deepclause list-commands # List available compiled skills
|
|
245
|
+
deepclause list-tools # Show available tools
|
|
246
|
+
deepclause set-model <model> # Change default model
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Run Options
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
deepclause run skill.dml "input" \
|
|
253
|
+
--model google/gemini-2.5-flash \ # Override model
|
|
254
|
+
--stream \ # Stream output
|
|
255
|
+
--verbose \ # Show tool calls
|
|
256
|
+
--workspace ./data # Set working directory
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Configuration
|
|
260
|
+
|
|
261
|
+
`.deepclause/config.json`:
|
|
262
|
+
```json
|
|
263
|
+
{
|
|
264
|
+
"model": "gpt-4o",
|
|
265
|
+
"provider": "openai",
|
|
266
|
+
"agentvm": { "network": true }
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Model at Compile Time vs Run Time
|
|
271
|
+
|
|
272
|
+
The model specified in `config.json` (or via `--model`) is used during **compilation** to generate the DML program. At **run time**, you can use a different model:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# Compile with GPT-4o (better at understanding intent)
|
|
276
|
+
deepclause set-model openai/gpt-4o
|
|
277
|
+
deepclause compile research.md
|
|
278
|
+
|
|
279
|
+
# Run with a faster/cheaper model
|
|
280
|
+
deepclause run research.dml "quantum computing" --model google/gemini-2.5-flash
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
This lets you use a more capable model for the one-time compilation step, then execute with a faster or cheaper model for repeated runs.
|
|
284
|
+
|
|
285
|
+
### Supported Models
|
|
286
|
+
|
|
287
|
+
| Provider | Models |
|
|
288
|
+
|----------|--------|
|
|
289
|
+
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `o1`, `o3-mini` |
|
|
290
|
+
| Anthropic | `claude-sonnet-4-20250514`, `claude-3-5-sonnet-20241022` |
|
|
291
|
+
| Google | `gemini-2.5-pro`, `gemini-2.5-flash` |
|
|
292
|
+
| OpenRouter | Any model via `openrouter/provider/model` |
|
|
293
|
+
|
|
294
|
+
## Understanding DML
|
|
295
|
+
|
|
296
|
+
The compiled `.dml` files use DML (DeepClause Meta Language), a dialect of Prolog designed for AI workflows.
|
|
297
|
+
|
|
298
|
+
```prolog
|
|
299
|
+
% Generated from research.md
|
|
300
|
+
tool(search(Query, Results), "Search the web") :-
|
|
301
|
+
exec(web_search(query: Query), Results).
|
|
302
|
+
|
|
303
|
+
agent_main(Topic) :-
|
|
304
|
+
system("You are a research assistant..."),
|
|
305
|
+
task("Research {Topic} and summarize findings."),
|
|
306
|
+
answer("Done").
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
You can edit DML directly for fine-grained control. See the [DML Reference](./docs/DML_REFERENCE.md) for the full language spec.
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
### Backtracking: Automatic Retry Logic
|
|
313
|
+
|
|
314
|
+
Prolog's backtracking means you can define multiple approaches. If one fails, execution automatically tries the next:
|
|
315
|
+
|
|
316
|
+
```prolog
|
|
317
|
+
% Try fast approach first, fall back to thorough approach
|
|
318
|
+
agent_main(Question) :-
|
|
319
|
+
system("Answer concisely."),
|
|
320
|
+
task("Answer: {Question}"),
|
|
321
|
+
validate_answer, % Fails if answer is inadequate
|
|
322
|
+
answer("Done").
|
|
323
|
+
|
|
324
|
+
agent_main(Question) :-
|
|
325
|
+
system("Be thorough and detailed."),
|
|
326
|
+
task("Research and answer: {Question}"),
|
|
327
|
+
answer("Done").
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
If `validate_answer` fails, Prolog backtracks and tries the second clause. No explicit if/else needed.
|
|
331
|
+
|
|
332
|
+
### Recursion: Processing Lists
|
|
333
|
+
|
|
334
|
+
Handle variable-length inputs naturally:
|
|
335
|
+
|
|
336
|
+
```prolog
|
|
337
|
+
% Process each file in a list
|
|
338
|
+
process_files([]).
|
|
339
|
+
process_files([File|Rest]) :-
|
|
340
|
+
task("Review {File} for issues."),
|
|
341
|
+
process_files(Rest).
|
|
342
|
+
|
|
343
|
+
agent_main(Files) :-
|
|
344
|
+
process_files(Files),
|
|
345
|
+
answer("All files reviewed.").
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Memory Isolation: Independent Sub-tasks
|
|
349
|
+
|
|
350
|
+
Use `prompt/N` for LLM calls that shouldn't share context:
|
|
351
|
+
|
|
352
|
+
```prolog
|
|
353
|
+
agent_main(Topic) :-
|
|
354
|
+
system("You are a researcher."),
|
|
355
|
+
task("Research {Topic} deeply.", Findings),
|
|
356
|
+
|
|
357
|
+
% Independent critique - fresh context, no bias from main research
|
|
358
|
+
prompt("As a skeptic, critique: {Findings}", Critique),
|
|
359
|
+
|
|
360
|
+
% Back to main context
|
|
361
|
+
task("Address this critique: {Critique}"),
|
|
362
|
+
answer("Done").
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Tool Scoping: Controlled Capabilities
|
|
366
|
+
|
|
367
|
+
Limit what tools are available to specific sub-tasks:
|
|
368
|
+
|
|
369
|
+
```prolog
|
|
370
|
+
tool(dangerous_action(X, Result), "Do something risky") :-
|
|
371
|
+
exec(vm_exec(command: X), Result).
|
|
372
|
+
|
|
373
|
+
agent_main(Task) :-
|
|
374
|
+
% Main task has all tools
|
|
375
|
+
task("Plan how to: {Task}", Plan),
|
|
376
|
+
|
|
377
|
+
% Execute with restricted tools - no dangerous_action allowed
|
|
378
|
+
without_tools([dangerous_action], (
|
|
379
|
+
task("Execute this plan safely: {Plan}")
|
|
380
|
+
)),
|
|
381
|
+
answer("Done").
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Composition: Building Blocks
|
|
385
|
+
|
|
386
|
+
Define reusable predicates and compose them:
|
|
387
|
+
|
|
388
|
+
```prolog
|
|
389
|
+
% Reusable building blocks
|
|
390
|
+
search_and_summarize(Query, Summary) :-
|
|
391
|
+
exec(web_search(query: Query), Results),
|
|
392
|
+
task("Summarize: {Results}", Summary).
|
|
393
|
+
|
|
394
|
+
verify_facts(Text, Verified) :-
|
|
395
|
+
task("Fact-check this text: {Text}", Issues),
|
|
396
|
+
(Issues = "none" -> Verified = Text ; fix_issues(Text, Issues, Verified)).
|
|
397
|
+
|
|
398
|
+
% Compose into a skill
|
|
399
|
+
agent_main(Topic) :-
|
|
400
|
+
search_and_summarize(Topic, Draft),
|
|
401
|
+
verify_facts(Draft, Final),
|
|
402
|
+
answer(Final).
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### When to Use DML Directly
|
|
406
|
+
|
|
407
|
+
| Use Markdown When... | Use DML When... |
|
|
408
|
+
|---------------------|-----------------|
|
|
409
|
+
| Linear, single-task workflow | Complex control flow needed |
|
|
410
|
+
| No error handling needed | Need retry/fallback logic |
|
|
411
|
+
| Simple input → output | Processing collections |
|
|
412
|
+
| Quick prototyping | Production reliability |
|
|
413
|
+
| Non-programmers writing skills | Fine-grained tool control |
|
|
414
|
+
|
|
415
|
+
Start with Markdown. Graduate to DML when you need the power.
|
|
416
|
+
|
|
417
|
+
## Using as a Library
|
|
418
|
+
|
|
419
|
+
Embed DeepClause in your own applications:
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
import { createDeepClause } from 'deepclause-sdk';
|
|
423
|
+
|
|
424
|
+
const dc = await createDeepClause({
|
|
425
|
+
model: 'gpt-4o',
|
|
426
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
for await (const event of dc.runDML(code)) {
|
|
430
|
+
console.log(event.type, event.content);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
await dc.dispose();
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
See [sdk-examples/](./sdk-examples/) for more.
|
|
437
|
+
|
|
438
|
+
## More Resources
|
|
439
|
+
|
|
440
|
+
- [DML Reference](./docs/DML_REFERENCE.md) - Full language documentation
|
|
441
|
+
- [Examples](./dml-examples/) - Sample DML programs
|
|
442
|
+
- [Architecture](./ARCHITECTURE.md) - How it works
|
|
443
|
+
|
|
444
|
+
## License
|
|
445
|
+
|
|
446
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Loop Implementation
|
|
3
|
+
* Runs an LLM agent loop for task() predicate execution
|
|
4
|
+
*
|
|
5
|
+
* Based on AI SDK v6 agent patterns:
|
|
6
|
+
* - Uses Zod schemas for tool definitions
|
|
7
|
+
* - Uses result.response.messages for message history management
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolDefinition, MemoryMessage } from './types.js';
|
|
10
|
+
export interface AgentLoopOptions {
|
|
11
|
+
taskDescription: string;
|
|
12
|
+
outputVars: string[];
|
|
13
|
+
memory: MemoryMessage[];
|
|
14
|
+
tools: Map<string, ToolDefinition>;
|
|
15
|
+
modelOptions: {
|
|
16
|
+
model: string;
|
|
17
|
+
provider: string;
|
|
18
|
+
temperature: number;
|
|
19
|
+
maxOutputTokens: number;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
onOutput: (text: string) => void;
|
|
23
|
+
onStream?: (chunk: string, done: boolean) => void;
|
|
24
|
+
onToolCall?: (toolName: string, args: Record<string, unknown>) => void;
|
|
25
|
+
onAskUser: (prompt: string) => Promise<string>;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
streaming?: boolean;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface AgentLoopResult {
|
|
31
|
+
success: boolean;
|
|
32
|
+
outputs: string[];
|
|
33
|
+
variables: Record<string, unknown>;
|
|
34
|
+
/** Conversation messages from the agent loop (excludes system messages which are task-specific) */
|
|
35
|
+
messages: Array<{
|
|
36
|
+
role: 'user' | 'assistant';
|
|
37
|
+
content: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run an agent loop for a task
|
|
42
|
+
*/
|
|
43
|
+
export declare function runAgentLoop(options: AgentLoopOptions): Promise<AgentLoopResult>;
|
|
44
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAqChE,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACnC,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACvE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,mGAAmG;IACnG,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClE;AA4DD;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CA6ZtF"}
|