Examples
DML language examples
Small, runnable DML programs that demonstrate the language: failure-driven control flow, tools with nested LLM calls, tool scoping, knowledge bases, constraint planning, and research agents.
Running examples
deepclause run dml-examples/<example>.dml
# or from a checkout
node dist/cli/index.js run dml-examples/<example>.dml
Example index
| Example | What it shows |
|---|---|
test.dml | Minimal program structure |
vm-exec.dml | Executing external tools via exec/2 |
coding-agent.dml | Failure-driven control flow in a coding assistant |
knowledge-agent.dml | A shopping assistant backed by Prolog facts |
conversational-agent.dml | Minimal agent with web search and code execution |
nested-task-test.dml | task() inside tool/2 definitions |
tool-scoping-test.dml | with_tools/2 and without_tools/2 |
clpfd-planner.dml | Constraint planning with CLP(FD) |
deep_research.dml | Multi-step research with citations |
arxiv-researcher.dml | Literature search and review |
data-analysis.dml | Reading data and reporting results |
image-analyzer.dml | Multimodal analysis through tools |
Key concepts
Failure-driven control flow
Try each approach until one succeeds:
handle_task(Task) :-
approach_1(Task).
handle_task(Task) :-
approach_2(Task).
handle_task(_) :-
fallback_response.
Tools with nested LLM calls
Tools can use task/N internally to combine deterministic logic with model reasoning:
tool(explain_calculation(A, B, Explanation)) :-
Sum is A + B,
format(string(Desc), "Explain ~w + ~w = ~w to a child", [A, B, Sum]),
task(Desc, Explanation).
Tool scoping
Control which tools a nested task may use:
tool(restricted_task(Input, Output), "Only allows specific tools") :-
with_tools([tool_a, tool_b], (
format(string(Desc), "Process '~w' with limited tools", [Input]),
task(Desc, Output)
)).
tool(safe_task(Input, Output), "Excludes dangerous tools") :-
without_tools([dangerous_tool], (
format(string(Desc), "Process '~w' safely", [Input]),
task(Desc, Output)
)).
Knowledge base
Prolog facts and rules are a first-class knowledge base:
product("laptop", 999).
product("monitor", 249).
discounted(Item, Price, Discounted) :-
product(Item, Price),
Price > 500,
Discounted is Price * 0.9.