自研 Agent 框架的管理系统,负责 Agent 的生命周期管理和任务执行调度。
Gateway 是自研 Agent 框架的管理系统,专注于"使命/职能对话":
与 IM 系统的区别:
┌──────────────────────┐
│ 飞书(个人助理) │
│ 使命/职能对话 │
└──────────┬───────────┘
│
│ Webhook
│
┌───────────────────────────▼───────────────────────────┐
│ Gateway(Agent 管理系统) │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Channels(外部渠道接入) │ │
│ │ - 飞书集成(个人助理型) │ │
│ │ - 消息路由 │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Lifecycle(生命周期管理) │ │
│ │ - Trace 注册和查询 │ │
│ │ - Workspace 管理 │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Executor(任务执行调度) │ │
│ │ - 接收用户任务 │ │
│ │ - 调度 Agent 执行 │ │
│ └──────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ IM Server │
│ - 接入飞书(数字员工型)、微信等渠道 │
│ - LLM 作为主体参与对话 │
└─────────────────────────────────────────────────────────┘
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 工具
│
└── docs/ # 文档
├── requirements.md # 需求规划
├── architecture.md # 架构设计
├── core/ # 核心模块文档
│ ├── channels.md # 外部渠道接入
│ ├── lifecycle.md # 生命周期管理
│ └── executor.md # 任务执行调度
├── api/ # API 文档
├── client/ # 客户端文档
├── guides/ # 使用指南
└── decisions.md # 设计决策
# 直接导入 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=trace_id,
task_description="分析销售数据"
)
# 查询任务状态
task = task_mgr.get_task(task_id)
print(task["status"]) # pending/running/completed/failed
# 使用 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=trace_id,
task_description="分析销售数据"
)
# 查询任务状态
task = client.get_task(task_id)
print(task["status"])
docs/guides/quickstart.mddocs/guides/internal-agent.mddocs/guides/external-agent.mdmodule/file.py:function_name