Documentation Index
Fetch the complete documentation index at: https://simplellmfunc.cn/llms.txt
Use this file to discover all available pages before exploring further.
Runtime Patches
ContextMutation is SimpleLLMFunc’s internal typed patch protocol for transcript edits produced by runtime side effects.
Mutations do not define the whole context. The final LLM request is compiled from:
- invocation configuration — docstring prompt, template parameters, tool guidance, output contract, SelfRef snapshot;
- a base transcript/message list — history, current user input, previous assistant/tool messages;
- runtime patches — the
ContextMutationobjects described on this page.
history, and SelfRef primitives.
The Mutation Union
Standard Flow Patches
These are produced during normal ReAct loop operation.AssistantMessageMutation
Emitted when the LLM produces a response (text, tool calls, or both).Effect: Appends an assistant message to the transcript.
Producer:
execute_single_llm_phase() in the ReAct loop.
ToolResultMutation
Emitted when a tool finishes execution with a text result.Effect: Appends a tool result message linked to its call by
tool_call_id.Producer:
schedule_tool_batch() → tool execution.
MultimodalToolResultMutation
Emitted when a tool returns images or mixed content that can’t be represented as a simple string.ImgPath, ImgUrl, or a tuple containing multimodal content.Effect: Replaces the tool call with an assistant summary message + user messages containing the multimodal content. This restructuring is required because most providers only support images in user messages.
Producer:
schedule_tool_batch() with multimodal tool returns.
UserMessageMutation
Emitted when a new user message needs to be injected mid-loop.Effect: Appends a user message to the transcript.
Producer: Custom hooks,
AgentInputRouter.
Context Reset Patches
These replace or restructure the working transcript.ContextReplaceMutation
Hard reset — replaces the entire message list.Effect: Discards the current transcript entirely, replaces with
messages.Producer: SelfRef fork spawn (to set child context), custom hooks.
ContextSummaryMutation
Context compaction — replaces transcript with a summary and optionally stores new experiences.runtime.selfref.context.compact(...) is called from a tool.Effect:
- Preserves the system prompt message
- Replaces the working transcript with
summary_message - Stores any items in
rememberas durable experiences
compact primitive.
Experience Patches
These update durable experiences stored in the system context (via SelfRef).ExperienceRememberMutation
Store a new durable experience.runtime.selfref.context.remember(...) is called.Effect: Adds the text as a new experience entry in the system context’s experience section.
Producer: SelfRef
remember primitive.
ExperienceForgetMutation
Remove a stored experience by ID.runtime.selfref.context.forget(...) is called.Effect: Removes the experience with the matching ID from the system context.
Producer: SelfRef
forget primitive.
Abort Patches
These handle interruption and cancellation.AssistantTruncatedMutation
Records a partially-received assistant response that was interrupted.AbortSignal fires while the LLM is streaming.Effect: Appends the partial content as an assistant message with truncation metadata.
Producer:
execute_single_llm_phase() on abort.
ToolCancelledMutation
Records a tool call that was aborted before completion.AbortSignal fires while tools are executing.Effect: Appends a cancelled-tool result message so the transcript remains structurally valid (every tool call has a corresponding result).
Producer:
schedule_tool_batch() on abort.
Mutation Application Order
Mutations are applied sequentially in the order they were produced. Within a single ReAct iteration:- Hook mutations (from SelfRef session
collect_context_mutations) — applied first - LLM mutations (AssistantMessage) — from the LLM call
- Tool mutations (ToolResult, MultimodalToolResult, Experience*) — from tool execution
- Abort mutations (AssistantTruncated, ToolCancelled) — if interruption occurred
The Guarantee
Runtime-produced transcript edits go through this patch protocol. This means LLM calls, tool execution, SelfRef primitives, and abort handling do not directly mutate the live transcript. This does not mean every LLM-visible input comes from a mutation. The initial transcript, docstring/system prompt, template parameters, tool guidance, and SelfRef snapshot are separate compile inputs.Next: Compile Pipeline
How invocation config, transcript, and runtime patches are transformed into the final LLM request.