Skip to content

feat(gateway): yuanbao platform#13276

Closed
loongfay wants to merge 2 commits into
NousResearch:mainfrom
YuanbaoTeam:feature/yuanbao
Closed

feat(gateway): yuanbao platform#13276
loongfay wants to merge 2 commits into
NousResearch:mainfrom
YuanbaoTeam:feature/yuanbao

Conversation

@loongfay

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds full Yuanbao (元宝) platform support to Hermes Agent, enabling the bot to connect to Tencent's Yuanbao enterprise messaging platform via WebSocket gateway. This includes real-time message receive/send (C2C and group), media handling (images, files via COS upload), sticker support, access control policies, and a middleware-based inbound message pipeline.

Yuanbao is Tencent's enterprise messaging platform with over 100 million monthly active users, that uses WebSocket for real-time communication with HMAC-based authentication. This PR implements the full adapter lifecycle: authentication (AUTH_BIND), heartbeat, reconnection, message decoding (protobuf-like binary protocol), and outbound message encoding.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

Core Platform Adapter

  • gateway/platforms/yuanbao.py — Main adapter: WebSocket lifecycle, AUTH_BIND, heartbeat, reconnection with close-code classification, inbound pipeline (17 OOP middlewares), outbound queue with fence-aware text buffering, @mention conversion, markdown splitting, DM active messaging
  • gateway/platforms/yuanbao_proto.py — Custom binary protocol codec (protobuf-like): conn/biz layer encode/decode, InboundMessagePush parsing, SendC2C/GroupMessage encoding, auth-bind/ping/push-ack
  • gateway/platforms/yuanbao_media.py — COS upload via temporary credentials (genUploadInfo), TIMImageElem/TIMFileElem message body construction, file download
  • gateway/platforms/yuanbao_sticker.py — TIMFaceElem support with built-in sticker catalogue, fuzzy search by keyword/description

Tools & Skills

  • tools/yuanbao_tools.py — Toolset (hermes-yuanbao): yb_query_group_info, yb_query_group_members, yb_search_sticker, yb_send_sticker, yb_send_dm
  • skills/yuanbao/SKILL.md — Skill definition for @mention workflow, DM sending, group queries

Gateway & CLI Integration

  • gateway/config.py — Added Yuanbao platform enum, config fields (app_id, app_secret, bot_id, ws_url, api_domain, access policies)
  • gateway/run.py — Integrated Yuanbao adapter startup/shutdown
  • gateway/platforms/__init__.py — Registered Yuanbao platform
  • hermes_cli/gateway.py — Added _setup_yuanbao() interactive wizard
  • hermes_cli/platforms.py — Added Yuanbao to platform list
  • hermes_cli/setup.py — Yuanbao setup integration
  • hermes_cli/tools_config.py — Registered hermes-yuanbao toolset
  • hermes_cli/web_server.py — Yuanbao status endpoint
  • toolsets.py — Yuanbao toolset registration

Agent & Messaging

  • agent/prompt_builder.py — Yuanbao-specific prompt context (slow-task hints, platform awareness)
  • tools/send_message_tool.py — Extended send_message to support Yuanbao targets
  • run_agent.py — Yuanbao adapter integration in agent runner

Documentation

  • website/docs/user-guide/messaging/yuanbao.md — Full setup guide (prerequisites, wizard, env vars, features)
  • website/docs/user-guide/messaging/index.md — Added Yuanbao to messaging index

Tests (4 new test files, 2400+ lines)

  • tests/test_yuanbao_proto.py — Protocol codec unit tests (varint, conn/biz layer, MsgContent, InboundPush, outbound encoding, constants)
  • tests/test_yuanbao_pipeline.py — Inbound pipeline middleware tests (17 middlewares, OOP registration, end-to-end flows)
  • tests/test_yuanbao_integration.py — Integration tests (adapter lifecycle, media handling, access control)
  • tests/test_yuanbao_markdown.py — Markdown splitting/enhancement tests

How to Test

  1. Install dependencies: pip install websockets httpx aiofiles
  2. Run the setup wizard: hermes gateway setup → select Yuanbao → provide APP_ID and APP_SECRET
  3. Start the gateway: hermes gateway run -vv
  4. Send a message to the bot in Yuanbao app (DM or group @mention) and verify response
  5. Run tests: pytest tests/test_yuanbao_proto.py tests/test_yuanbao_pipeline.py tests/test_yuanbao_integration.py tests/test_yuanbao_markdown.py -v

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS (darwin)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings)
  • I've updated cli-config.yaml.example if I added/changed config keys
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

[INFO] Yuanbao: WebSocket connected to wss://...
[INFO] Yuanbao: AUTH_BIND success, bot_id=xxx
[INFO] Yuanbao: Heartbeat running (interval=30s)
[INFO] Yuanbao: Received group message from alice in group:328306697
[INFO] Yuanbao: Sent 2 text chunks + 1 image to group:328306697

Architecture Overview

graph TD
    A[Yuanbao WS Gateway] -->|WebSocket| B[YuanbaoAdapter]
    B --> C[Inbound Pipeline - 17 Middlewares]
    C --> D[decode → extract-fields → dedup → skip-self]
    D --> E[chat-routing → access-guard → auto-sethome]
    E --> F[extract-content → placeholder-filter → owner-command]
    F --> G[build-source → group-at-guard → group-attribution]
    G --> H[classify-msg-type → quote-context → media-resolve → dispatch]
    H --> I[Hermes Agent]
    I -->|Response| J[OutboundQueue]
    J -->|Fence-aware splitting| K[WS Send]
    K --> A
Loading

@ygd58

ygd58 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested locally.

Test results: 213 passed, 2 skipped, 0 failed across all 4 test files:

  • test_yuanbao_proto.py
  • test_yuanbao_pipeline.py
  • test_yuanbao_integration.py
  • test_yuanbao_markdown.py

The implementation looks solid:

  • Protocol codec (varint, conn/biz layer, protobuf-like binary) is well-tested
  • 17-middleware inbound pipeline with OOP registration is clean
  • COS media upload and sticker catalogue are well-structured
  • Access control policies are properly implemented
  • Reconnection/heartbeat lifecycle looks correct

CI test failure appears to be due to missing dependency registrations in a partial checkout context, not a code issue — all 213 tests pass when the full file set is present.

LGTM from a test coverage and architecture perspective. 🚀

@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants