AHP 主机与服务器开发
build-ahp-host
实现或审查 Agent Host Protocol 主机或服务器,包括 JSON-RPC 传输路由、订阅、serverSeq 与重连、持久状态、取消、并发、模型适配器以及显式不支持的行为。适用于主机架构和服务器行为,不适用于变更 AHP 契约或构建客户端 UI。
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- build-ahp-host
- license
- MIT
- description
- Implement or review an Agent Host Protocol host or server, including JSON-RPC transport routing, subscriptions, serverSeq and reconnect, durable state, cancellation, concurrency, model adapters, and explicit unsupported behavior. Use for host architecture and server behavior, not for changing the AHP contract or building a client UI.
03 SKILL.md 正文
Build an AHP Host
Use this skill for an AHP server implementation or review: WebSocket/JSON-RPC entry points, command routing, state publication, persistence, model execution, and lifecycle behavior.
Use this / use another skill
| Use this skill | Use another skill |
|---|---|
| A host must accept requests, publish actions, resume clients, or run agent work. | Use design-ahp-protocol to alter commands, actions, schemas, or compatibility rules. |
| You are deciding persistence, fan-out, cancellation, or adapter boundaries. | Use build-ahp-client for application state, UI, and client reconnection code. |
| You need observable end-to-end probes against a host. | Use test-ahp-conformance to build the black-box tests. |
Ground the implementation
- Determine the negotiated AHP version and supported capabilities from the current protocol source. Read the applicable lifecycle, subscription, channel, error, and versioning documents plus wire schemas/types.
- Locate equivalent host code and tests in the current repository before inventing a new flow. If the protocol source is absent locally, consult the upstream repository and use released schemas; do not depend on a machine-specific sibling path.
- Mark each requirement as normative AHP behavior or this host's profile choice. For example, redb, replay retention limits, queue sizes, a narrow OpenAI request shape, and excluded feature surfaces are sample choices, not universal AHP rules.
- Map the existing seams: transport, JSON-RPC parser/router, protocol handler, domain/turn logic, persistence port, publisher, and model adapter.
Plan observable invariants
Before changing code, name the externally observable assertions:
| Area | Invariant |
|---|---|
| Handshake | Negotiate once; accept an offered compatible version or return the specified error and close. |
| Subscriptions | Return typed snapshots where applicable and send only traffic scoped to active subscriptions. |
| Actions | Assign monotonically increasing serverSeq; preserve channel routing and origin/rejection semantics. |
| Durability | Commit state and replayable action atomically before publishing it to peers. |
| Recovery | Replay a complete gap in order, or return replacement snapshots; never send a misleading partial replay. |
| Cancellation | A cancelled turn reaches one terminal state and cannot publish late output. |
| Errors | Invalid requests and unsupported methods fail explicitly; do not return success-shaped no-ops. |
Treat root/session/chat or other channel state as typed protocol projections, not persistence DTOs. Keep storage records behind a port so schema conversion and database migration do not leak into routing or turn logic.
Implement in a safe order
- Validate JSON-RPC shape, connection phase, negotiated version, channel URI, permissions, and action payload before mutating durable state.
- Route commands by their defined ownership. Preserve request/response correlation and distinguish requests from notifications.
- Serialize the critical publication path sufficiently to keep action order: reduce/transition state, durably append the envelope with its sequence, then fan it out. Do not hold unrelated network or model work under a global lock.
- Track subscribers and bounded outbound delivery deliberately. A slow peer may be dropped under a host policy, but its reconnection must be able to establish a truthful state from replay or snapshots.
- Implement reconnect from the client's last seen sequence and requested subscriptions. A replay gap requires snapshot fallback. Protocol notifications are ephemeral; make clients recover their catalog through the prescribed fetch/list path rather than pretending notifications replay.
- Give every running turn a cancellation/shutdown token. Check it before each persistence/publication step, remove its registry entry on all exits, and suppress deltas, completion, and errors that arrive after cancellation.
- Isolate model-provider request/response normalization and timeout/error mapping behind a small interface. Map provider failures to intentional AHP terminal behavior without exposing credentials or provider DTOs.
- Reject unsupported commands/actions clearly at the appropriate protocol boundary. Document the host profile rather than implying an omission is an AHP limitation.
- When models or provider options are selectable, advertise them through root
model metadata and the session-config commands. Persist resolved defaults,
validate mutable
session/configChangedactions, and record the effectiveModelSelectionon each user message rather than hiding selection in a private endpoint setting.
Keep the architecture human-scale
Prefer narrow ownership boundaries over a universal dispatcher:
- transport owns peers and connection loops;
- protocol owns parsing, negotiation, and command validation;
- domain/turn logic owns lifecycle decisions;
- persistence owns transactions, replay, and snapshot projections;
- publication owns sequence assignment and fan-out;
- adapters own external model APIs.
Use the repository's canonical types and generated bindings. Change generated files only through their documented generator.
Validate and finish
Run focused unit tests for the changed parser, persistence, turn, or publisher first. Then exercise a raw or SDK client for handshake, snapshot, action ordering, reconnection, two-client delivery, cancellation, and failure paths. Run broader host/conformance checks when the focused slice passes.
Stop when no post-cancellation output can appear, every advertised action was durable first, replay never lies about a gap, and unsupported scope is explicit. Document operational bounds and non-goals as host-profile choices.
04 同仓库更多 Skills
AHP 协议一致性测试
test-ahp-conformance
创建或审查 Agent Host Protocol(AHP)黑盒一致性测试,包括确定性模型夹具、生命周期与错误用例、多客户端与重启覆盖、有界超时控制,以及可附带 JSON 结果的 CLI/HTML 报告。用于可观测的互操作性测试,而非变更协议设计或实现宿主/客户端生产代码。
AHP 协议设计与评审
design-ahp-protocol
设计或审查 Agent Host Protocol(AHP)的命令、动作、状态、错误、reducer、schema、代码生成、版本控制、兼容性及多客户端不变量。适用于变更 AHP 契约或评估协议层设计时,而非仅实现单个宿主、客户端或测试套件时。
AHP 客户端应用开发
build-ahp-client
实现或审查基于 SDK 的 Agent Host Protocol(AHP)客户端应用程序,包括初始化、订阅、不可变 reducer 状态、重连清理、多主机行为以及 UI 友好的投影。适用于浏览器、TypeScript、桌面或其他客户端使用者,不适用于主机内部实现或协议契约变更。