mcpField
M
migrate-honcho

migrate-honcho

github.com/plastic-labs开发7.8k332 次安装今天更新
代码仓库

关于 migrate-honcho

migrate-honcho 是将 Python SDK 从 1.6.0 迁移到 2.1.1 的技能,面向升级到 Honcho 3.0.0+ 的项目维护者。它汇总了破坏性变更、API 替换和迁移核对项。

主要功能

  1. 01更新异步客户端访问方式
  2. 02替换 Observation 与配置 API
  3. 03调整上下文、流式和消息方法
  4. 04说明分页、校验与异常变化

适用场景

  1. 01将旧版 Honcho Python SDK 升级至 2.1.1
  2. 02定位移除或重命名的 SDK 方法
  3. 03检查升级后的异步调用和分页代码

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/plastic-labs/honcho --skill migrate-honcho

安装后在 Claude Code 中输入/migrate-honcho确认已加载。

附带文件DETAILED-CHANGES.mdMIGRATION-CHECKLIST.md

详细介绍

Honcho Python SDK 迁移(v1.6.0 → v2.1.1)

概述

此技能可将代码从 honcho Python SDK v1.6.0 迁移到 v2.1.1(Honcho 3.0.0+ 必需)。

主要破坏性变更:

  • 移除 AsyncHoncho/AsyncPeer/AsyncSession → 改用 .aio 访问器
  • 术语从“Observation”改为“Conclusion”
  • 移除 Representation 类(现在返回 str)
  • get_config/set_config → get_configuration/set_configuration
  • 使用 chat_stream() 进行流式传输,而非 chat(stream=True)
  • 移除 poll_deriver_status()
  • 移除 .core 属性

快速迁移

1. 更新异步架构
# Before
from honcho import AsyncHoncho, AsyncPeer, AsyncSession

async_client = AsyncHoncho()
peer = await async_client.peer("user-123")
response = await peer.chat("query")

# After
from honcho import Honcho

client = Honcho()
peer = await client.aio.peer("user-123")
response = await peer.aio.chat("query")

# Async iteration
async for p in client.aio.peers():
    print(p.id)
2. 将 observations 替换为 conclusions
# Before
from honcho import Observation, ObservationScope, AsyncObservationScope

scope = peer.observations
scope = peer.observations_of("other-peer")
rep = scope.get_representation()

# After
from honcho import Conclusion, ConclusionScope, ConclusionScopeAio

scope = peer.conclusions
scope = peer.conclusions_of("other-peer")
rep = scope.representation()  # Returns str
3. 更新 representation 处理方式
# Before
from honcho import Representation, ExplicitObservation, DeductiveObservation

rep: Representation = peer.working_rep()
print(rep.explicit)
print(rep.deductive)
if rep.is_empty():
    print("No observations")

# After
rep: str = peer.representation()
print(rep)  # Just a string now
if not rep:
    print("No conclusions")
4. 重命名配置方法
# Before
config = peer.get_config()
peer.set_config({"observe_me": False})
session.get_config()
client.get_config()

# After
from honcho.api_types import PeerConfig, SessionConfiguration, WorkspaceConfiguration

config = peer.get_configuration()
peer.set_configuration(PeerConfig(observe_me=False))
session.get_configuration()
client.get_configuration()
5. 更新方法名称
# Before
peer.working_rep()
peer.get_context()
peer.get_sessions()
session.get_context()
session.get_summaries()
session.get_messages()
session.get_peers()
session.get_peer_config()
client.get_peers()
client.get_sessions()
client.get_workspaces()

# After
peer.representation()
peer.context()
peer.sessions()
session.context()
session.summaries()
session.messages()
session.peers()
session.get_peer_configuration()
client.peers()
client.sessions()
client.workspaces()
6. 更新流式传输
# Before
response = peer.chat("query", stream=True)
for chunk in response:
    print(chunk, end="")

# After
stream = peer.chat_stream("query")
for chunk in stream:
    print(chunk, end="")
7. 更新队列状态(原名为 deriver)
# Before
from honcho_core.types import DeriverStatus

status = client.get_deriver_status()
status = client.poll_deriver_status(timeout=300.0)  # Removed!

# After
from honcho.api_types import QueueStatusResponse

status = client.queue_status()
# poll_deriver_status removed - implement polling manually if needed
8. 更新 representation 参数
# Before
rep = peer.working_rep(
    include_most_derived=True,
    max_observations=50
)

# After
rep = peer.representation(
    include_most_frequent=True,
    max_conclusions=50
)
9. 将 update_message 移至 session
# Before
updated = client.update_message(message=msg, metadata={"key": "value"}, session="sess-id")

# After
updated = session.update_message(message=msg, metadata={"key": "value"})
10. 更新 card() 返回类型和方法名称
# Before
card: str = peer.card()  # Returns str

# After (v2.0.0+)
card: list[str] | None = peer.get_card()  # Returns list[str] | None
if card:
    print("\n".join(card))

# peer.card() still works but is deprecated — use get_card()

# New in v2.0.1: set_card()
peer.set_card(["Prefers dark mode", "Located in US"])
11. 严格输入验证(v2.0.2+)

现在,所有输入模型都会通过 Pydantic 验证,以 extra="forbid" 拒绝未知字段。此前,拼写错误或多余的字段会被静默忽略。

# Before (v2.0.1 and earlier) — silently ignored
peer = client.peer("user-1", configuration=PeerConfig(observe_mee=True))  # typo silently ignored

# After (v2.0.2+) — raises ValidationError
peer = client.peer("user-1", configuration=PeerConfig(observe_mee=True))  # ValidationError!
12. peer() 和 session() 始终会发起 API 调用(v2.1.0+)

破坏性变更:peer() 和 session() 现在始终会发起获取或创建 API 调用。此前,不带元数据或配置调用时,会返回不会发起 API 调用的延迟对象。

# Before (v2.0.x) — no API call without options
peer = client.peer("user-123")  # Lazy, no network request

# After (v2.1.0+) — always hits the API
peer = client.peer("user-123")  # Makes POST to /peers (get-or-create)

# Async
peer = await client.aio.peer("user-123")  # Also always hits API
13. 新属性和方法(v2.1.0+)
# created_at on Peer and Session
peer = client.peer("user-123")
print(peer.created_at)  # datetime | None

session = client.session("sess-1")
print(session.created_at)  # datetime | None

# is_active on Session
print(session.is_active)  # bool | None

# get_message() on Session
msg = session.get_message("msg-id")
# Async: msg = await session.aio.get_message("msg-id")
14. 列表方法的分页参数(v2.1.0+)

现在所有列表方法都接受 page、size 和 reverse 参数:

# Before (v2.0.x) — only filters
peers_page = client.peers(filters={"metadata": {"role": "admin"}})

# After (v2.1.0+) — pagination controls
peers_page = client.peers(
    filters={"metadata": {"role": "admin"}},
    page=2,
    size=25,
    reverse=True
)

# Works on: client.peers(), client.sessions(), peer.sessions(),
# session.messages(), scope.list()
15. 扩大 HTTP 重试范围(v2.1.1+)

现在 SDK 会在遇到 httpx.TimeoutException、httpx.NetworkError 和 httpx.RemoteProtocolError 时重试(此前只会在遇到 httpx.TimeoutException 和 httpx.ConnectError 时重试)。这些异常分别映射为 SDK 的 TimeoutError 和 ConnectionError。无需更改代码——此行为会自动生效。

快速参考表

v1.6.0v2.0.0
AsyncHoncho()Honcho() + .aio 访问器
AsyncPeerPeer + .aio 访问器
AsyncSessionSession + .aio 访问器
ObservationConclusion
ObservationScopeConclusionScope
AsyncObservationScopeConclusionScopeAio
Representationstr
.observations.conclusions
.observations_of().conclusions_of()
.get_config().get_configuration()
.set_config().set_configuration()
.working_rep().representation()
.get_context().context()
.get_sessions().sessions()
.get_peers().peers()
.get_messages().messages()
.get_summaries().summaries()
.get_deriver_status().queue_status()
.poll_deriver_status()(已移除)
.get_peer_config().get_peer_configuration()
.set_peer_config().set_peer_configuration()
client.update_message()session.update_message()
peer.card()peer.get_card()(card() 已弃用)
(新增)peer.set_card(list[str])
chat(stream=True)chat_stream()
include_most_derived=include_most_frequent=
max_observations=max_conclusions=
last_user_message=search_query=
config=configuration=
PeerContextPeerContextResponse
DeriverStatusQueueStatusResponse
client.core(已移除)
(v2.1.0 新增)peer.created_at / session.created_at
(v2.1.0 新增)session.is_active
(v2.1.0 新增)session.get_message(id)
(v2.1.0 新增)列表方法中的 page=、size=、reverse=

详细参考

如需了解各项变更的完整详情,请参阅:

新增异常类型

from honcho import (
    HonchoError,
    APIError,
    BadRequestError,
    AuthenticationError,
    PermissionDeniedError,
    NotFoundError,
    ConflictError,
    UnprocessableEntityError,
    RateLimitError,
    ServerError,
    TimeoutError,
    ConnectionError,
)

New Import Locations

# Configuration types
from honcho.api_types import (
    PeerConfig,
    SessionConfiguration,
    WorkspaceConfiguration,
    SessionPeerConfig,
    QueueStatusResponse,
    PeerContextResponse,
)

# Async type hints
from honcho import HonchoAio, PeerAio, SessionAio

# Message types (note: Params is plural now)
from honcho import Message, MessageCreateParams

评论

支持 Markdown