LLM
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
No description
returns the type of the current state
The model's total context window in tokens, or null if unknown (e.g. a local or uncatalogued model).
Fork the conversation, so that otherwise-identical follow-ups evaluate independently instead of deduplicating to a single cached result.
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.
The text of the model's most recent reply.
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.
The full message history, as structured messages.
The model the conversation is running against, after resolving any configured default.
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 provider serving the model, e.g. "anthropic", "openai", "google", or "local".
Re-emit telemetry spans for the full message history, so a loaded conversation displays in the TUI.
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.
Force evaluation of the conversation's pending operations (prompts, steps, loops) in the engine.
The cumulative token usage, summed across every API call in the conversation.
Render documentation for the tools currently exposed to the model.
The message history rendered as a plain-text transcript, suitable for feeding back to an LLM (e.g. for summarization).
Return a new LLM with the specified function no longer exposed as a tool
Change the model for the rest of the conversation. The message history is preserved; the new model takes effect on the next step.
Track an object so the LLM can reference it in subsequent tool calls.
Queue a user prompt, to be sent to the model on the next step or loop.
Append an assistant response to the message history without calling the model, e.g. to reconstruct a conversation from another source.
Use a static set of tools for method calls, e.g. for MCP clients that do not support dynamic tool registration
Add a system prompt, instructing the model across the whole conversation.
Append the result of a tool call to the message history.
Disable the default system prompt
Clear the message history, keeping only the system prompts.
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
in
AbstractObject at line 19
protected null|array|string|int|float|bool
queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)
No description
at line 19
Binding
bindResult(string $name)
returns the type of the current state
at line 29
int
contextWindow()
The model's total context window in tokens, or null if unknown (e.g. a local or uncatalogued model).
at line 38
Env
env()
return the LLM's current environment
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.
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.
at line 66
Id
id()
A unique identifier for this LLM.
at line 75
string
lastReply()
The text of the model's most recent reply.
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.
at line 99
array
messages()
The full message history, as structured messages.
at line 108
string
model()
The model the conversation is running against, after resolving any configured default.
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.
at line 126
string
provider()
The provider serving the model, e.g. "anthropic", "openai", "google", or "local".
at line 135
LLM
replay()
Re-emit telemetry spans for the full message history, so a loaded conversation displays in the TUI.
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.
at line 157
Syncer
sync()
Force evaluation of the conversation's pending operations (prompts, steps, loops) in the engine.
at line 167
LLMTokenUsage
tokenUsage()
The cumulative token usage, summed across every API call in the conversation.
at line 176
string
tools()
Render documentation for the tools currently exposed to the model.
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).
at line 194
LLM
withBlockedFunction(string $typeName, string $function)
Return a new LLM with the specified function no longer exposed as a tool
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.
at line 239
LLM
withObject(string $tag, Id $object)
Track an object so the LLM can reference it in subsequent tool calls.
at line 250
LLM
withPrompt(string $prompt)
Queue a user prompt, to be sent to the model on the next step or loop.
at line 260
LLM
withPromptFile(File $file)
Queue a file's contents as a user prompt, like withPrompt.
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.
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
at line 310
LLM
withSystemPrompt(string $prompt)
Add a system prompt, instructing the model across the whole conversation.
at line 320
LLM
withToolResult(string $callId, string $content, bool $errored)
Append the result of a tool call to the message history.
at line 332
LLM
withoutDefaultSystemPrompt()
Disable the default system prompt
at line 341
LLM
withoutMessageHistory()
Clear the message history, keeping only the system prompts.
at line 350
LLM
withoutSystemPrompts()
Clear the user-added system prompts, keeping only the default system prompt.