Skip to content

Worker internals and application data flow ​

A Worker is an implementation and resource boundary. Applications invoke Node types and Runtime selects available replicas. A Worker type is not an Agent role such as “finance Agent”: a role usually combines Workers, and several roles may share Worker types.

1. Data flow between Workers ​

text
MEMORY.GET / SEARCH → validate and map ─┐
User messages / Skills / documents ────┴→ CONTEXT.LOAD / UPDATE
                                                ↓ SELECT
                                          INFER.REASONING.*
                                         ↙                 ↘
                                 Action request          Final content
                                      ↓                       ↓
                             INTERACTION.ACT.*        Validate → OUTPUT
                                      ↓                       ↓
                             INTERACTION.OBSERVE        MEMORY.WRITE
                                      ↓
                               CONTEXT.UPDATE → Loop

Mapping is explicit: Memory content is unknown, ContextItem metadata holds roles, Infer messages represent model content, and Interaction reports action state. Do not join similarly named types without conversion.

2. CONTEXT: prepare the working set ​

NodeInternal responsibilityExtension points
LOADNormalize messages/references/items and generate/check IDsReferenceResolver, stateStore
SELECTSelect by purpose, strategy, item count and token budgetselector, ragStrategy, tokenEstimator
UPDATERemove/add items and merge cross-Worker ingressCache CAS, operationQueue
COMPRESSTrim by protection groups and budgetcompressor, tokenEstimator

Default compression does not ask a model for a semantic summary. Use explicit INFER → validation → UPDATE → COMPRESS for summarization, keeping provenance, budgets and failures observable. Redis mode uses scopes and versions; explicit mode computes from the supplied snapshot.

Read data formats, cache mode, selection/compression plugins and errors in the CONTEXT API, then explore five context tasks.

3. INFER: model operations and reasoning strategies ​

INFER exposes four reasoning leaves and three CACHE leaves. ProviderRegistry resolves named adapters, inference execution handles budgets/cancellation, and strategies organize the reasoning task. Tools and business databases are outside its default execution path.

OperationKey distinction
SAMPLEProduces a response or action request; does not execute it
TRAJECTORYMulti-step reasoning with outer and inner status
REFLECTReviews or revises an existing result
DELIBERATEEvaluates, selects or combines candidates
CACHEExplicit inference cache independent of Context/Memory

See INFER for strategies, budgets and streaming, and Providers for custom model protocols.

MEMORY validates inputs, applies query/pagination limits, calls Store/Search providers, validates outputs and wraps NodeResult. It does not bundle a business database driver or schema. Adapters implement transactions, atomicity, idempotency and index consistency.

GET/QUERY and SEARCH serve different purposes. UPDATE modifies by id; DELETE accurately reports removed IDs. Stable errors must not expose connection strings containing passwords to models.

Start with databases and algorithms, then consult the six MEMORY nodes.

5. INTERACTION: actions, observations and delivery ​

NodeInternal componentApplication resource
ACT.TOOLToolRegistryRegisteredTool and business SDK
ACT.MCPMcpRegistryConnected neutral McpClient
OBSERVEResult normalizationNo automatic retries or Context updates
OUTPUTReceipt validationApplication OutputSink

Action failure is business information; infrastructure failures may also throw. Handle both paths. Descriptive approval fields do not enforce approval, and accepted alone does not prove delivery completion. See INTERACTION.

6. Shared lifecycle ​

Create/connect shared SDKs → construct definitions → register with Runtime → handle Graph/Loop requests → stop accepting new tasks → drain in-flight requests → Runtime.close → close application-owned clients.

A resources factory creates replica-specific resources; dispose releases them. Passing one client to several definitions shares it. Do not close a shared client when the first replica stops while others still need it.

7. Understand Nodes and parameters by function ​

Choose the Node's responsibility before tuning its parameters. The same INFER.REASONING.SAMPLE can answer a question, produce a plan or classify a request; messages and model configuration specify the task. The Node type establishes the execution contract; parameters select this call's inputs, algorithm or limits.

Parameter layerWhat it controlsEffect on the Worker
Node inputContent, selection conditions, generation settings, strategy and result count for one callChanges that invocation without modifying Worker-wide configuration
Worker constructionProviders, stores, tools, defaults and replica concurrencyDetermines available capabilities, resources and simultaneous entry calls
Runtime / Graph / LoopDependencies, Graph concurrency, Worker bindings, cancellation and Graph execution limitsControls scheduling; does not automatically add model candidates or database pool capacity
External adapterSupported model parameters, database indexes, tool validation and backend deadlinesDetermines actual resource behavior; passing Ditto validation does not prove every remote parameter is supported

These limits act together. Graph concurrency 4 and INFER replica concurrency 2 do not imply eight allowed simultaneous model calls. A long TRAJECTORY makes several model requests inside one Worker invocation; more rounds keep that slot occupied longer. Reducing Context limits model input, whereas INFER maxTokens limits an individual generation's output budget.

Follow the goal to its parameter guide ​

GoalRead
Keep enough evidence for this step while limiting inputCONTEXT: functional selection and parameter effects
Balance stability, diversity, reasoning depth and costINFER: functional selection and parameter effects
Restore tasks exactly, search durable memory or modify recordsMEMORY: functional selection and parameter effects
Execute tools, interpret action results and verify deliveryINTERACTION: functional selection and parameter effects
Tune retrieval coverage, candidate pools, fusion and rerankingRETRIEVAL: functional selection and parameter effects

Evaluate parameters against task outcomes. For models, record format validation, factual evidence, truncation rate, call count, token usage and latency. For retrieval, check whether relevant evidence reaches the candidate pool and final Context. For writes, check persisted records and actual receipts. Change one primary variable at a time using the same tasks and evidence. Temperature is not confidence, relevance scores are not correctness probabilities, and a successful return does not automatically establish business completion.

Next: optional RETRIEVAL or custom Workers and Nodes.

Ditto · @codesoul-co/ditto · Node.js 24+