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

@@ -19,7 +19,7 @@ ModelType = Literal["LLM", "ASR", "TTS", "Realtime", "Embedding", "Agent"]
AssistantType = Literal["prompt", "workflow", "dify", "fastgpt", "opencode"]
TurnEndStrategy = Literal["silence", "smart_turn"]
KnowledgeRetrievalMode = Literal["automatic", "on_demand"]
ToolType = Literal["end_call", "http", "mcp", "client"]
ToolType = Literal["system", "http", "mcp", "client"]
ToolStatus = Literal["active", "archived", "draft"]
McpServerStatus = Literal["active", "archived", "draft"]
McpTransport = Literal["streamable_http", "sse"]
@@ -30,6 +30,12 @@ ClientToolResponseWaitMode = Literal["timeout", "session"]
DynamicVariableType = Literal["string", "number", "boolean"]
PromptEntryMode = Literal["wait_user", "generate"]
PromptOpeningMode = Literal["interruptible", "playback", "confirmation"]
SystemToolKind = Literal[
"end_conversation",
"update_state",
"skip_turn",
"request_human_handoff",
]
# 外部应用类型:其 config.apiKey 是该助手私有密钥,读时打码 / 写时哨兵
EXTERNAL_TYPES = {"dify", "fastgpt", "opencode"}
@@ -153,6 +159,8 @@ class AssistantUpsert(CamelModel):
startup: StartupConfig = Field(default_factory=StartupConfig)
vision_enabled: bool = False
vision_model_resource_id: str | None = None
# 内置系统工具开关(仅 prompt 类型可用,类似 ElevenLabs Agent 的系统工具)。
system_tools: list[SystemToolKind] = Field(default_factory=list, max_length=4)
model_resource_ids: dict[ModelType, str] = Field(default_factory=dict)
knowledge_base_id: str | None = None
@@ -191,6 +199,8 @@ class AssistantUpsert(CamelModel):
for field in ("prompt", "api_url", "api_key", "app_id"):
if field not in allowed:
setattr(self, field, "")
if self.type != "prompt":
self.system_tools = []
if "graph" not in allowed:
self.graph = {}
if self.type == "workflow":
@@ -210,6 +220,15 @@ class AssistantUpsert(CamelModel):
# 外部托管大脑只能 cascade,拦住不兼容的 realtime
if self.runtime_mode == "realtime" and self.type not in REALTIME_CAPABLE_TYPES:
raise ValueError(f"类型 {self.type} 不支持 realtime 运行模式")
if self.type == "prompt":
self.system_tools = list(dict.fromkeys(self.system_tools))
if self.runtime_mode == "realtime" and self.system_tools:
raise ValueError("Prompt Realtime 模式暂不支持系统工具")
if (
"update_state" in self.system_tools
and not self.dynamic_variable_definitions
):
raise ValueError("启用更新状态工具前必须声明至少一个动态变量")
return self
@@ -250,7 +269,8 @@ class ToolParameter(CamelModel):
required: bool = True
class EndCallToolConfig(CamelModel):
class SystemToolConfig(CamelModel):
kind: Literal["end_conversation"] = "end_conversation"
message_type: Literal["none", "custom"] = "none"
custom_message: str = ""
capture_reason: bool = True
@@ -275,10 +295,10 @@ class HttpToolConfig(CamelModel):
return value
class EndCallToolDefinition(CamelModel):
class SystemToolDefinition(CamelModel):
schema_version: int = 1
type: Literal["end_call"] = "end_call"
config: EndCallToolConfig = Field(default_factory=EndCallToolConfig)
type: Literal["system"] = "system"
config: SystemToolConfig = Field(default_factory=SystemToolConfig)
class HttpToolDefinition(CamelModel):
@@ -326,7 +346,7 @@ class McpToolDefinition(CamelModel):
ToolDefinition = Annotated[
Union[
EndCallToolDefinition,
SystemToolDefinition,
HttpToolDefinition,
ClientToolDefinition,
McpToolDefinition,