Documentation Index
Fetch the complete documentation index at: https://simplellmfunc.cn/llms.txt
Use this file to discover all available pages before exploring further.
@llm_chat
@llm_chat creates a multi-turn conversational agent. It manages history, executes a ReAct loop with tools, streams responses, and optionally integrates with SelfRef for durable context.
Basic Usage
History Management
Thehistory parameter (or chat_history) is special. The framework:
- Takes your provided history as the conversation transcript
- Appends the current user message
- Runs the ReAct loop
- Returns updated history in
output.messages
Streaming
Withstream=True, you receive chunks as events:
stream=False, the model response arrives as a single ResponseYield.
Tools
- LLM decides to call a tool →
ToolCallStartEvent - Framework executes the tool →
ToolCallEndEvent - The runtime records the tool result as an internal transcript patch
- Context is recompiled → LLM sees the patched transcript → decides next action
max_tool_calls limits total tool calls per invocation. Default is framework-defined. None means unlimited.
SelfRef Integration
For agents that need durable memory, context compaction, or sub-agent forking:self_reference_key, the framework:
- Binds a
SelfReferencebackend to this key - Creates a
SelfRefSessionper invocation - Makes selfref primitives available in PyRepl
- Persists updated history after each turn
Template Parameters
Inject runtime values into the system prompt:Return Mode
| Mode | Behavior |
|---|---|
"text" (default) | output.response is the final text string |
"raw" | output.response is the raw message dict from the provider |
System Prompt Construction
For@llm_chat, the final system prompt is built from multiple sources:
- Docstring → base system prompt (with template params applied)
- Tool best practices →
<tool_best_practices>block prepended - Must principles →
<must_principles>block appended (use native tool calls) - SelfRef experiences → rendered into the system prompt if active
- Latest system message in history → overrides docstring if present
Concurrent Sessions
Multiple independent conversations can run simultaneously:Parameters Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
llm_interface | LLM_Interface | required | The model to call |
toolkit | List[Tool] | None | Available tools |
max_tool_calls | int | None | framework default | Tool call limit |
stream | bool | False | Enable streaming |
self_reference | SelfReference | None | None | Explicit selfref backend |
self_reference_key | str | None | None | Auto-create selfref for this key |
**llm_kwargs | Any | — | Passed to LLM (temperature, etc.) |
_template_params: Dict[str, Any]— template values_abort_signal: AbortSignal— cancellation_too_long_to_file: bool— truncate long tool results to file