装饰器 API 参考
@llm_function
LLMFunction callable instance。await fn(...) 返回解析后的类型化结果;fn.stream(...) 产出 ReactOutput。
对于多模态输入,llm_function 保持普通 Python 函数风格:显式把图片参数标注为 ImgUrl、ImgPath,或包含这些类型的列表/Union。ImgUrl 支持 http(s) URL 与 data: URL;ImgPath 会在 provider 边界编码为图片 data URL。
参数
特殊调用时参数
示例
@llm_chat
LLMChat callable instance。调用它会产出 AsyncGenerator[ReactOutput, None],并为 SelfRef 提供稳定的 agent identity。
对于多模态 chat 输入,推荐使用单个显式的 message: UserChatMessage 参数。UserChatMessage 兼容 OpenAI Chat Completions user message,可以包含 text 与 image_url content parts。
参数
特殊调用时参数
History 参数
函数必须具有名为history 或 chat_history 的参数(类型:list | None)。框架使用该参数来承载对话状态。
示例
多模态 Chat 示例
@tool
参数
要求
- 被装饰的函数必须是
async def - 文档字符串应包含
Args、Returns和Best Practices部分 - 参数类型将成为工具的 JSON schema