Ditto
A lightweight Node Runtime graphs for composable Agent system.
Scale Workers without changing Graphs or Node Contracts.
English | 简体中文
Start the web graph editor · Build a complete Agent from scratch · Configuration reference · Developer handbook
Install and use
Requires Node.js 24+ and npm 11+. The configuration-based Agent API and template below require @codesoul-co/ditto@0.1.5 or later.
npm init -y
npm pkg set type=module
npm install @codesoul-co/ditto
Start with the standard root template agent_example.json. It includes main, a Subgraph, a Loop and Worker registration/bindings; edit ordinary parameters in config. After npm installation, copy it:
cp node_modules/@codesoul-co/ditto/agent_example.json agent.json
Start the web graph editor
From the root of the Ditto source checkout with Node.js 24+ and npm 11+, install dependencies once and start the editor:
npm ci
npm run editor
Open the address printed in the terminal, normally http://127.0.0.1:4317. Keep that terminal running while you edit. The default canvas opens agent_example.json. Use Import JSON to open a definition in a new canvas, and Save JSON to export it. Click the filename to open Canvas history. Each row has a Delete canvas action that removes its local draft, layout and conversations after confirmation. Layout and conversations are kept in your browser. For open-ended chat, choose a provider, model and API key in the sidebar settings. Canvas editing works without a model key.
In the node library, choose a Worker category to see its nodes. Right-click the canvas to insert a node or subgraph, or right-click a wire to delete it. Drag ports to connect nodes. Wires start unconditional and can be edited by double-clicking. Use Repeat nodes to loop over a path or a single subgraph call. The sidebar also accepts Markdown attachments.
Open a built-in canvas from Import JSON. See the graph editor examples for setup and run instructions.
Standard Agent JSON template
In the source repository, use cp agent_example.json agent.json. The complete configuration follows: an outer Loop runs main, main invokes the load-context Subgraph and then SELECT, and deployment registers and binds the Worker.
{
"version": 1,
"id": "agent-example",
"config": { "selectionLimit": 1, "repetitions": 1 },
"graphs": {
"main": {
"nodes": [
{
"id": "prepare", "kind": "subgraph", "graph": "load-context",
"input": { "$ref": "input" }
},
{
"id": "selected", "type": "CONTEXT.SELECT", "dependsOn": ["prepare"],
"input": {
"context": { "$ref": "nodes.prepare" }, "purpose": "infer",
"limit": { "$ref": "config.selectionLimit" }
}
}
],
"output": { "$ref": "nodes.selected.context.items.0.content" }
},
"load-context": {
"nodes": [{
"id": "loaded", "type": "CONTEXT.LOAD",
"input": { "sources": [{ "role": "user", "content": { "$ref": "input" } }] }
}],
"output": { "$ref": "nodes.loaded" }
}
},
"loop": {
"entry": "prepare", "maxIterations": 8,
"state": { "round": 0, "result": null },
"steps": {
"prepare": {
"graph": "main", "input": { "$ref": "input" },
"assign": {
"round": { "$op": "add", "args": [{ "$ref": "state.round" }, 1] },
"result": { "$ref": "result" }
},
"transitions": [
{
"when": { "$op": "gte", "args": [{ "$ref": "state.round" }, { "$ref": "config.repetitions" }] },
"end": "completed"
},
{ "next": "prepare" }
]
}
},
"output": { "$ref": "state.result" }
},
"deployment": {
"workers": [{ "id": "context", "use": "context" }],
"bindings": {
"main": { "prepare/loaded": "context", "selected": "context" }
}
}
}
The default is one iteration; set config.repetitions to 2 for two. loop.maxIterations bounds total Graph executions. Save these runtime settings as ditto.yaml:
runtime:
graphConcurrency: 4
workers:
context:
policy:
maxItems: 256
Save the host as app.mjs, then run node app.mjs:
import { readFile } from "node:fs/promises";
import { createAgent } from "@codesoul-co/ditto/runtime";
import { createContextWorker } from "@codesoul-co/ditto/worker/context";
const definition = JSON.parse(await readFile("agent.json", "utf8"));
const agent = await createAgent(definition, {
workers: { context: createContextWorker() },
});
try { console.log(await agent.run("Hello Ditto")); }
finally { await agent.close(); }
| Configuration |
Responsibility |
agent.json |
main, Subgraphs, Node dependencies, Loop transitions/stopping, application parameters and Worker bindings |
ditto.yaml |
Runtime and Worker behavior defaults, loaded automatically when creating an Agent / Runtime |
.env |
Credentials, endpoints, model selection and deployment permissions; load with node --env-file=.env app.mjs when needed |
createAgent() / createDitto() automatically read ditto.yaml from the current working directory (process.cwd()) and combine it with the existing process.env; no manual loader call or parent-directory search is needed. A missing default file falls back to environment values and built-in defaults; malformed settings and other read errors fail immediately. Each Runtime reads its configuration once at startup, not on every Node call. An explicit config completely bypasses automatic loading. Use config: loadRuntimeConfigFile("path/to/ditto.yaml") for a custom path or config: loadRuntimeConfig({}) for built-in defaults only. Load .env separately through the application or node --env-file=.env; importing the package and calling compileAgent() do not read files.
Precedence depends on the parameter; the two files are not merged wholesale:
| Parameter |
Effective order (leftmost wins) |
| Runtime configuration source |
Explicit createAgent(..., { config }) / createDitto({ config }) → automatic ./ditto.yaml and process environment → built-in field defaults |
| Loop budget |
agent.json.loop.maxIterations, required when loop is present. YAML runtime.loopMaxIterations only supplies a fallback for code-based Loops without an explicit budget; an Agent without loop runs main once |
| Graph concurrency |
agent.run(input, { concurrency }) → YAML runtime.graphConcurrency → built-in Infinity |
| Memory query limit |
Node input limit (which can be set in agent.json) → Worker factory defaults.queryLimit → YAML workers.memory.queryLimit → built-in 100 |
| Application parameters |
agent.json.config is only available through $ref: "config.…"; it does not override YAML or the host's Runtime config |
| Context policy |
Explicit Worker factory policy fields → YAML workers.context.policy → built-in defaults; createContextWorker() uses Runtime policy automatically |
Environment variables supply credentials, addresses, model selection and deployment permissions; YAML supplies behavior defaults. They own different fields, with no universal “environment overrides JSON/YAML” rule. Other Node parameters follow their respective contracts; default overrides cannot grant tool permissions. The host still creates and injects databases, tools and service profiles.
From zero to a complete Agent: resources, JSON and deployment
Follow Run a complete Agent from scratch, then deploy remote Workers. This path uses five Workers, a real model, Redis, SQLite and tool execution. Its 13-node main Graph is orchestrated entirely by agent.json.
| Worker |
Where resources are connected |
| Context |
Connect an application Redis client and pass it to createContextWorker({ redis: { client } }) |
| Memory |
Supply a SQLite / other database MemoryStore through createMemoryWorker({ store }) |
| Infer |
Configure model endpoint, key, model name and network permission in .env; Runtime builds the HTTP Provider |
| Interaction |
Register tool implementations, an OutputSink and permitted-tool service profiles in the host |
| Retrieval |
Install the separate package and inject a file / vector-service search Provider |
Download application examples into an empty directory and install published npm packages:
mkdir my-ditto-agent
cd my-ditto-agent
curl -fL https://codesoul-co.github.io/Ditto/downloads/ditto-examples.zip -o examples.zip
unzip -q examples.zip
npm install
cp examples/package-basics/.env.example .env
cp examples/json-agent/npm-scenarios/single/ditto.example.yaml ditto.yaml
cp examples/json-agent/npm-scenarios/single/agent.json agent.json
cp examples/json-agent/npm-scenarios/single/input.example.json input.json
mkdir -p task
cp examples/json-agent/npm-scenarios/single/guide.example.json task/guide.json
Fill in real model credentials, the permitted network origin and Redis URL in .env, then start Redis. The application creates SQLite automatically; this five-Worker path needs no third-party extension. Run:
node --env-file=.env examples/json-agent/npm-scenarios/cli.mjs agent.json input.json task
cat task/answers/demo-1.md
Expect 3, with a real tool call, Redis Context, task/memory.sqlite and an answer file. Use fresh business IDs for each new task. openScenarioResources() in host.ts opens resources and builds Workers once; the CLI reads JSON and calls createAgent() / agent.run(). Resource adapters are application source, not built-in Core database connections.
For a long-running service, create resources and the Agent at startup, reuse agent.run(input) per request, then drain the Agent before closing Redis/database clients. JSON selects host implementations through deployment.workers[].use and instances through bindings; it does not implement tools or grant itself permissions.
Keep the same JSON when deploying across machines. remote.mjs provides runnable HTTP server/controller modes. The server owns resources and five registered Workers; the controller uses compileAgent(), createHttpTransport() and registerRemote() to execute the plan. Graph/Loop stay on the controller, Node calls cross HTTP(S), and databases/model keys stay on the execution host. IPC is available for local child processes. See the complete deployment steps for tokens, TLS, manifests, shutdown and communication limits; agent.json does not automatically deploy or discover remote services.
Configured Agents also support independent Graph/Subgraph execution, durable checkpoints, awaited state-update/pause boundaries, and editor schemas, diagnostics and node mappings. See the execution and recovery guide for APIs available in 0.1.5 and later.
This first Graph requires no model, Redis or credentials. For a complete Agent, use real model configuration, Redis Context and database Memory as shown in the detailed package guide (中文). It covers installation, strict TypeScript, every execution entry, result handling, tools, Loop composition, storage, recovery, output and troubleshooting.
The four runnable beginner examples demonstrate Context, tools, optional retrieval and a persistent multi-turn Agent. The guide includes exact commands to copy application adapters into an independent npm project; example business functions are not package exports.
Install retrieval separately when needed:
npm install @codesoul-co/ditto-retrieval
Import its Worker from @codesoul-co/ditto-retrieval. Runtime and built-in Worker entries such as @codesoul-co/ditto/runtime and @codesoul-co/ditto/worker/memory belong to the main package. Do not import private src or dist paths.