@llm_function
@llm_function turns a Python function signature into a complete LLM call. One input, one typed output. No history, no tools (or tools with auto-loop), no state management.
Basic Usage
How the System Prompt Is Built
Your docstring is the starting point, but the framework augments it:- Your docstring → task policy, quality bar, constraints
- Parameter types → automatically described for the model
- Return type schema → output format instructions (XML-based structured extraction)
- Tool best practices → prepended if tools are mounted
Return Types
Pydantic Models (recommended for structured output)
Plain str (for free-form text)
Lists and nested types
Primitive types
Template Parameters
Inject runtime values into the docstring:Multimodal Image Parameters
@llm_function keeps the normal Python-function shape for image input: declare explicit image parameters in the function signature.
ImgUrl for web URLs or data: URLs. Use ImgPath for local files; the framework encodes the image as a data URL before sending it to the model. Multiple images should be expressed as explicit parameters or typed lists such as list[ImgUrl] / list[ImgPath].
With Tools
@llm_function can use tools via a ReAct loop:
max_tool_calls limits how many tool calls the model can make. None means unlimited.
Event Stream Mode
@llm_function returns an LLMFunction callable instance. Normal calls use await fn(...); use fn.stream(...) for ReactOutput:
AbortSignal
Cancel a running call:Parameters Reference
| Parameter | Type | Default | Description |
|---|---|---|---|
llm_interface | LLM_Interface | required | The model to call |
toolkit | List[Tool] | None | Tools the model can use |
max_tool_calls | int | None | None | Max tool calls before forcing final answer |
system_prompt_template | str | None | None | Override system prompt template |
user_prompt_template | str | None | None | Override user prompt template |
**llm_kwargs | Any | — | Passed to the LLM (temperature, etc.) |
_):
_template_params: Dict[str, Any]— template values for docstring formatting_abort_signal: AbortSignal— cancellation signal