精选82Claude Agent SDK Python(GitHub Releases)AI 编程与模型
Claude Agent SDK Python v0.2.140:支持 MCP 2.x
v0.2.140
推荐理由
使用 Claude Agent SDK 的开发者注意:v0.2.140 带来 MCP 2.x 支持、ResultError 结构化异常和 forward_subagent_text 选项,建议升级以利用新能力并简化错误处理。
New Features
新特性
- MCP 2.x support for in-process SDK MCP servers: The SDK now supports mcp 2.x alongside 1.x (dependency widened to mcp>=1.23.0,<3.0.0). In-process servers are served over mcp's own in-memory transport instead of hand-rolled JSON-RPC dispatch, so hand-built mcp.server.Server instances now work at full fidelity — resources, prompts, and all result content types reach the CLI verbatim. Tool cancellation on interrupt is supported on mcp 2.x. claude_agent_sdk.ToolAnnotations accepts both camelCase and snake_case hint names on every mcp version (#1218)
- forward_subagent_text option: New forward_subagent_text boolean on ClaudeAgentOptions forwards a subagent's text and thinking blocks as messages in the stream, so consumers can render the full nested transcript. Matches the TypeScript SDK's forwardSubagentText (#1206)
- ResultError exception with structured error payload: When the CLI exits after a terminal error result, the SDK now raises ResultError (a subclass of ProcessError) instead of a bare "exit code 1" error. Carries subtype, errors, result, api_error_status, terminal_reason, session_id, and the raw data dict so callers can branch on failure reason without string matching. New exported types: ResultError (#1205)
- can_use_tool callback support for query() and string prompts: The can_use_tool permission callback now works with string prompts (not just ClaudeSDKClient), and stdin is kept open so the CLI can send permission requests over the control protocol (#1204)
- 对进程内 SDK MCP 服务器的 MCP 2.x 支持:SDK 现在支持 mcp 2.x 以及 1.x(依赖范围扩大至 mcp>=1.23.0,<3.0.0)。进程内服务器通过 mcp 自身的内存传输提供服务,而非手写的 JSON-RPC 分发,因此手工构建的 mcp.server.Server 实例现在可以完整保真运行——资源、提示以及所有结果内容类型均原样到达 CLI。中断时的工具取消在 mcp 2.x 上受支持。claude_agent_sdk.ToolAnnotations 在每个 mcp 版本上都接受 camelCase 和 snake_case 提示名称(#1218)
- forward_subagent_text 选项:ClaudeAgentOptions 上新增的布尔型 forward_subagent_text 将子代理的文本和思考块作为消息转发到流中,使消费者能够渲染完整的嵌套转录。与 TypeScript SDK 的 forwardSubagentText 一致(#1206)
- 带有结构化错误负载的 ResultError 异常:当 CLI 在终端错误结果后退出时,SDK 现在会引发 ResultError(ProcessError 的子类),而非仅返回“退出代码 1”错误。它携带 subtype、errors、result、api_error_status、terminal_reason、session_id 以及原始数据字典,使调用者无需字符串匹配即可根据失败原因进行分支处理。新增导出类型:ResultError(#1205)
- 对 query() 和字符串提示的 can_use_tool 回调支持:can_use_tool 权限回调现在适用于字符串提示(不仅限于 ClaudeSDKClient),并且 stdin 保持打开,以便 CLI 可以通过控制协议发送权限请求(#1204)
Bug Fixes
错误修复
- Recover parent_tool_use_id when reading subagent transcripts: get_subagent_messages() and get_subagent_messages_from_store() now recover the parent_tool_use_id from the subagent's metadata, linking each subagent's messages to the Agent tool_use block in the parent session. SessionMessage also gains a parent_agent_id field for the spawning agent's id (#1207)
- 读取子代理转录时恢复 parent_tool_use_id:get_subagent_messages() 和 get_subagent_messages_from_store() 现在从子代理的元数据中恢复 parent_tool_use_id,将每个子代理的消息链接到父会话中的 Agent tool_use 块。SessionMessage 还新增了 parent_agent_id 字段,用于记录生成代理的 id(#1207)
Internal/Other Changes
内部/其他更改
- Updated bundled Claude CLI to version 2.1.235
- 更新捆绑的 Claude CLI 至版本 2.1.235
PyPI: https://pypi.org/project/claude-agent-sdk/0.2.140/
PyPI:https://pypi.org/project/claude-agent-sdk/0.2.140/
代码 · 1 行
pip install claude-agent-sdk==0.2.140代码 · 1 行
pip install claude-agent-sdk==0.2.140更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力