Skip to content

feat: support channel routing to dispatch messages to different agents#1889

Closed
ixiadao wants to merge 1 commit intoagentscope-ai:mainfrom
ixiadao:feat/channel-routing-v2
Closed

feat: support channel routing to dispatch messages to different agents#1889
ixiadao wants to merge 1 commit intoagentscope-ai:mainfrom
ixiadao:feat/channel-routing-v2

Conversation

@ixiadao
Copy link
Copy Markdown
Contributor

@ixiadao ixiadao commented Mar 19, 2026

Summary

Add channel routing support to dispatch channel messages to different agents based on configurable rules. This enables a single channel (e.g. one Feishu bot) to serve multiple agents by routing messages based on meta fields like feishu_chat_id.

Changes

config/config.py

  • Add ChannelRoutingRule model with fields: channel, match_field, match_value, target_agent_id
  • Add channel_routing field to AgentsConfig

app/channels/base.py

  • Add _channel_routing_rules and _multi_agent_manager to BaseChannel.__init__
  • Add _resolve_channel_routing() to match meta fields against routing rules
  • Add _get_routed_process() to get the target agent's stream_query handler
  • Modify _run_process_loop() to use routed process when a rule matches

app/channels/feishu/channel.py

  • Override _run_process_loop() to support channel routing (Feishu overrides the base method, so routing must be added here too)

app/_app.py

  • Inject routing rules and multi_agent_manager into default agent's channels during startup

Configuration Example

{
  "agents": {
    "channel_routing": [
      {
        "channel": "feishu",
        "match_field": "feishu_chat_id",
        "match_value": "oc_xxxx",
        "target_agent_id": "agent_1"
      }
    ]
  }
}

Use Case

When running multiple agents, users often want a single Feishu bot (one App) to serve different agents in different group chats. This PR enables that by routing messages based on the group chat ID to the appropriate agent.

Testing

  • Tested with 3 routing rules (3 Feishu group chats → 3 different agents)
  • Messages in each group are correctly routed to the target agent
  • Messages in unmatched chats (e.g. DM) fall through to the default agent
  • No impact on channels without routing rules configured

Add channel_routing configuration to route channel messages (e.g. Feishu)
to specific agents based on meta fields like chat_id.

Changes:
- Add ChannelRoutingRule model in config
- Add _resolve_channel_routing and _get_routed_process in BaseChannel
- Override _run_process_loop in FeishuChannel to support routing
- Inject routing rules during app startup
@github-actions github-actions Bot added the first-time-contributor PR created by a first time contributor label Mar 19, 2026
@ixiadao ixiadao closed this Mar 22, 2026
@ixiadao ixiadao deleted the feat/channel-routing-v2 branch March 22, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor PR created by a first time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant