更新日期: 2026-03-12
module/file.py:function_nameGateway 采用分层架构:
┌─────────────────────────────────────────────────────────────┐
│ API 层(HTTP 接口) │
│ - 供外部 Agent 调用 │
│ - RESTful API │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Core 层(核心服务) │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Lifecycle(生命周期管理) │ │
│ │ - Trace 注册和元数据管理 │ │
│ │ - Workspace 管理 │ │
│ │ - 配置热重载 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Conversations(对话管理) │ │
│ │ - 对话管理 │ │
│ │ - 消息历史存储 │ │
│ │ - 消息队列和调度 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Routing(消息路由) │ │
│ │ - 飞书消息接收和转发 │ │
│ │ - 消息路由规则管理 │ │
│ │ - Agent 联系人列表维护 │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
gateway/
├── core/ # 核心服务层(内部接口)
│ ├── lifecycle/ # Agent 生命周期管理
│ │ ├── trace_manager.py # Trace 注册和元数据管理
│ │ ├── workspace_manager.py # Workspace 管理
│ │ └── config_watcher.py # 配置热重载
│ │
│ ├── conversations/ # 对话管理
│ │ ├── conversation_manager.py # 对话管理
│ │ ├── message_store.py # 消息历史存储
│ │ └── message_queue.py # 消息队列和调度
│ │
│ ├── routing/ # 消息路由
│ │ ├── router.py # 消息路由核心
│ │ ├── feishu_connector.py # 飞书集成
│ │ └── contact_manager.py # 联系人管理
│ │
│ └── registry.py # Agent 注册表(保留,兼容旧代码)
│
├── api/ # HTTP API 层(外部接口)
│ ├── lifecycle_api.py # 生命周期管理 API
│ ├── conversations_api.py # 对话管理 API
│ └── routing_api.py # 消息路由 API
│
├── enterprise/ # 企业功能(可选)
│ ├── auth/ # 认证授权
│ ├── audit/ # 审计日志
│ └── multi_tenant/ # 多租户
│
└── client/ # 客户端 SDK
└── python/ # Python SDK
├── client.py # GatewayClient
├── tools.py # 工具函数
└── cli.py # CLI 工具
职责:
实现位置:
gateway/core/lifecycle/trace_manager.pygateway/core/lifecycle/workspace_manager.pygateway/core/lifecycle/config_watcher.py职责:
实现位置:
gateway/core/conversations/conversation_manager.pygateway/core/conversations/message_store.pygateway/core/conversations/message_queue.py职责:
实现位置:
gateway/core/routing/router.pygateway/core/routing/feishu_connector.pygateway/core/routing/contact_manager.py特点:
使用方式:
# 直接导入 Core 层模块
from gateway.core.conversations import ConversationManager
manager = ConversationManager()
messages = manager.get_messages(conversation_id)
特点:
使用方式:
# 使用 Client SDK
from gateway.client.python import GatewayClient
client = GatewayClient("http://gateway-host:8000")
messages = client.get_messages(conversation_id)
说明: