feat: add system tools and state updates

This commit is contained in:
Xin Wang
2026-08-04 15:27:39 +08:00
parent 5bf5987fe4
commit 731a372df9
33 changed files with 1787 additions and 124 deletions

View File

@@ -36,6 +36,35 @@ def _validate_workflow(body: AssistantUpsert) -> None:
return
body.graph = normalize_graph(body.graph or {})
errors = validate_graph(body.graph)
declared_variables = set(body.dynamic_variable_definitions)
for node in body.graph.get("nodes") or []:
node_id = str(node.get("id") or "")
node_type = node.get("type")
data = node.get("data") or {}
if node_type == "update_state":
unknown = sorted(
set((data.get("assignments") or {}).keys()) - declared_variables
)
if unknown:
errors.append(
f"Update State 节点 {node_id} 引用了未声明变量:"
+ ",".join(unknown)
)
elif node_type == "agent":
authorized = set(data.get("stateVariableNames") or [])
unknown = sorted(authorized - declared_variables)
if unknown:
errors.append(
f"Agent 节点 {node_id} 授权了未声明变量:"
+ ",".join(unknown)
)
if (
"update_state" in (data.get("systemTools") or [])
and not authorized
):
errors.append(
f"Agent 节点 {node_id} 启用更新状态工具时必须授权至少一个变量"
)
if errors:
raise HTTPException(400, "工作流校验失败:" + ";".join(errors))
# Graph settings are the source of truth. The flat flag is only a session
@@ -283,6 +312,7 @@ async def _to_out(session: AsyncSession, assistant: Assistant) -> AssistantOut:
enable_interrupt=assistant.enable_interrupt,
turn_config=assistant.turn_config or {},
startup=assistant.startup or {},
system_tools=assistant.system_tools or [],
vision_enabled=assistant.vision_enabled,
vision_model_resource_id=assistant.vision_model_resource_id,
model_resource_ids=await _resource_ids(session, assistant.id),
@@ -359,6 +389,7 @@ async def duplicate_assistant(
enable_interrupt=source.enable_interrupt,
turn_config=dict(source.turn_config or {}),
startup=dict(source.startup or {}),
system_tools=list(source.system_tools or []),
vision_enabled=source.vision_enabled,
vision_model_resource_id=source.vision_model_resource_id,
knowledge_base_id=source.knowledge_base_id,