new and lookup

new creates Complex Type instances. lookup retrieves existing persistent instances when the type implements a lookup contract.

Syntax

@t1 new Table "c1" "c2" "c3"
@doc new Document "doc1"
@workflowAgent new Workflow "Assistant"
@specsFolder new Folder "./specs"
@agent2 lookup FakeAgent Einstein

Example

@agent1 new FakeAgent 007Agent
@agent2 lookup FakeAgent Einstein
@resp1 agent1.ask "What is your name?"
@resp2 agent2.ask "What is your name?"

This pattern is validated in tests/pipelines/customTypes/fakeAgentTest.mjs. lookup requires at least type and primary key. If lookup fails, output remains undefined and error info is attached.

Step-by-Step Interaction

When new executes, the runtime checks whether the output variable already points to an existing instance. If no instance exists, the runtime creates one through the custom type registry and calls initialization with the provided arguments. If an instance already exists and the input arguments changed, the runtime prefers reinit(...args) when the type exposes it, which preserves object identity while updating internal state. This behavior is validated in tests/pipelines/customTypes/reinitBehaviorTest.mjs.

When lookup executes, the runtime asks the registry to resolve an existing instance by primary key, and it binds the resolved object to the output variable when lookup succeeds. After either new or lookup, interaction continues through member methods:

@nob1 new NamedObject "NOB1"
@waitSetNameResult nob1.setName "NOB1_1"
@currentName := $nob1.name

Method invocation semantics are part of command execution and can also be conditionally guarded (object.?method).

Runtime Behavior Notes

The new command delegates object creation and restoration to the custom type registry, and it binds instance lifecycle to the output variable so downstream dependencies remain stable. The lookup command delegates resolution to type-specific lookup adapters, which makes persistent integration explicit and type-controlled. If lookup fails, the runtime keeps the output undefined and writes error metadata instead of silently creating a substitute object.