class LLM extends AbstractObject implements IdAble, Node, Syncer

A conversation with a large language model (LLM): queue prompts, expose tools, and step the model until it completes its turn.

Properties

$lastQuery from  AbstractObject

Methods

__construct(AbstractClient $client, QueryBuilderChain $queryBuilderChain)

No description

null|array|string|int|float|bool
queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)

No description

int
contextTokens()

estimated number of tokens currently occupying the context window; unlike tokenUsage this is not cumulative over the session

int
contextWindow()

The model's total context window in tokens, or null if unknown (e.g. a local or uncatalogued model).

LLM
fork(string $label)

Fork the conversation, so that otherwise-identical follow-ups evaluate independently instead of deduplicating to a single cached result.

bool
hasPending()

Report whether anything is queued to send to the model: an unsent prompt or unevaluated tool results. When true, another step will do work; when false, the turn is complete.

Id
id()

A unique identifier for this LLM.

string
lastReply()

The text of the model's most recent reply.

LLM
loop(int|null $maxSteps = null, int|null $maxTokens = null)

Send the queued prompt and step the model against the available tools, until it ends its turn: a reply with no tool calls and nothing left queued.

array
messages()

The full message history, as structured messages.

string
model()

The model the conversation is running against, after resolving any configured default.

Id
portableID()

A portable, self-contained ID for the conversation that node() can resolve in any session. Unlike id, which may return an engine-local runtime handle valid only within the current session, this returns the recipe form suitable for persisting and later restoring the conversation. The recipe is flattened: bindings superseded during the session (workspace overlays recorded by each mutating tool call, and re-bound toolsets) are dropped, while the current workspace binding — including any pending, un-exported edits — is preserved.

string
provider()

The provider serving the model, e.g. "anthropic", "openai", "google", or "local".

string
reasoningEffort()

The reasoning effort in use, e.g. "low", "medium", or "high". Empty or "none" when reasoning is disabled.

LLM
replay()

Re-emit telemetry spans for the full message history, so a loaded conversation displays in the TUI.

array
skills()

The skills visible to the model, exactly as the ListSkills tool serves them: engine-embedded skills, skills installed with withSkills, and skills discovered in the workspace.

LLM
step(int|null $maxTokens = null)

Advance the conversation by a single step: send the queued prompt or tool results to the model, evaluate any tool calls it makes, and queue their results. Use loop to step until the model ends its turn.

sync()

Force evaluation of the conversation's pending operations (prompts, steps, loops) in the engine.

tokenUsage()

The cumulative token usage, summed across every API call in the conversation.

string
tools()

Render documentation for the tools currently exposed to the model.

string
transcript()

The message history rendered as a plain-text transcript, suitable for feeding back to an LLM (e.g. for summarization).

LLM
withMCPServer(string $name, Service $service)

Add an external MCP server to the LLM

LLM
withModel(string $model, string|null $provider = null)

Change the model for the rest of the conversation. The message history is preserved; the new model takes effect on the next step.

LLM
withPrompt(string $prompt)

Queue a user prompt, to be sent to the model on the next step or loop.

LLM
withPromptFile(File $file)

Queue a file's contents as a user prompt, like withPrompt.

LLM
withReasoningEffort(string $effort)

Change the reasoning effort for the rest of the conversation, overriding any configured default. The message history is preserved; the new effort takes effect on the next step.

LLM
withResponse(array $content, int|null $inputTokens = 0, int|null $outputTokens = 0, int|null $cachedTokenReads = 0, int|null $cachedTokenWrites = 0, int|null $totalTokens = 0)

Append an assistant response to the message history without calling the model, e.g. to reconstruct a conversation from another source.

LLM
withSkills(Directory $directory)

Install skills from a directory, adding them to the skills the model discovers with ListSkills and reads with ReadSkill. Each skill is a directory containing a SKILL.md with name and description frontmatter, discovered anywhere in the tree. Installed skills take precedence over skills discovered in the workspace, but cannot shadow the engine's built-in skills.

LLM
withSystemPrompt(string $prompt)

Add a system prompt, instructing the model across the whole conversation.

LLM
withToolResult(string $callId, string $content, bool $errored)

Append the result of a tool call to the message history.

LLM
withTools(Node $object, array|null $except = [])

Expose an object's methods as tools. Every eligible method of the bound object becomes a tool; a tool that returns this object's own type replaces it as the new state. Repeatable to bind several objects.

LLM
withWorkspace(Workspace $workspace)

Bind the LLM to a workspace, exposing its modules as tools exactly as the Dagger CLI would serve them for that workspace.

LLM
withoutDefaultSystemPrompt()

Disable the default system prompt

LLM
withoutMessageHistory()

Clear the message history, keeping only the system prompts.

LLM
withoutSystemPrompts()

Clear the user-added system prompts, keeping only the default system prompt.

workspace()

Return the workspace the LLM is bound to.

Details

in AbstractObject at line 13
__construct(AbstractClient $client, QueryBuilderChain $queryBuilderChain)

No description

Parameters

AbstractClient $client
QueryBuilderChain $queryBuilderChain

in AbstractObject at line 19
protected null|array|string|int|float|bool queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)

No description

Parameters

QueryBuilder $leafQueryBuilder
string $leafKey

Return Value

null|array|string|int|float|bool

at line 19
int contextTokens()

estimated number of tokens currently occupying the context window; unlike tokenUsage this is not cumulative over the session

Return Value

int

at line 28
int contextWindow()

The model's total context window in tokens, or null if unknown (e.g. a local or uncatalogued model).

Return Value

int

at line 37
LLM fork(string $label)

Fork the conversation, so that otherwise-identical follow-ups evaluate independently instead of deduplicating to a single cached result.

Parameters

string $label

Return Value

LLM

at line 47
bool hasPending()

Report whether anything is queued to send to the model: an unsent prompt or unevaluated tool results. When true, another step will do work; when false, the turn is complete.

Return Value

bool

at line 56
Id id()

A unique identifier for this LLM.

Return Value

Id

at line 65
string lastReply()

The text of the model's most recent reply.

Return Value

string

at line 74
LLM loop(int|null $maxSteps = null, int|null $maxTokens = null)

Send the queued prompt and step the model against the available tools, until it ends its turn: a reply with no tool calls and nothing left queued.

Parameters

int|null $maxSteps
int|null $maxTokens

Return Value

LLM

at line 89
array messages()

The full message history, as structured messages.

Return Value

array

at line 98
string model()

The model the conversation is running against, after resolving any configured default.

Return Value

string

at line 107
Id portableID()

A portable, self-contained ID for the conversation that node() can resolve in any session. Unlike id, which may return an engine-local runtime handle valid only within the current session, this returns the recipe form suitable for persisting and later restoring the conversation. The recipe is flattened: bindings superseded during the session (workspace overlays recorded by each mutating tool call, and re-bound toolsets) are dropped, while the current workspace binding — including any pending, un-exported edits — is preserved.

Return Value

Id

at line 116
string provider()

The provider serving the model, e.g. "anthropic", "openai", "google", or "local".

Return Value

string

at line 125
string reasoningEffort()

The reasoning effort in use, e.g. "low", "medium", or "high". Empty or "none" when reasoning is disabled.

Return Value

string

at line 134
LLM replay()

Re-emit telemetry spans for the full message history, so a loaded conversation displays in the TUI.

Return Value

LLM

at line 144
array skills()

The skills visible to the model, exactly as the ListSkills tool serves them: engine-embedded skills, skills installed with withSkills, and skills discovered in the workspace.

Return Value

array

at line 153
LLM step(int|null $maxTokens = null)

Advance the conversation by a single step: send the queued prompt or tool results to the model, evaluate any tool calls it makes, and queue their results. Use loop to step until the model ends its turn.

Parameters

int|null $maxTokens

Return Value

LLM

at line 165
Syncer sync()

Force evaluation of the conversation's pending operations (prompts, steps, loops) in the engine.

Return Value

Syncer

at line 175
LLMTokenUsage tokenUsage()

The cumulative token usage, summed across every API call in the conversation.

Return Value

LLMTokenUsage

at line 184
string tools()

Render documentation for the tools currently exposed to the model.

Return Value

string

at line 193
string transcript()

The message history rendered as a plain-text transcript, suitable for feeding back to an LLM (e.g. for summarization).

Return Value

string

at line 202
LLM withMCPServer(string $name, Service $service)

Add an external MCP server to the LLM

Parameters

string $name
Service $service

Return Value

LLM

at line 213
LLM withModel(string $model, string|null $provider = null)

Change the model for the rest of the conversation. The message history is preserved; the new model takes effect on the next step.

Parameters

string $model
string|null $provider

Return Value

LLM

at line 226
LLM withPrompt(string $prompt)

Queue a user prompt, to be sent to the model on the next step or loop.

Parameters

string $prompt

Return Value

LLM

at line 236
LLM withPromptFile(File $file)

Queue a file's contents as a user prompt, like withPrompt.

Parameters

File $file

Return Value

LLM

at line 246
LLM withReasoningEffort(string $effort)

Change the reasoning effort for the rest of the conversation, overriding any configured default. The message history is preserved; the new effort takes effect on the next step.

Parameters

string $effort

Return Value

LLM

at line 256
LLM withResponse(array $content, int|null $inputTokens = 0, int|null $outputTokens = 0, int|null $cachedTokenReads = 0, int|null $cachedTokenWrites = 0, int|null $totalTokens = 0)

Append an assistant response to the message history without calling the model, e.g. to reconstruct a conversation from another source.

Parameters

array $content
int|null $inputTokens
int|null $outputTokens
int|null $cachedTokenReads
int|null $cachedTokenWrites
int|null $totalTokens

Return Value

LLM

at line 287
LLM withSkills(Directory $directory)

Install skills from a directory, adding them to the skills the model discovers with ListSkills and reads with ReadSkill. Each skill is a directory containing a SKILL.md with name and description frontmatter, discovered anywhere in the tree. Installed skills take precedence over skills discovered in the workspace, but cannot shadow the engine's built-in skills.

Parameters

Directory $directory

Return Value

LLM

at line 297
LLM withSystemPrompt(string $prompt)

Add a system prompt, instructing the model across the whole conversation.

Parameters

string $prompt

Return Value

LLM

at line 307
LLM withToolResult(string $callId, string $content, bool $errored)

Append the result of a tool call to the message history.

Parameters

string $callId
string $content
bool $errored

Return Value

LLM

at line 319
LLM withTools(Node $object, array|null $except = [])

Expose an object's methods as tools. Every eligible method of the bound object becomes a tool; a tool that returns this object's own type replaces it as the new state. Repeatable to bind several objects.

Parameters

Node $object
array|null $except

Return Value

LLM

at line 332
LLM withWorkspace(Workspace $workspace)

Bind the LLM to a workspace, exposing its modules as tools exactly as the Dagger CLI would serve them for that workspace.

Parameters

Workspace $workspace

Return Value

LLM

at line 342
LLM withoutDefaultSystemPrompt()

Disable the default system prompt

Return Value

LLM

at line 351
LLM withoutMessageHistory()

Clear the message history, keeping only the system prompts.

Return Value

LLM

at line 360
LLM withoutSystemPrompts()

Clear the user-added system prompts, keeping only the default system prompt.

Return Value

LLM

at line 369
Workspace workspace()

Return the workspace the LLM is bound to.

Return Value

Workspace