模块: gateway/core/channels/
module/file.py:function_name外部渠道接入,包括:
说明: Channels 模块只用于个人助理型 Agent 的飞书接入(使命/职能对话)
飞书用户 → 飞书 Webhook → Channels 模块 → Executor 模块 → Agent 执行 → Executor → Channels → 飞书
gateway/core/channels/
├── feishu/ # 飞书集成
│ ├── connector.py # 飞书连接器
│ ├── webhook.py # Webhook 处理
│ └── api.py # 飞书 API 调用
│
├── router.py # 消息路由
└── channel_manager.py # 渠道管理
实现位置: gateway/core/channels/feishu/connector.py
职责:
核心接口:
class FeishuConnector:
def __init__(self, app_id: str, app_secret: str):
"""初始化飞书连接器"""
pass
def handle_webhook(self, event: dict) -> dict:
"""处理飞书 Webhook 事件"""
pass
def send_message(self, user_id: str, text: str):
"""发送消息给飞书用户"""
pass
def get_user_info(self, user_id: str) -> dict:
"""获取飞书用户信息"""
pass
实现位置: gateway/core/channels/router.py
职责:
核心接口:
class MessageRouter:
def route_message(self, channel: str, user_id: str, message: dict) -> str:
"""路由消息,返回 task_id"""
pass
def get_trace_id(self, channel: str, user_id: str) -> str:
"""获取或创建 Trace ID"""
pass
def create_trace_for_user(self, channel: str, user_id: str) -> str:
"""为用户创建 Trace"""
pass
实现位置: gateway/core/channels/channel_manager.py
职责:
核心接口:
class ChannelManager:
def register_channel(self, channel_id: str, config: dict):
"""注册渠道"""
pass
def start_channel(self, channel_id: str):
"""启动渠道"""
pass
def stop_channel(self, channel_id: str):
"""停止渠道"""
pass
def get_channel_status(self, channel_id: str) -> dict:
"""获取渠道状态"""
pass
FeishuConnector.handle_webhook()MessageRouter.route_message()Lifecycle.TraceManager.create_trace()Executor.TaskManager.submit_task()FeishuConnector.send_message() 发送回复# 创建 Trace
from gateway.core.lifecycle import TraceManager
trace_mgr = TraceManager()
trace_id = trace_mgr.create_trace(
workspace_id=f"feishu:{user_id}",
agent_type="personal_assistant"
)
# 提交任务
from gateway.core.executor import TaskManager
task_mgr = TaskManager()
task_id = task_mgr.submit_task(
trace_id=trace_id,
task_description=message_text,
mode="async"
)
# config.yaml
channels:
feishu:
enabled: true
app_id: "cli_xxx"
app_secret: "xxx"
webhook_url: "https://gateway.example.com/webhook/feishu"
# 路由配置
routing:
# 自动为新用户创建 Trace
auto_create_trace: true
# Workspace ID 前缀
workspace_prefix: "feishu"