fix: refresh delegation permissions and report Reasoner task outcomes
This commit is contained in:
@@ -16,9 +16,29 @@ TASK_HINT = """
|
||||
"""
|
||||
|
||||
|
||||
async def load_current_backend(assistant_id, configured_backend, variable_definitions):
|
||||
"""Recheck task permissions at delegation, even during a long voice call."""
|
||||
from db.models import Assistant
|
||||
from db.session import SessionLocal
|
||||
from services.task_backend_resources import resolve_task_backend
|
||||
|
||||
async with SessionLocal() as session:
|
||||
assistant = await session.get(Assistant, assistant_id)
|
||||
if assistant is None:
|
||||
raise ValueError("助手已删除,不能创建新任务")
|
||||
if (assistant.dynamic_variable_definitions or {}) != variable_definitions:
|
||||
raise ValueError("助手变量配置已更新,请重新连接后再委派任务")
|
||||
current = await resolve_task_backend(session, assistant)
|
||||
if (current is None or current.id != configured_backend.id
|
||||
or current.instruction_source != configured_backend.instruction_source):
|
||||
raise ValueError("助手任务绑定已更新,请重新连接后再委派任务")
|
||||
return current
|
||||
|
||||
|
||||
class PromptTaskBridge:
|
||||
def __init__(self, cfg, runtime, executor, service=task_service):
|
||||
def __init__(self, cfg, runtime, executor, service=task_service, backend_loader=load_current_backend):
|
||||
self.cfg, self.runtime, self.executor, self.service = cfg, runtime, executor, service
|
||||
self._backend_loader = backend_loader
|
||||
self._announced = set()
|
||||
self._detach = service.subscribe(runtime.session_id, self.on_task) if runtime.transport is not None else lambda: None
|
||||
|
||||
@@ -39,6 +59,8 @@ class PromptTaskBridge:
|
||||
await params.result_callback({"status": "error", "message": "自动测试不启动真实后台任务,请使用语音调试验证"})
|
||||
return
|
||||
try:
|
||||
assistant_id = self.cfg.dynamic_variables.get("system__agent_id", "")
|
||||
current_backend = await self._backend_loader(assistant_id, backend, self.cfg.dynamic_variable_definitions)
|
||||
kind = source.get("source")
|
||||
if kind == "model":
|
||||
instruction = (params.arguments or {}).get("instruction")
|
||||
@@ -53,9 +75,9 @@ class PromptTaskBridge:
|
||||
if not isinstance(instruction, str):
|
||||
raise ValueError("任务指令必须是字符串")
|
||||
result = await self.service.submit(
|
||||
assistant_id=self.cfg.dynamic_variables.get("system__agent_id", ""),
|
||||
assistant_id=assistant_id,
|
||||
conversation_id=self.cfg.conversation_id,
|
||||
backend=backend, instruction=instruction, invocation_id=params.tool_call_id,
|
||||
backend=current_backend, instruction=instruction, invocation_id=params.tool_call_id,
|
||||
variable_state={"values": self.executor.store.values,
|
||||
"definitions": self.cfg.dynamic_variable_definitions,
|
||||
"secrets": self.executor.store.secrets},
|
||||
|
||||
Reference in New Issue
Block a user