LLM 0.32 发布:推理轨迹、服务端工具与结构化流式事件

Simon Willison2026-08-06 05:03

核心更新

LLM 0.32 发布,重点扩展了推理模型支持、服务端工具调用、日志存储和 Python API 能力。此次更新还同步推出了 llm-anthropic 0.26。

CLI:推理轨迹与服务端工具

使用推理模型时,LLM 现在会将推理轨迹输出到标准错误流。这样,常规回答仍可通过标准输出传递给其他命令行工具;如不需要显示推理过程,可使用 -R 或 --hide-reasoning。

新版本内置支持 GPT-5.6 系列模型,执行 llm "提示词" 时的默认模型调整为 GPT-5.6 Luna。

LLM 还支持调用不同提供商的服务端工具。例如,可通过 OpenAI 的代码执行环境查询当前 Python 与 SQLite 版本:

llm --tool CodeInterpreter 'Show current python and SQLite versions'

OpenAI 可使用 WebSearch 工具。llm-anthropic 0.26 则新增 WebSearch、WebFetch、CodeExecution 与 AnthropicMCP 等服务端工具。

例如,可让 Claude 在一次请求中通过 MCP 查询数据表行数:

llm -m claude-sonnet-5 -T 'AnthropicMCP("https://datasette.simonwillison.net/-/mcp")' \
  'how many rows in the blog_blogmark table?'

直接调用 OpenAI 兼容端点

新增的 llm openai endpoint 命令可直接向任意兼容 OpenAI API 的端点发送单次提示词,无须预先配置模型。这类调用不会写入日志,适合临时测试。

以下示例通过本地 LM Studio 运行 Gemma 4 12B,并加载 QuickJS 工具:

uvx --with llm-tools-quickjs \
  llm openai endpoint http://localhost:1234/v1 \
  -m google/gemma-4-12b \
  -T QuickJS 'Use QuickJS to multiply 3434 * 2434' --td

Python API:支持完整消息序列与事件流

此前,Python API 主要通过会话逐条发送消息。0.32 新增 model.prompt(messages=[]),可直接传入完整消息历史,更贴近大模型请求的实际结构。

import llm
from llm import assistant, system, user

model = llm.get_model("gpt-5.6-luna")
response = model.prompt(messages=[
    system("You are a helpful pirate."),
    user("What is the capital of France?"),
    assistant("Paris, matey."),
    user("And Germany?"),
])
print(response.text())

模型响应不再仅被视为字符串片段。新接口可通过 stream_events() 接收不同类型的事件,包括推理文本、常规输出、工具调用及图像附件等。

for event in model.prompt("Explain cats").stream_events():
    if event.type == "reasoning":
        print(f"[thinking] {event.chunk}", end="", flush=True)
    elif event.type == "text":
        print(event.chunk, end="", flush=True)
    else:
        print(f"Other event: {event}")

OpenAI Chat Completions 兼容服务

基于这些能力,llm-chat-completions-server 插件提供了 OpenAI Chat Completions API 的兼容实现:

llm install llm-chat-completions-server
llm chat-completions-server --port 9000

服务启动后,可通过兼容端点调用:

llm openai endpoint http://127.0.0.1:9000/v1 'hello' -m gpt-5.4-mini

日志改用内容寻址消息存储

对于每轮请求都携带完整消息历史的场景,重复保存整段 JSON 会造成冗余。LLM 0.32 引入了受 Git 启发的内容寻址消息存储,以减少重复记录。

llm logs 和 llm logs --json 已适配新格式,仍可将数据还原为便于查看和消费的输出。

插件与 Agent 能力

现有插件预计仍可继续使用,但提供额外模型的插件需要升级至 0.32,才能完整支持新的流式事件机制。

llm-anthropic 0.26 支持 Claude 5 系列模型及多项服务端工具。llm-gemini、llm-openrouter 和 llm-mistral 的相关更新仍在推进。

此外,工具链现可在执行中暂停等待人工批准,并可从已保存的消息历史恢复。这些能力使 LLM 更接近可组合的 Agent 基础设施:在一条命令中组合不同模型与不同工具,同时也可作为 Python 库构建更复杂的自动化系统。

评论

请登录后发表观点

暂无数据