模块: gateway/core/channels/
module/file.py:function_name外部渠道接入,包括:
说明: Channels 模块只用于个人助理型 Agent 的飞书接入(使命/职能对话)
飞书用户 → 飞书 Webhook → Channels 模块 → Executor 模块 → Agent 执行 → Executor → Channels → 飞书
gateway/core/channels/
├── manager.py # ChannelRegistry(通用注册/启停/状态)
├── router.py # ChannelTraceRouter(与 IM 无关的 trace 解析)
├── loader.py # 渠道加载入口
├── types.py # RouteResult 等
├── protocols.py # TraceBackend 等协议
│
└── feishu/ # 飞书渠道
├── manager.py # FeishuChannelManager、FeishuChannelConfig
├── connector.py # FeishuConnector(HTTP 入站解析等)
├── router.py # FeishuMessageRouter
├── bridge.py # FeishuHttpRunApiExecutor(调 Gateway Executor / Agent)
├── api.py # FastAPI 路由装配(Webhook 等)
├── identity.py # 用户身份解析
└── types.py # 飞书侧类型
飞书侧还包含 openclaw-lark 等子项目(Node/TS IM 逻辑),Compose 中可由独立 feishu 服务承载 HTTP;Gateway 通过 FEISHU_HTTP_BASE_URL 等与其通信。
实现位置: 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
职责: 与具体 IM 无关;按 workspace_prefix 生成 workspace_id,并委托 TraceBackend 解析已绑定的 Agent trace_id(不在 Gateway 内预分配 UUID)。
class ChannelTraceRouter:
async def get_trace_id(
self, channel: str, user_id: str, *, create_if_missing: bool = True
) -> str: ...
async def create_trace_for_user(self, channel: str, user_id: str) -> str: ...
实现位置: gateway/core/channels/feishu/router.py
职责: 飞书消息 → workspace_id / 路由决策;与 FeishuChannelManager、bridge 协同。
实现位置: gateway/core/channels/feishu/manager.py、feishu/bridge.py
FeishuChannelConfig)、依赖(Trace/Workspace/Executor)、Webhook 处理与跟单策略。submit_task,并在 Agent 返回后 TraceManager.bind_agent_trace。workspace_prefix、auto_create_trace、dispatch_card_actions、stop_container_on_trace_terminal 等(见 FeishuChannelConfig 字段注释)。实现位置: gateway/core/channels/manager.py
职责: 通用渠道注册表、启停与状态查询(register_channel、start_channel、stop_channel、get_channel_status)。
FeishuConnector / api 解析事件与用户标识。workspace_id(如 feishu:<open_id>);TraceManager.prepare_workspace_session(workspace_id) → Workspace 目录 + 沙箱(ensure_session)。TaskManager.submit_task;内部 HTTP 调 Agent POST .../run 创建/续跑 Trace。trace_id 后,TraceManager.bind_agent_trace(workspace_id, trace_id, ...)。FeishuChannelConfig 开关控制。trace_id 时,可直接 submit_task(trace_id, ...) 续跑。stop_container_on_trace_terminal)。# 准备会话目录与沙箱;Agent 返回 trace_id 后再绑定
await trace_mgr.prepare_workspace_session(f"feishu:{user_id}")
# ... Agent run 得到 trace_id 后:
await trace_mgr.bind_agent_trace(
f"feishu:{user_id}",
agent_trace_id=trace_id,
agent_type="personal_assistant",
)
详见 Lifecycle 模块(目录布局、命名卷、volume_subpath)。
task_id = await 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"
gateway_exec、Agent HTTPdocker-compose.yml:gateway / feishu / api 服务与环境变量