Developer Guide: DeepClause Architecture & DML

Build resilient, logic-driven AI agents using the DeepClause Meta Language (DML).

Core Architecture

DeepClause uses a hybrid approach to ensure both flexibility and security:

  • The Sprite VM: A dedicated, persistent Linux microVM for every user. This is a real, lightweight cloud instance, not a browser-side sandbox.
  • DML Engine: The core logic engine is a WASM-compiled Prolog interpreter (SWI-Prolog) that runs inside the Sprite VM.
  • Persistence: Each Sprite has a private /workspace directory that persists between skill runs.

DML Full Language Reference

DML (DeepClause Meta Language) is a logic programming dialect designed for AI orchestration. It uses Prolog-style unification and backtracking to manage complex LLM workflows.

1. Entry Points

Every DML skill must define at least one agent_main clause.

  • agent_main: No arguments.
  • agent_main(+Arg1): Receives one input parameter.
  • agent_main(+Arg1, +Arg2): Receives two input parameters.

2. Task Predicates (LLM Calls)

Tasks are the primary way to interact with the LLM. You can use Type-Safe Output Variables to enforce strict validation of the LLM's response.

  • task(+Description): Sends a task to the LLM.
  • task(+Description, -Var1): Binds the output to Var1.
  • task(+Description, integer(Var1)): Forces Var1 to be an integer.
  • task(+Description, boolean(Var1)): Forces Var1 to be a boolean.
  • task(+Description, list(string(Var1))): Forces Var1 to be a list of strings.
  • task(+Description, object(Var1)): Forces Var1 to be a JSON-style object (dictionary).
  • task(Prompt, V1, V2, V3): Binds output to up to three variables simultaneously.

3. Memory & Context

  • system(+Text): Adds a permanent system instruction or persona for the current session.
  • user(+Text): Manually injects a user message into the LLM's conversation context.

4. Execution & Tools

  • exec(+ToolCall, -Output): Directly executes a system tool (e.g., exec(bash(cmd: "ls -la"), Files)).
  • tool(Signature, +Description) :- Body.: Defines a custom DML tool that the LLM can decide to use during a task/n call.
  • with_tools(+ToolList, +Goal): Restricts the LLM to only the specified tools while executing Goal.
  • without_tools(+ToolList, +Goal): Excludes specific tools while executing Goal.

5. Output & Control

  • output(+Text) / yield(+Text): Streams a progress update back to the user without affecting the LLM's conversation history.
  • log(+Text): Emits a debug log event.
  • answer(+Text): Emits the final response and commits the execution, stopping further backtracking.
  • param(+Key, +Description, -Value): Retrieves named parameters passed from the dashboard or API.

6. Logic & Interpolation

  • Backtracking: DML automatically handles failure by backtracking to alternative clauses. If a task fails or a condition isn't met, the state is restored and the next option is tried.
  • String Interpolation: Use {var} inside any text string to automatically interpolate the value of a bound variable.
  • Standard Prolog: Full support for is/2, atom_json_dict/3, list processing [H|T], and constraints (CLP).

Logic-Driven Orchestration: The DML Engine

DeepClause agents aren't just a sequence of prompts. They are powered by the DeepClause Meta Language (DML), a logic-driven orchestration engine built on the foundations of Prolog.

The Power of Logic Programming

By using a Prolog-based engine, DeepClause gains two critical capabilities for autonomous agents:

  • Deterministic Backtracking: If a tool or API call fails, the engine automatically rolls back its internal state and tries the next available logical branch without wasting LLM context.
  • Unification: Variables are bound across the entire execution path, ensuring that data retrieved in step 1 is perfectly preserved and accessible in step 100.

Example: The Deep Research Agent

The following DML code powers the Deep Research skill. It demonstrates tool definitions, interactive user confirmation, multi-step LLM tasks, and native file I/O within the Sprite workspace.

% --- Tool Definitions ---
tool(search(Query, Results), "Search the web for information") :-
    exec(web_search(query: Query, count: 10), Results).

tool(ask_user(Prompt, Response), "Ask user for input") :-
    exec(ask_user(prompt: Prompt), Result),
    get_dict(user_response, Result, Response).

% --- Main Agent Logic ---
agent_main(Question) :-
    system("You are a meticulous research assistant..."),

    output("Step 1: Analyzing the research question..."),
    task("Analyze question: '{Question}'. Identify key topics.", KeyTopics),

    output("Step 2: Creating a research plan..."),
    task("Create plan for: {KeyTopics}. Store in ResearchPlan.", ResearchPlan),

    output("Step 3: Confirming the plan with the user..."),
    confirm_plan(ResearchPlan),

    output("Step 4: Executing research and generating the report..."),
    task("Execute {ResearchPlan}. Synthesize into FinalReport.", FinalReport),

    output("Step 5: Saving the report to a file..."),
    generate_filename(Question, Filename),
    open(Filename, write, Stream), write(Stream, FinalReport), close(Stream),

    format(string(Msg), "Research complete. Saved to ~s.", [Filename]),
    answer(Msg).

% Helper: Handles interactive plan approval
confirm_plan(Plan) :-
    task("Present {Plan} to user. If Approved is 'yes', proceed.", Approved),
    ( Approved == "yes" ->
        output("Plan approved.")
    ;   answer("Research cancelled."), !, fail
    ).

Sprite VM Network Security

By default, your Sprite runs in a highly secure, restricted networking environment to prevent data exfiltration and protect your privacy.

Network Policy Modes

Default (Restricted)

Allows only a curated allowlist of essential hosts: Package registries (npm, pypi), Google APIs (for GWS), and platform proxies. Everything else is blocked by a default deny rule.

Access Anything

Gives the Sprite full outbound internet access. Useful for scraping broad websites or connecting to arbitrary third-party APIs. Use with caution.

Advanced (Custom)

Allows you to define a surgical allowlist and denylist of specific domains (e.g., *.example.com or api.github.com).

How to change: Go to Dashboard → Settings → Network Policy. Changes are applied instantly to your running Sprite environment.