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

bindResult(string $name)

returns the type of the current state

int
contextWindow()

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

Env
env()

return the LLM's current environment

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.

string
provider()

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

LLM
replay()

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

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
withBlockedFunction(string $typeName, string $function)

Return a new LLM with the specified function no longer exposed as a tool

LLM
withEnv(Env $env)

allow the LLM to interact with an environment via MCP

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
withObject(string $tag, Id $object)

Track an object so the LLM can reference it in subsequent tool calls.

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
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
withStaticTools()

Use a static set of tools for method calls, e.g. for MCP clients that do not support dynamic tool registration

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
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.

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
Binding bindResult(string $name)

returns the type of the current state

Parameters

string $name

Return Value

Binding

at line 29
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 38
Env env()

return the LLM's current environment

Return Value

Env

at line 47
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 57
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 66
Id id()

A unique identifier for this LLM.

Return Value

Id

at line 75
string lastReply()

The text of the model's most recent reply.

Return Value

string

at line 84
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 99
array messages()

The full message history, as structured messages.

Return Value

array

at line 108
string model()

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

Return Value

string

at line 117
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.

Return Value

Id

at line 126
string provider()

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

Return Value

string

at line 135
LLM replay()

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

Return Value

LLM

at line 145
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 157
Syncer sync()

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

Return Value

Syncer

at line 167
LLMTokenUsage tokenUsage()

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

Return Value

LLMTokenUsage

at line 176
string tools()

Render documentation for the tools currently exposed to the model.

Return Value

string

at line 185
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 194
LLM withBlockedFunction(string $typeName, string $function)

Return a new LLM with the specified function no longer exposed as a tool

Parameters

string $typeName
string $function

Return Value

LLM

at line 205
LLM withEnv(Env $env)

allow the LLM to interact with an environment via MCP

Parameters

Env $env

Return Value

LLM

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

Add an external MCP server to the LLM

Parameters

string $name
Service $service

Return Value

LLM

at line 226
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 239
LLM withObject(string $tag, Id $object)

Track an object so the LLM can reference it in subsequent tool calls.

Parameters

string $tag
Id $object

Return Value

LLM

at line 250
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 260
LLM withPromptFile(File $file)

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

Parameters

File $file

Return Value

LLM

at line 270
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 301
LLM withStaticTools()

Use a static set of tools for method calls, e.g. for MCP clients that do not support dynamic tool registration

Return Value

LLM

at line 310
LLM withSystemPrompt(string $prompt)

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

Parameters

string $prompt

Return Value

LLM

at line 320
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 332
LLM withoutDefaultSystemPrompt()

Disable the default system prompt

Return Value

LLM

at line 341
LLM withoutMessageHistory()

Clear the message history, keeping only the system prompts.

Return Value

LLM

at line 350
LLM withoutSystemPrompts()

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

Return Value

LLM