Skip to main content

Decorators API Reference

@llm_function

Transforms an async function into an LLMFunction callable instance. await fn(...) returns the parsed typed result; fn.stream(...) yields ReactOutput. For multimodal input, keep the normal Python-function style: explicitly type image parameters as ImgUrl, ImgPath, or lists/unions containing those types. ImgUrl accepts http(s) URLs and data: URLs; ImgPath is encoded as an image data URL at the provider boundary.

Parameters

Special Call-Time Parameters

Example


@llm_chat

Creates an LLMChat callable instance. Calling it yields AsyncGenerator[ReactOutput, None] and gives SelfRef a stable agent identity. For multimodal chat input, prefer a single explicit message: UserChatMessage argument. UserChatMessage is OpenAI Chat Completions-compatible and can contain text and image_url content parts.

Parameters

Special Call-Time Parameters

History Parameter

The function must have a parameter named history or chat_history (type: list | None). The framework uses it to carry conversation state.

Example

Multimodal Chat Example


@tool

Registers an async function as a tool callable by the LLM. Can be used with or without arguments.

Parameters

Requirements

  • Decorated function must be async def
  • Docstring should include Args, Returns, and Best Practices sections
  • Parameter types become the tool’s JSON schema

Example


Tool Class

For programmatic tool creation without the decorator.

Methods

Properties