Documentation Index
Fetch the complete documentation index at: https://simplellmfunc.cn/llms.txt
Use this file to discover all available pages before exploring further.
Context Overview
This page explains how SimpleLLMFunc compiles context — the information the LLM sees at each reasoning step. The final provider-facing message list is built from invocation configuration, a base transcript, and internal runtime patches.The Core Data Structures
ContextState
The runtime representation of a conversation’s current state:messagesis the base transcript for the current runtime state — assistant messages, tool results, user messagesdata_from_selfrefcarries durable state from the SelfReference backend (experiences, summaries)pending_mutationsaccumulates internal runtime patches during a ReAct iteration, applied to the transcript at the next compile boundary
CompileSource
The input boundary — everything needed to produce an LLM request:DataFromAgentConfig
Static configuration from the decorator:DataFromSelfRef
Durable state from the SelfReference backend:Context Inputs
SimpleLLMFunc does not build LLM context from mutations alone. Each LLM request is compiled from three inputs:- Invocation configuration — the
InvocationSpec/ prompt contract built from the decorated function, docstring, template parameters, tool guidance, return mode, and SelfRef snapshot. - Base transcript — the message list created from
history/chat_history, the current user input, and the previous finalized messages. - Runtime patches —
ContextMutationobjects produced internally by LLM calls, tools, SelfRef primitives, compaction, and abort/cancel handling.
Data Flow: From Your Code to the LLM
The Key Invariants
-
Runtime side effects do not edit the live transcript directly — LLM calls, tools, SelfRef primitives, and abort handling produce
ContextMutationpatches instead of mutatingContextState.messagesin place. - Mutations are transcript patches, not the whole context — docstrings, template params, tool guidance, SelfRef snapshots, and initial history come from invocation configuration and the base transcript.
-
Mutations accumulate, then apply atomically — During a ReAct iteration, runtime patches collect in
pending_mutations. They’re applied together at the compile boundary. - Compile produces a snapshot — The compiled output is a clone. The original state is never mutated in place.
-
SelfRef state propagates —
DataFromSelfRefis carried forward through compilations. If selfref markers are detected in the transcript after mutation application, the snapshot is refreshed. -
System prompt resolution has priority order:
- SelfRef snapshot (if present) → renders base prompt + experiences
- PromptContract.system_prompt (if set explicitly)
- Latest system message in transcript
- PromptContract.base_instruction (docstring fallback)
Next Steps
Runtime Patches
The internal mutation types — when runtime effects produce transcript patches.
Compile Pipeline
How invocation config, transcript, and patches become the final LLM request.