落地并存测服全端:智能体 Graph/路由、后台切 8180、主账与部署脚本齐备,便于线上重发与验收。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,5 +2,97 @@
|
||||
意图路由:DeepSeek A → 唯一 RouteDecision。
|
||||
|
||||
禁止:在本包产生业务副作用(建单、发消息、改六态)。
|
||||
骨架:仅占位。
|
||||
正式路径:DeepSeekARouter(strict tool);route_stub 仅兼容旧自检名。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from agent.llm import LlmGateway, LlmMode
|
||||
from agent.routing.decision import RouteDecision
|
||||
from agent.routing.deepseek_a import DeepSeekARouter
|
||||
from agent.routing.dispatch import HANDLER_REGISTRY, dispatch_inbound, resolve_handler
|
||||
from agent.routing.ordered_actions import (
|
||||
ORDERED_ACTIONS_TOOL_NAME,
|
||||
OrderedActionsError,
|
||||
OrderedActionsResult,
|
||||
ordered_actions_tool_definition,
|
||||
parse_ordered_actions_arguments,
|
||||
)
|
||||
|
||||
# IntentRouter 定义见下
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class IntentRouter:
|
||||
"""
|
||||
路由门面。
|
||||
|
||||
- route():优先 DeepSeek A(默认 stub,不开费)
|
||||
- enqueue_ordered_actions():快回路径入 LLM Stream
|
||||
"""
|
||||
|
||||
llm: Optional[LlmGateway] = None
|
||||
deepseek_a: Optional[DeepSeekARouter] = None
|
||||
allow_network: bool = False
|
||||
|
||||
def _a(self) -> DeepSeekARouter:
|
||||
if self.deepseek_a is not None:
|
||||
return self.deepseek_a
|
||||
return DeepSeekARouter.from_settings(allow_network=self.allow_network)
|
||||
|
||||
def route_stub(self, *, text: str, sender_id: str) -> RouteDecision:
|
||||
"""
|
||||
兼容旧名:等价于无网络的 A stub fixture。
|
||||
|
||||
正式生产请用 route() 并在 Worker 开 allow_network + 数据确认。
|
||||
"""
|
||||
return self._a().route_stub_fixture(text=text, sender_id=sender_id)
|
||||
|
||||
def route(self, *, text: str, sender_id: str) -> RouteDecision:
|
||||
"""一条入站一个 RouteDecision。"""
|
||||
return self._a().route(text=text, sender_id=sender_id)
|
||||
|
||||
def enqueue_ordered_actions(
|
||||
self,
|
||||
*,
|
||||
text: str,
|
||||
sender_id: str,
|
||||
idempotency_key: str,
|
||||
) -> str:
|
||||
"""
|
||||
将 A 路由任务入 LLM 队列(快回路径用)。
|
||||
|
||||
返回 stream entry id;无 LlmGateway 时抛错。
|
||||
"""
|
||||
if self.llm is None:
|
||||
raise RuntimeError("IntentRouter 未注入 LlmGateway")
|
||||
result = self.llm.enqueue(
|
||||
mode=LlmMode.ORDERED_ACTIONS,
|
||||
payload={"text": text, "sender_id": sender_id},
|
||||
idempotency_key=idempotency_key,
|
||||
)
|
||||
if not result.accepted:
|
||||
raise RuntimeError(result.reason or "enqueue_rejected")
|
||||
return result.entry_id
|
||||
|
||||
|
||||
__all__ = [
|
||||
"RouteDecision",
|
||||
"IntentRouter",
|
||||
"DeepSeekARouter",
|
||||
"ORDERED_ACTIONS_TOOL_NAME",
|
||||
"OrderedActionsError",
|
||||
"OrderedActionsResult",
|
||||
"ordered_actions_tool_definition",
|
||||
"parse_ordered_actions_arguments",
|
||||
"HANDLER_REGISTRY",
|
||||
"dispatch_inbound",
|
||||
"resolve_handler",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user