更新日期: 2026-03-14
module/file.py:function_nameGateway 是自研 Agent 框架的管理系统,负责 Agent 的生命周期管理和任务执行调度。
核心定位: 使命/职能对话系统
与 IM 系统的区别:
Gateway:用户对 LLM 的使命/职能对话(管理-执行关系)
┌──────────────────────┐
│ 飞书(个人助理) │
│ 使命/职能对话 │
└──────────┬───────────┘
│
│ Webhook
│
┌───────────────────────────▼───────────────────────────┐
│ Gateway(Agent 管理系统) │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Channels(外部渠道接入) │ │
│ │ - 飞书集成(个人助理型) │ │
│ │ - 消息路由 │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Lifecycle(生命周期管理) │ │
│ │ - Trace 注册和查询 │ │
│ │ - Workspace 管理 │ │
│ │ - 配置热重载 │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Executor(任务执行调度) │ │
│ │ - 接收用户任务 │ │
│ │ - 调度 Agent 执行 │ │
│ │ - 管理执行状态 │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ IM Client(可选) │ │
│ │ - Agent 主动通信 │ │
│ └──────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ IM Server │
│ - 所有主体(Agent、用户)的平等通信系统 │
│ - 接入飞书(数字员工型)、微信等渠道 │
│ - LLM 作为主体参与对话 │
└─────────────────────────────────────────────────────────┘
↑
│ IM Protocol
│
┌────────────────┼────────────────┐
│ │ │
┌────▼────┐ ┌───▼────┐ ┌───▼────┐
│IM Client│ │IM Client│ │IM Client│
│(自研) │ │(Claude │ │(飞书数字 │
│ │ │ Code) │ │ 员工) │
└─────────┘ └─────────┘ └─────────┘
gateway/
├── core/ # 核心服务层(内部接口)
│ ├── channels/ # 外部渠道接入
│ │ ├── feishu/ # 飞书集成
│ │ │ ├── connector.py # 飞书连接器
│ │ │ ├── webhook.py # Webhook 处理
│ │ │ └── api.py # 飞书 API 调用
│ │ ├── router.py # 消息路由
│ │ └── channel_manager.py # 渠道管理
│ │
│ ├── lifecycle/ # Agent 生命周期管理
│ │ ├── trace_manager.py # Trace 注册和查询
│ │ ├── workspace_manager.py # Workspace 管理
│ │ └── config_watcher.py # 配置热重载
│ │
│ └── executor/ # 任务执行调度
│ ├── task_manager.py # 任务管理
│ ├── scheduler.py # 调度器
│ └── execution_context.py # 执行上下文
│
├── api/ # HTTP API 层(外部接口)
│ ├── lifecycle_api.py # 生命周期管理 API
│ ├── executor_api.py # 任务执行 API
│ └── webhook_api.py # Webhook API(飞书等)
│
└── client/ # 客户端 SDK
└── python/ # Python SDK
├── client.py # GatewayClient
└── cli.py # CLI 工具
职责:
实现位置:
gateway/core/channels/feishu/connector.pygateway/core/channels/router.pygateway/core/channels/channel_manager.py详细文档: channels.md
职责:
实现位置:
gateway/core/lifecycle/trace_manager.pygateway/core/lifecycle/workspace_manager.pygateway/core/lifecycle/config_watcher.py详细文档: lifecycle.md
职责:
实现位置:
gateway/core/executor/task_manager.pygateway/core/executor/scheduler.pygateway/core/executor/execution_context.py详细文档: executor.md
场景:
消息流转:
用户 → Gateway API → Executor → Agent 框架执行 → Executor → Gateway API → 用户
特点:
场景:
消息流转:
用户/Agent A → IM Client → IM Server → IM Client → Agent B
特点:
特点:
使用方式:
# 直接导入 Core 层模块
from gateway.core.lifecycle import TraceManager
from gateway.core.executor import TaskManager
trace_mgr = TraceManager()
task_mgr = TaskManager()
# 创建 Trace
trace_id = trace_mgr.create_trace(workspace_id="user_001", agent_type="personal_assistant")
# 提交任务
task_id = task_mgr.submit_task(trace_id, task_description="分析销售数据")
特点:
使用方式:
# 使用 Client SDK
from gateway.client.python import GatewayClient
client = GatewayClient("http://gateway-host:8000")
# 创建 Trace
trace_id = client.create_trace(workspace_id="user_001", agent_type="personal_assistant")
# 提交任务
task_id = client.submit_task(trace_id, task_description="分析销售数据")
Gateway 管理的 Agent 可以通过 IM Client 参与 IM 系统的通信:
Agent 执行过程中需要协作:
Agent 主动通知用户:
消息历史管理: