feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持
This commit is contained in:
1 parent
ac4262cd75
commit
c8ce77199e
183 files changed
+11690
-2300
No files matched your search
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
backend/app/services/chat/executors/base.py
|
||||
|
||||
用途:聊天 Executor 基类与 Dify 流构建辅助。
|
||||
依赖:agent_runtime_context.dify_inputs、agent_registry.handlers。
|
||||
逻辑:各 runtime_provider Executor 实现 stream() 返回上游 SSE 行迭代器。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Iterator
|
||||
|
||||
from app.services.agent_registry.handlers.base import ChatStreamContext
|
||||
|
||||
|
||||
class ChatExecutor(ABC):
|
||||
"""聊天运行时 Executor 基类。"""
|
||||
|
||||
provider_key: str = ''
|
||||
|
||||
@abstractmethod
|
||||
def stream(self, ctx: ChatStreamContext) -> Iterator[str]:
|
||||
"""
|
||||
产出上游 SSE 行(`data: {...}\\n\\n`)。
|
||||
|
||||
Args:
|
||||
ctx: 聊天流上下文。
|
||||
"""
|
||||
|
||||
|
||||
def build_dify_inputs_for_context(ctx: ChatStreamContext) -> dict[str, Any]:
|
||||
"""调用 Context Adapter Registry 构建 Dify inputs。"""
|
||||
from app.services.agent_runtime_context.dify_inputs import build_chat_dify_inputs
|
||||
|
||||
return build_chat_dify_inputs(
|
||||
ctx.agent,
|
||||
session_id=str(getattr(ctx.session, 'session_id', '') or ''),
|
||||
request_id=ctx.request_id,
|
||||
trigger_source='frontend_chat',
|
||||
adapter_hints=ctx.adapter_hints,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'ChatExecutor',
|
||||
'ChatStreamContext',
|
||||
'build_dify_inputs_for_context',
|
||||
]
|
||||
Reference in new issue
Block a user