Yuanbao

Connect Hermes toYuanbao, Tencent’s enterprise messaging platform. The adapter uses a WebSocket gateway for real-time message delivery and supports both direct (C2C) and group conversations.

Yuanbao is an enterprise messaging platform primarily used within Tencent and enterprise environments. It uses WebSocket for real-time communication, HMAC-based authentication, and supports rich media including images, files, and voice messages.

Prerequisites​

websockets httpx aiofiles

Install the required dependencies:

pip install websockets httpx aiofiles

Setup​

1. Create a Bot in Yuanbao​

  1. Download the Yuanbao app fromhttps://yuanbao.tencent.com/
  2. In the app, go toPAI → My Botand create a new bot
  3. After the bot is created, copy theAPP_IDandAPP_SECRET

2. Run the Setup Wizard​

The easiest way to configure Yuanbao is through the interactive setup:

hermes gateway setup

SelectYuanbaowhen prompted. The wizard will:

  1. Ask for your APP_ID
  2. Ask for your APP_SECRET
  3. Save the configuration automatically

The WebSocket URL and API Domain have sensible defaults built in. You only need to provide APP_ID and APP_SECRET to get started.

3. Configure Environment Variables​

After initial setup, verify these variables in~/.hermes/.env:

~/.hermes/.env

# RequiredYUANBAO_APP_ID=your-app-idYUANBAO_APP_SECRET=your-app-secretYUANBAO_WS_URL=wss://api.yuanbao.example.com/wsYUANBAO_API_DOMAIN=https://api.yuanbao.example.com# Optional: bot account ID (normally obtained automatically from sign-token)# YUANBAO_BOT_ID=your-bot-id# Optional: internal routing environment (e.g. test/staging/production)# YUANBAO_ROUTE_ENV=production# Optional: home channel for cron/notifications (format: direct:<account> or group:<group_code>)YUANBAO_HOME_CHANNEL=direct:bot_account_idYUANBAO_HOME_CHANNEL_NAME="Bot Notifications"# Optional: restrict access (legacy, see Access Control below for fine-grained policies)YUANBAO_ALLOWED_USERS=user_account_1,user_account_2

4. Start the Gateway​

hermes gateway

The adapter will connect to the Yuanbao WebSocket gateway, authenticate using HMAC signatures, and begin processing messages.

Features​

Configuration Options​

Chat ID Formats​

Yuanbao uses prefixed identifiers depending on conversation type:

Chat Type Format Example
Direct message (C2C) direct: direct:user123
Group message group: group:grp456

direct:<account> direct:user123 group:<group_code> group:grp456

Media Uploads​

The Yuanbao adapter automatically handles media uploads via COS (Tencent Cloud Object Storage):

Media URLs are automatically validated and downloaded before upload to prevent SSRF attacks.

Home Channel​

Use the/sethomecommand in any Yuanbao chat (DM or group) to designate it as thehome channel. Scheduled tasks (cron jobs) deliver their results to this channel.

/sethome

If no home channel is configured, the first user to message the bot will be automatically set as the home channel owner. If the current home channel is a group chat, the first DM will upgrade it to a direct channel.

You can also set it manually in~/.hermes/.env:

~/.hermes/.env

YUANBAO_HOME_CHANNEL=direct:user_account_id# or for a group:# YUANBAO_HOME_CHANNEL=group:group_codeYUANBAO_HOME_CHANNEL_NAME="My Bot Updates"

Example: Set Home Channel​

  1. Start a conversation with the bot in Yuanbao
  2. Send the command:/sethome
  3. The bot responds: “Home channel set to [chat_name] with ID [chat_id]. Cron jobs will deliver to this location.”
  4. Future cron jobs and notifications will be sent to this channel

/sethome

Example: Cron Job Delivery​

Create a cron job:

/cron "0 9 * * *" Check server status

The scheduled output will be delivered to your Yuanbao home channel every day at 9 AM.

Usage Tips​

Starting a Conversation​

Send any message to the bot in Yuanbao:

hello

The bot responds in the same conversation thread.

Available Commands​

All standard Hermes commands work on Yuanbao:

Command Description
/new Start a fresh conversation
/model [provider:model] Show or change the model
/sethome Set this chat as the home channel
/status Show session info
/help Show available commands

/new /model [provider:model] /sethome /status /help

Sending Files​

To send a file to the bot, simply attach it directly in the Yuanbao chat. The bot will automatically download and process the file attachment.

You can also include a message with the attachment:

Please analyze this document

Receiving Files​

When you ask the bot to create or export a file, it sends the file directly to your Yuanbao chat.

Troubleshooting​

Bot is online but not responding to messages​

Cause: Authentication failed during WebSocket handshake.

Fix:

  1. Verify APP_ID and APP_SECRET are correct
  2. Check that the WebSocket URL is accessible
  3. Ensure the bot account has proper permissions
  4. Review gateway logs:tail -f ~/.hermes/logs/gateway.log

tail -f ~/.hermes/logs/gateway.log

“Connection refused” error​

Cause: WebSocket URL is unreachable or incorrect.

Fix:

  1. Verify the WebSocket URL format (should start withwss://)
  2. Check network connectivity to the Yuanbao API domain
  3. Confirm firewall allows WebSocket connections
  4. Test URL with:curl -I https://[YUANBAO_API_DOMAIN]

wss:// curl -I https://[YUANBAO_API_DOMAIN]

Media uploads fail​

Cause: COS credentials are invalid or media server is unreachable.

Fix:

  1. Verify API_DOMAIN is correct
  2. Check that media upload permissions are enabled for your bot
  3. Ensure the media file is accessible and not corrupted
  4. Check COS bucket configuration with platform admin

Messages not delivered to home channel​

Cause: Home channel ID format is incorrect or cron job hasn’t triggered.

Fix:

  1. Verify YUANBAO_HOME_CHANNEL is in correct format
  2. Test with/sethomecommand to auto-detect correct format
  3. Check cron job schedule with/status
  4. Verify bot has send permissions in the target chat

/sethome /status

Frequent disconnections​

Cause: WebSocket connection is unstable or network is unreliable.

Fix:

  1. Check gateway logs for error patterns
  2. Increase heartbeat timeout in connection settings
  3. Ensure stable network connection to Yuanbao API
  4. Consider enabling verbose logging:HERMES_LOG_LEVEL=debug

HERMES_LOG_LEVEL=debug

Access Control​

Yuanbao supports fine-grained access control for both DM and group conversations:

# DM policy: open (default) | allowlist | disabledYUANBAO_DM_POLICY=open# Comma-separated user IDs allowed to DM the bot (only used when DM_POLICY=allowlist)YUANBAO_DM_ALLOW_FROM=user_id_1,user_id_2# Group policy: open (default) | allowlist | disabledYUANBAO_GROUP_POLICY=open# Comma-separated group codes allowed (only used when GROUP_POLICY=allowlist)YUANBAO_GROUP_ALLOW_FROM=group_code_1,group_code_2

These can also be set inconfig.yaml:

config.yaml

platforms:  yuanbao:    extra:      dm_policy: allowlist      dm_allow_from: "user1,user2"      group_policy: open      group_allow_from: ""

Advanced Configuration​

Message Chunking​

Yuanbao has a maximum message size. Hermes automatically chunks large responses with Markdown-aware splitting (respects code fences, tables, and paragraph boundaries).

Connection Parameters​

The following connection parameters are built into the adapter with sensible defaults:

Parameter Default Value Description
WebSocket connect timeout 15 seconds Time to wait for WS handshake
Heartbeat interval 30 seconds Ping frequency to keep connection alive
Max reconnect attempts 100 Maximum number of reconnection tries
Reconnect backoff 1s → 60s (exponential) Wait time between reconnect attempts
Reply heartbeat interval 2 seconds RUNNING status send frequency
Send timeout 30 seconds Timeout for outbound WS messages

These values are currently not configurable via environment variables. They are optimized for typical Yuanbao deployments.

Verbose Logging​

Enable debug logging to troubleshoot connection issues:

HERMES_LOG_LEVEL=debug hermes gateway

Integration with Other Features​

Cron Jobs​

Schedule tasks that run on Yuanbao:

/cron "0 */4 * * *" Report system health

Results are delivered to your home channel.

Background Tasks​

Run long operations without blocking the conversation:

/background Analyze all files in the archive

Cross-Platform Messages​

Send a message from CLI to Yuanbao:

hermes chat -q "Send 'Hello from CLI' to yuanbao:group:group_code"