@fishaudio/agent-protocol

中文文档
1.0.0发布于 2026/11/09MITTypeScriptESM + CJS零依赖近 30 天下载 2.2万

Wire contracts for Fish Audio agent sessions: realtime room-channel messages and session-creation shapes.

原始使用文档
文档目录4 节
  1. What's inside
  2. Realtime channel ( realtime.ts )
  3. Session creation ( session.ts )
  4. Conventions

@fishaudio/agent-protocol

The wire contract for Fish Audio agent sessions: the realtime room-channel messages exchanged between the agent runtime and end-user clients, and the shapes of the session-creation exchange. It contains TypeScript types and topic constants only. Zero runtime dependencies, no code.

This is a semi-internal package. It lives in the open so that what travels over the wire is fully auditable, and so the SDK and the agent runtime conform to one published contract. It is not an API for applications. Do not depend on it directly. @fishaudio/agent-client already re-exports the types application code needs: SessionToken, SessionOverrides, and AgentSessionCreateRequest. Reach for this package only when building a custom consumer of the realtime channel or auditing the protocol itself.

What's inside

Realtime channel (realtime.ts)

One topic constant per channel, plus the payload type that travels on it:

TopicDirectionPayload
AGENT_EVENT_TOPICagent → clientAgentSessionMessage. Session control such as client_tool.call, the tool.started / tool.completed / tool.failed lifecycle, session.ended (with a SessionEndedReason), and error (a category code plus stage and recovered). One complete JSON object per message.
CLIENT_EVENT_TOPICclient → agentClientSessionMessage. Text injection, tool results, graceful hangup, the audio readiness report (client.audio_ready).

Two participant attributes complete the room-level contract. They are published as constants so clients and the runtime share one definition:

ConstantSet byMeaning
AGENT_READY_ATTRIBUTE (fish.agent.ready)agentSticky, value epoch ms. The pipeline is live and the opener is queued. Gate the "connected" UI on it, with lk.agent.state as the fallback for older runtimes.
CLIENT_AUDIO_READY_ATTRIBUTE (fish.client.audio_ready)clientCLIENT_AUDIO_READY_PENDING ("pending") right after joining announces a client that will report readiness. An epoch-ms value means the agent's audio track is attached and the browser allows playback. The runtime waits a bounded time for it before speaking the opener. Publishing it needs a join token that lets the participant update its own attributes. The ready value is also sent as a client.audio_ready message on CLIENT_EVENT_TOPIC, because LiveKit delays attribute updates from a participant that has published no track (a microphone-off session). The runtime takes whichever arrives first.

Transcripts (streaming assistant reply and user ASR, interim and final) are not part of this contract: they travel on LiveKit's built-in lk.transcription text streams, keyed by the lk.segment_id attribute, with lk.transcription_final marking finals and the stream's sender identity distinguishing user from agent.

Session creation (session.ts)

The POST /v1/agent/sessions exchange:

  • AgentSessionCreateRequest is the request body. It carries the agent id, per-session SessionOverrides, dynamic variables, attribution fields, and two fields meant for a backend's session-creation call rather than the SDK's public-agent options: llm_extra_body (forwarded to a custom LLM endpoint) and record_audio (per-session recording override).
  • SessionOverrides is the allow-listed per-session config replacement. It covers first message, system prompt, voice, language, and speech recognition model.
  • SessionToken is the response. It is a discriminated union on transport and is handed to the client verbatim.

Conventions

  • Casing. Session-creation shapes are snake_case, following the Fish API convention, because clients consume responses verbatim. Realtime message fields are camelCase.
  • Compatibility is additive-only. Published fields never change name, meaning, or type. New fields are optional. A semantic change ships as a new type. Consumers must ignore unknown type values and unknown fields. Old clients then keep working as the protocol grows.
  • Transports. SessionToken.transport is a discriminated union. A consumer that doesn't recognize the negotiated arm must fail with an explicit upgrade error, never silently.

版本与发布记录

@fishaudio/agent-protocol 共发布 8 个版本,首次发布于 2026/08/01;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.0.0latest2026/11/095 天前
0.4.12026/11/068 天前
0.4.02026/11/068 天前
0.3.02026/09/152 个月前
0.2.12026/09/052 个月前
0.2.02026/08/182 个月前

关于 @fishaudio/agent-protocol 的常见问题

@fishaudio/agent-protocol 是什么?

Wire contracts for Fish Audio agent sessions: realtime room-channel messages and session-creation shapes.

如何安装 @fishaudio/agent-protocol?

在项目目录运行 npm install @fishaudio/agent-protocol,或使用 pnpm add / yarn add / bun add。

@fishaudio/agent-protocol 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fishaudio/agent-protocol 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fishaudio/agent-protocol 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fishaudio/agent-protocol 可以商用吗?

@fishaudio/agent-protocol 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fishaudio/agent-protocol 的下载量有多少?

根据 npm 官方下载统计,@fishaudio/agent-protocol 在 2026/10/15 – 2026/11/13 这 30 天内被下载 22,120 次,日均约 737 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fishaudio/agent-protocol 还在维护吗?

最新版本 1.0.0 发布于 2026/11/09(5 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/08/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。