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

ExampleWhat it shows
test.dmlMinimal program structure
vm-exec.dmlExecuting external tools via exec/2
coding-agent.dmlFailure-driven control flow in a coding assistant
knowledge-agent.dmlA shopping assistant backed by Prolog facts
conversational-agent.dmlMinimal agent with web search and code execution
nested-task-test.dmltask() inside tool/2 definitions
tool-scoping-test.dmlwith_tools/2 and without_tools/2
clpfd-planner.dmlConstraint planning with CLP(FD)
deep_research.dmlMulti-step research with citations
arxiv-researcher.dmlLiterature search and review
data-analysis.dmlReading data and reporting results
image-analyzer.dmlMultimodal 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.