Repository navigation
LLM ⇄ Workspace: object tools and Env removal - #13635
Merged
Merged
Conversation
This was referenced Jul 13, 2026
vito
force-pushed
the
llm-workspace-llm-binding
branch
from
July 13, 2026 21:27
31c8b75 to
4183bac
Compare
vito
force-pushed
the
llm-workspace-llm-binding
branch
from
July 13, 2026 21:57
4183bac to
1fd56dc
Compare
vito
force-pushed
the
llm-workspace-llm-binding
branch
2 times, most recently
from
July 14, 2026 20:01
6ed219d to
e197067
Compare
vito
force-pushed
the
llm-workspace-llm-binding
branch
3 times, most recently
from
July 15, 2026 01:01
566ba9b to
a3b7c2f
Compare
vito
force-pushed
the
llm-workspace-llm-binding
branch
from
July 15, 2026 19:54
4773b57 to
15bde10
Compare
vito
force-pushed
the
llm-workspace-llm-binding
branch
from
July 15, 2026 23:26
cb8d48d to
6c303ed
Compare
The LLM acts through the methods of the objects it's bound to via LLM.withTools: each eligible method becomes a tool, a method that returns the bound object's own type rebinds it as the new state, and a Changeset return applies to the bound workspace. Host-writing fields are blocked from the model, module entrypoints are surfaced as the way in, and the schema the model sees derives from the workspace it's bound to. This replaces the per-field MCP tool surface, and with the workspace binding in place the Env type loses its last responsibility: Env, its schema, and its prompt I/O machinery are deleted. (cherry picked from commit 6b74120) Signed-off-by: Alex Suraci <[email protected]>
Add Query.currentNode, returning the object that received the current module function call as the universal Node interface. It reads the receiver threaded onto the active FunctionCall (ModuleFunction.Call now records it on FunctionCall.parentTyped), which rides the existing per-session fnCall channel into the module's nested client, so a module can reference itself without reconstructing a fresh instance. To let a statically typed caller pass that Node where an object is wanted, LLM.withTools's object argument now carries @expectedType(name: "Node"): every object implements Node, so Dang accepts any object and conveys it as its id. A new dagql Argument.Directive builder attaches the directive. Together these let a module bind its own methods as the LLM's tools via base.withTools(currentNode, ...), unblocking doug2. Verified for the in-process Dang runtime, where the receiver crosses by reference. The containerized runtime rides the same fnCall channel but, along with the interface-typed return, needs a from-source engine to confirm. SDKs and docs are regenerated. (cherry picked from commit f690e8a) Signed-off-by: Alex Suraci <[email protected]>
Two token-accounting fixes. Add LLM.contextTokens, the estimated tokens currently occupying the context window -- the last provider-reported usage plus an estimate of any messages appended since -- as distinct from the cumulative LLM.tokenUsage. And stop double-counting cached prompt tokens: OpenAI and Codex report prompt_tokens inclusive of cached reads, so subtract the cached portion from InputTokens, record the cache-read metric they were dropping, and include cache tokens in TotalTokens across the providers. (cherry picked from commit 83cf980) Signed-off-by: Alex Suraci <[email protected]>
The LLM's in-session overlay makes the workspace it is bound to diverge from the frozen per-client one, which exposed every place the engine assumed those were the same. Close them: currentWorkspace prefers the bound workspace, group runs (checks, generators, agents, services) re-seed the workspace they were called on into each leaf, the binding is carried across nested module clients on the same channel that carries the receiver object, and a tool returning a Workspace rebinds the LLM to it. Module source stays session-served, so ordinary module usage is unchanged. REBASE NOTE: this replaced WorkspaceOverride which emerged independently and landed first Signed-off-by: Alex Suraci <[email protected]>
Consolidate the architecture of the workspace-bound LLM: the Workspace binding that replaced Env, object tools as the agent interface, installable @agent plugins, and the workspace propagation semantics (seed vs propagate, the A-calls-B invariant). Supersedes the retired working docs for the individual pieces. (cherry picked from commit 1690122) Signed-off-by: Alex Suraci <[email protected]>
Old module views were seeing the new API surface: the Agent and AgentGroup types (plus their generated ID/load fields), the @agent plumbing (Function.withAgent, Workspace.agents), Query.currentNode, and the LLM workspace binding (withWorkspace, workspace, contextTokens). Gate them all to v1.0.0-0, following the same pattern the LLM foundation PR used for the content-block model. Update base_schema.json to reflect the intended base view: identical to main's plus the Env/Binding removal (a deliberate breaking change of this PR) and the @agent directive, which has no view gating mechanism. The golden had been recorded before the foundation PR gated its own surface, so it also wrongly allowlisted content-block types, Workspace.glob/search, and the loop(maxAPICalls) move. (cherry picked from commit 1fcf9a2) Signed-off-by: Alex Suraci <[email protected]>
Env and Binding were the two core types whose fields were generated per installed type, so the core schema changed shape depending on which modules were loaded. With them gone, codegen's ExtendableTypes is just Query. Regenerate the Go client and the other SDKs without Env, drop the hand-written documentation references, and rework the Env-era test fixtures for the workspace world — including the go-programmer fixture, which is rewritten against object tools and loses its checked-in generated client. The Java SDK also learns to marshal interface-typed args by ID, which the object-tools call path now depends on. Signed-off-by: Alex Suraci <[email protected]>
The LLM replay recordings were checked in as golden files keyed by a bespoke format, so every API change meant hand-editing them. Derive them from the engine's own messages export instead, keyed the same way, and update the remaining Env-era API usage in the tests that consume them. Signed-off-by: Alex Suraci <[email protected]>
Refresh the base schema gold now that the agent-era surface is gated, and regenerate the SDK clients and reference docs to match. Also drops a codegen file left orphaned by the go-programmer fixture rewrite. Signed-off-by: Alex Suraci <[email protected]>
The object-tools rewrite removed the ListMethods/SelectMethods/CallMethod surface but dagger mcp was never migrated, so a served module exposed no module methods at all: a bare LLM binds no tool objects. MCP now binds each served workspace module's main object through the canonical server (entrypoint constructors are not in the sugared schema), skipping constructors with required non-Workspace args, when nothing else is bound. Rewrite the MCP tests to the object-tools surface; the privileged variants are renamed since --env-privileged no longer has a core-API tool surface post-Env and now only gates module-less serving. (cherry picked from commit 8ebfaf3) Signed-off-by: Alex Suraci <[email protected]>
Workspace inheritance leaked into dependencies: a module's deps picked up the caller's workspace, so a dep resolved its own module context against the wrong tree. Stop inheriting into deps while keeping the frozen per-client workspace inherited where it is still correct, and rewrite the propagation section of the design doc to describe the resulting rule. Signed-off-by: Alex Suraci <[email protected]>
Surface the Anthropic thinking blocks the provider already returns, and let several Changeset-returning tools run in one turn: each changeset is applied to the workspace overlay in call order instead of the last one winning. Signed-off-by: Alex Suraci <[email protected]>
LLM spans were emitted with telemetry.Reveal() so they would surface at the top level. The TUI now surfaces the conversation itself, so revealing every individual span double-counts them and fights the transcript rendering. Drop Reveal() from the LLM, display, and mod-tree spans. Signed-off-by: Alex Suraci <[email protected]>
Loading an ID from its recipe evaluates every argument eagerly: the loader walks each argument literal, gathers the IDs it depends on, and resolves them all before the field's resolver ever runs. That is necessary in general — reconstructing a receiver's state usually needs real argument values — but it is wrong for an argument whose value the resolver never dereferences. Add lazy reference args for those. An argument marked LazyRef is skipped when gathering recipe inputs, carried into the frame in pure recipe form, and decoded for the selector straight from the recipe ID's literals, so it reaches the resolver as an unevaluated ID rather than a result that was intentionally never produced. The resolver loads the referenced object itself, only if and when it needs the value. This lets a session be resumed even when it carries stale data or content that would fail to evaluate — conflict markers, for instance, which would otherwise break any tool that builds or starts something. The marking is resolved from the schema by receiver type and field without evaluating anything, and is best-effort: if the type is not currently installed, the argument is treated as normal. Signed-off-by: Alex Suraci <[email protected]>
LLM.withTools binds an object only to expose its type's methods as tools; the value itself is never dereferenced when the conversation is reconstructed. Mark the object argument LazyRef so restoring a persisted session does not re-run the call that produced it — which may have side effects, or may no longer be reproducible. boundTool holds the binding as an unevaluated ID plus the object's GraphQL type, so the toolset can be built without loading anything. The object is loaded on first dispatch, when a tool is actually invoked on it. Signed-off-by: Alex Suraci <[email protected]>
Replaying a conversation lost most of what the TUI needs to render it: tool arguments were dropped, thinking blocks were not re-emitted, the server was not set on the replayed LLM, and each tool call produced a redundant extra span. Keep the arguments as span attributes, re-emit thinking, set the server, collapse the duplicate span, and set the LLM call digest so the TUI can group a call with its result. Tool output previews are also trimmed to the last 8 lines instead of 100. Signed-off-by: Alex Suraci <[email protected]>
loadWorkspaceArg had two identical callerInModuleFunction guards — a rebase artifact — with one placed before the bound-workspace check. A generator/check leaf's auto-injected Workspace! is resolved while running inside the module runtime, so callerInModuleFunction is true at that point. The misplaced first guard short-circuited with the "workspace arguments are not inherited by module runtime calls" error before the seeded bound workspace was ever consulted, so the leaf fell back to stale (frozen) source. The visible symptom: an agent edits files, runs its `generate` tool (which rolls up and runs Workspace.generators), and the edit has no effect — e.g. removing an API from core/schema/ left docs:references unchanged, because the overlay never reached the generator. Fix: check the bound workspace (WorkspaceFromContext) first, then apply the single callerInModuleFunction guard as the fallback. This matches the design in hack/designs/workspace-agents.md §4 and the surviving comment. It does not weaken cross-module isolation: the overlay is explicit (the group threaded it via WorkspaceToContext), not silent inheritance. Add TestGeneratorSeesOverlayEdits to TestLLM, with a gen-agent fixture: a workspace whose module exposes write + generate tools and a @generate generator. The canned conversation edits input.txt, runs generate, and asserts the generator observed the overlay ("generated from: B-OVERLAY") rather than the frozen base. Verified the test fails when the bug is reintroduced. (cherry picked from commit 7fb7cd3) Signed-off-by: Alex Suraci <[email protected]>
NewLLM captured the calling context's currentWorkspace imperatively, invisible to the LLM's recipe. That ambient inheritance is how a module function returning a bare llm() picked up the caller's live workspace (the doug2 dead-client bug), and it made LLM IDs lie about what they were bound to. Start the LLM with no workspace instead. Binding one is now always the caller's explicit choice via LLM.withWorkspace, recorded as a selector on the ID. An unbound LLM remains valid: MCP.Server already falls back to the current client's served deps. Signed-off-by: Alex Suraci <[email protected]>
dagger mcp served llm().__mcp and relied on the ambient workspace capture to expose the workspace's schema over MCP. Resolve the current workspace and bind it explicitly on the served LLM instead. Signed-off-by: Alex Suraci <[email protected]>
The cross-session gating fixture returned a bare llm, relying on the ambient workspace capture that no longer exists. Take the auto-injected Workspace! arg and bind it explicitly — the calling session's live workspace still ends up embedded in the cached LLM, so the test guards the same dead-client regression through the explicit path. Signed-off-by: Alex Suraci <[email protected]>
go-programmer and gen-agent constructed a bare llm and relied on the ambient workspace for their Workspace!-typed tools. Take ws as an explicit arg on run/drive (auto-injected at the CLI boundary, passed explicitly module-internally) and bind it with withWorkspace. The replay recordings are unaffected: they diff message text only, and the prompts are unchanged. Signed-off-by: Alex Suraci <[email protected]>
llm() no longer inherits the ambient workspace, so the CLI states its intent on the ID: a fresh prompt-mode LLM chains withWorkspace(currentWorkspace). Resume needs no change in principle: a saved recipe's withWorkspace(currentWorkspace) node replays through the cache lookup and re-resolves against the resuming session's live workspace. Signed-off-by: Alex Suraci <[email protected]>
The parallel-changeset shell pipeline relied on the ambient binding llm() no longer performs; give it an explicit with-workspace $(current-workspace) stage. The unbound-LLM error message stops claiming a default binding exists. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Setting Server to the bound type name for replay span fidelity (2717ed8) made CallBatch treat object tools as MCP server tools, since it used a non-empty Server as the discriminator. Parallel Changeset-returning calls then skipped callBatchChangesets, fell through callBatchMCPServer's unknown-server fallback into plain parallel execution, and each call applied its changeset directly to the workspace — last writer wins, dropping the other tool's changes. It also lost the sequential guarantee for destructive object tools. Route on membership in mcpServers instead, so Server stays display metadata for tools that aren't backed by a registered MCP server. Signed-off-by: Alex Suraci <[email protected]>
Generator spans stopped setting `reveal` along with the rest of the mod-tree spans, which broke the generate-fail golden: the failed generator row and its rolled-up exec stderr vanished from the report. Instead of restoring reveal, detect Generate spans structurally, the way checks, tests, and conversations already surface. dagui gains SurfacedGenerators -- a reveal-independent tree keyed on the GeneratorName marker with the same boundary/severed-chain containment as checks, deduped by name, failed-first -- plus HasGenerators and PromoteGeneratorsTo for the live tree. The final report renders a GENERATORS section in lockstep with CHECKS/TESTS; a failed leaf generator renders its own rolled-up logs and error (the changeset is forced inside the generator span, so its log buffer is the exec failure), deferring to explicit ErrorOrigins links when present rather than hunting descendants, which repeated the generator's row and surfaced runc internals. Live, promoteGeneratorsLocked wires the surfaced tree into the host's RevealedSpans and marks it Passthrough, keeping skipped-module rows visible alongside. The FinalRender persistence gate, report-only log prefetch, SurfacedFailedCheckSpans, and the root-cause suppression guard all learn about generators, and the generate-fail golden is regenerated to the new sectioned shape with the same failure content. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Rebasing onto main picked up Query.volume (#13719), whose additions to the schema and every client collided with this stack's own generated output. The conflicts were resolved by regenerating rather than merging by hand, so this is codegen output only - no hand edits. Signed-off-by: Alex Suraci <[email protected]>
grouville
approved these changes
Aug 5, 2026
grouville
left a comment
Member
There was a problem hiding this comment.
Approving eagerly, everything LGTM apart the LLM edge case I found and documented on the comment
|
|
||
| changed = true | ||
| syncedLLMQ = syncedLLMQ. | ||
| Select("withObject"). |
Member
There was a problem hiding this comment.
Looks like syncing an object-typed shell variable into the LLM still uses withObject, which no longer exists.
I was able to reproduce it against the dev engine:
./hack/with-dev ./bin/dagger shell
obj=$(container)
● ✔ obj=$(container) 0.0s
# press > to switch to prompt mode, then submit a prompt
gpt-5.6 ❯ hello
Error: returned error 422: Cannot query field "withObject" on type "LLM".After assigning the object, switching to prompt mode, and typing hello, GraphQL validation fails before the prompt can run. I think this should use withTools(object: ...) instead.
Contributor
Author
There was a problem hiding this comment.
Ah, yeah makes sense - that code all gets ripped out in #13780 so I didn't catch it. I'll remove it from this PR so we can merge it independently.
Remove syncVarsToLLM/syncVarsFromLLM instead of porting the object-var loop to withTools. Binding every object-typed shell var as a toolset was a holdover from the tagged-value Env model and no longer makes sense now that objects reach the LLM as tools bound to the workspace. The two useful side effects buried in syncVarsToLLM survive inline in WithPrompt: picking up a reassigned $agent var as the LLM to prompt, and initializing the beforeFS baseline for the "Changes" preview. Also drop the now-unused skipEnv/syncedVars session state, the lastValueVar const, and the DAGUI_DEBUG dbg logger whose only caller was the sync loop. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The headline of the stack: the LLM becomes a workspace-bound agent, and
Env/Bindingare deleted entirely — taking with them the engine's last dynamically-extended core schema surface.hack/designs/workspace-agents.mddocuments the as-built design.The LLM binds to a Workspace
The LLM binds to the same
Workspacea CLI user sees, and its tools are generated from the objects bound viaLLM.withTools:llm()starts unbound; a workspace arrives only viaLLM.withWorkspace, recorded as a selector on the ID, so an LLM's ID never lies about what it is bound to.daggerprompt mode chainswithWorkspace(currentWorkspace)at session start,dagger mcpbinds it on the served LLM, and a module function returning an LLM threads aWorkspaceit was handed. An unbound LLM stays valid —MCP.Serverfalls back to the current client's served deps.Changesetapplies to the workspace overlay, aWorkspacerebinds the LLM's workspace, and any other object syncs and returns its logs. SeveralChangeset-returning tools may run in one turn; their changesets apply to the overlay in call order rather than last-writer-wins.Workspace!-typed args auto-inject from the binding and never appear in tool schemas. A module function's contextual (+defaultPath) arguments resolve against the bound workspace too, anchored at its root.Workspace.exporttouches disk.Query.currentNodelets a module's agent entrypoint bind its live receiver (withTools(currentNode)), since aselfreconstructed from serialized state has no engine-side identity.dagger mcpis migrated onto the same path: with nothing else bound, MCP binds each served workspace module's main object through the canonical server, so a served module exposes its methods again after the removal ofListMethods/SelectMethods/CallMethod.Lazy reference args
Restoring a persisted session must not re-run the calls that built the objects bound as tools — they may have side effects, or may no longer be reproducible (a workspace carrying conflict markers, say, would break any tool that builds or starts something).
withToolswas already lazy on the live path: its resolver takes an ID, andboundToolkeeps that ID plus the object's GraphQL type, loading the object only on first dispatch. But that laziness is downstream of the problem. Loading an ID from its recipe evaluates every argument eagerly — the loader walks each argument literal, gathers the IDs it depends on, and resolves the whole transitive DAG before the field's resolver runs. It has no way to know the resolver only wants a type name.So dagql grows
LazyRef: an argument marked with it is skipped when gathering recipe inputs, carried into the frame in pure recipe form, and decoded for the selector straight from the recipe ID's literals, so it arrives at the resolver as an unevaluated ID. The marking is resolved from the schema by receiver type and field without evaluating anything, and is best-effort — an argument on a type that is not currently installed is treated as normal.Env and Binding are gone
With the workspace supplying mutable state and scope, and object tools supplying tool generation,
Envloses its last responsibility.Env,Binding, their schemas, the prompt I/O machinery (inputs/outputs,Save,DeclareOutput,$VARexpansion), the nested-clientEnvContextplumbing, docs, and SDK surface are all deleted.That removal also eliminates a source of dynamic core schema behavior:
EnvandBindingwere the two core types whose fields were generated per installed type (Env.with<Type>Input/Output,Binding.as<Type>), meaning the core schema changed shape depending on which modules were loaded. Codegen'sExtendableTypesis now justQuery.Workspace propagation: seeding, not inheritance
The LLM's in-session overlay makes the bound workspace diverge from the frozen per-client one, which exposed every place the engine assumed those were the same. The rule this branch settles on — matching the direction
maintook in #13229 — is that a workspace is seeded into a call chain and otherwise passed explicitly; it is never carried implicitly across a module boundary.currentWorkspaceprefers a context-bound workspace over the session's frozen one. Group runs (checks/generators/agents/services) already re-seeded the workspace they were rolled up from (Workspace & Directory APIs: patch conflicts, overlay search, path removal #13777), butloadWorkspaceArgconsulted itscallerInModuleFunctionguard before the bound workspace — and a group leaf's auto-injectedWorkspace!resolves while running inside the module runtime, so the seeded workspace was rejected and the leaf read stale, frozen source. The visible symptom: an agent edits a file, runs itsgeneratetool, and the edit has no effect. Checking the bound workspace first fixes it (TestGeneratorSeesOverlayEdits).Workspaceexplicitly; an omitted auto-injectedWorkspace!errors rather than silently falling back to the caller's workspace. An earlier revision of this branch did carry the binding across nested module clients (aWorkspaceContextalongside the receiver object, plus a server-sideCurrentWorkspaceContextfallback); that leaked into dependencies, which then resolved their own module context against the caller's tree, and it has been removed along with the now-redundantisModuleRuntimeClientinheritance guard. The explicit-pass gate inloadWorkspaceArgis the single place this is enforced.Also in here
telemetry.Reveal()now that the TUI surfaces the conversation itself. SettingServerfor that fidelity madeCallBatchmistake object tools for MCP server tools; batching now routes on membership inmcpServersinstead.Generatespans structurally rather than viareveal:daguigains aSurfacedGeneratorstree keyed on the generator marker (same boundary/severed-chain containment as checks), and the final report grows aGENERATORSsection alongsideCHECKS/TESTS, with failed leaf generators rendering their own rolled-up logs and error.withWorkspace,workspace,contextTokens,Query.currentNode) is gated to v1 clients; the Java SDK marshals interface-typed args by ID, which the object-tools call path depends on; tests, fixtures, and docs are reworked from the Env era to the workspace/object-tools world.Note on session resources
An earlier revision of this branch gated client-owned workspace results behind a per-client session-resource handle, so a cached result embedding a workspace could only be served to the session that created it. That handle has been dropped, along with its dagql value-scoping support in #13776.
It was a point fix for one instance of a broader class — state pinned to a client session that has since gone away — and resume was observed to break through other members of that class even while the workspace survived. Dropping it is safe here because module calls taking
Workspace!args are session-unique by construction: the injectedcurrentWorkspaceID carries a per-call nonce, so those calls are never shared across sessions, and cross-session sharing rides only on returned-module-object content digests, which carry no client binding.TestWorkspaceBoundLLMAcrossSessionscovers this and passes without the handle. The genericSessionResourceHandleused by secrets and sockets is untouched.