跳到主内容
精选80Claude Agent SDK Python(GitHub Releases)AI 编程与模型

Claude Agent SDK Python v0.2.137:新增会话重置与消息来源

v0.2.137

原文
推荐理由

SDK 用户注意:v0.2.137 扩大了 Message 联合类型,用 assert_never 做穷尽匹配的代码会编译失败,需更新;同时新增的 resume_session_at 支持安全回退到上一轮提示之前,建议升级体验。

New Features

新功能

  • ConversationResetMessage for conversation reset events: The SDK now surfaces the CLI's conversation_reset frame as a ConversationResetMessage dataclass, letting applications detect when a /clear or other transcript-discarding flow resets the conversation mid-session. Includes new_conversation_id, uuid, and session_id fields. This widens the Message union — code that exhaustively matches with assert_never will need updating (#1196)
  • Message origin on UserMessage and ResultMessage: New origin: MessageOrigin | None field on UserMessage and ResultMessage surfaces why a turn was initiated — distinguishing application-submitted prompts ("human") from background-task notifications, scheduled triggers, peer messages, and other session-injected turns. New exported types: MessageOrigin, MessageOriginKind, TaskNotificationOriginSubkind (#1199)
  • resume_session_at / resume_drops_turn options for truncating resume: ClaudeAgentOptions now supports resume_session_at (fork a session at an earlier transcript entry) and resume_drops_turn (validate that only entries from a specific turn are discarded). Enables safe rewind-to-before-last-prompt without silently dropping unobserved messages (#1198)
  • 用于会话重置事件的 ConversationResetMessage:SDK 现在将 CLI 的 conversation_reset 帧作为 ConversationResetMessage 数据类呈现,让应用程序能够检测 /clear 或其他丢弃转录的流程何时在会话中途重置会话。包含 new_conversation_id、uuid 和 session_id 字段。这扩展了 Message 联合类型——使用 assert_never 进行穷尽匹配的代码需要更新 (#1196)
  • UserMessage 和 ResultMessage 上的消息来源:UserMessage 和 ResultMessage 上新增的 origin: MessageOrigin | None 字段揭示了回合发起的原因——区分应用程序提交的提示(“human”)与后台任务通知、计划触发器、对等消息以及其他会话注入的回合。新增导出类型:MessageOrigin、MessageOriginKind、TaskNotificationOriginSubkind (#1199)
  • 用于截断恢复的 resume_session_at / resume_drops_turn 选项:ClaudeAgentOptions 现在支持 resume_session_at(在较早的转录条目处派生会话)和 resume_drops_turn(验证仅丢弃来自特定回合的条目)。支持安全地回退到最后一个提示之前,而不会静默丢弃未观察到的消息 (#1198)

Bug Fixes

错误修复

  • Seed settings.json into temp config dir on SessionStore resume: Resuming from a SessionStore now copies settings.json and cowork_settings.json into the temporary config directory, preserving apiKeyHelper auth, user hooks, env vars, and permissions. Previously, hosts authenticating solely via apiKeyHelper would fail with "Not logged in" on resume (#1197)
  • Improved error messages for failed resume: When the CLI rejects a resume (e.g. nonexistent session or resume_drops_turn guard failure), pending control requests like initialize() now receive the actual error text instead of a generic "Command failed with exit code 1" (#1198)
  • 在 SessionStore 恢复时将 settings.json 种子化到临时配置目录:从 SessionStore 恢复现在会将 settings.json 和 cowork_settings.json 复制到临时配置目录,保留 apiKeyHelper 认证、用户钩子、环境变量和权限。以前,仅通过 apiKeyHelper 进行认证的主机在恢复时会失败并显示“未登录” (#1197)
  • 改进恢复失败时的错误消息:当 CLI 拒绝恢复(例如,会话不存在或 resume_drops_turn 保护失败)时,挂起的控制请求(如 initialize())现在会收到实际的错误文本,而不是通用的“命令失败,退出代码 1” (#1198)

Internal/Other Changes

内部/其他更改

  • Updated bundled Claude CLI to version 2.1.229
  • 更新捆绑的 Claude CLI 至版本 2.1.229

PyPI: https://pypi.org/project/claude-agent-sdk/0.2.137/

PyPI:https://pypi.org/project/claude-agent-sdk/0.2.137/

代码 · 1
pip install claude-agent-sdk==0.2.137
代码 · 1
pip install claude-agent-sdk==0.2.137

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近