2026-04-02 16:36:35 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from enum import Enum
|
2026-04-03 16:56:47 +08:00
|
|
|
from typing import Any, Literal
|
2026-04-02 16:36:35 +08:00
|
|
|
|
2026-04-03 16:56:47 +08:00
|
|
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
2026-04-02 16:36:35 +08:00
|
|
|
|
|
|
|
|
from schemas.agent.ui_hints import UiHintsPayload
|
2026-04-06 01:28:10 +08:00
|
|
|
from schemas.domain.divination import DerivedDivinationData
|
2026-04-02 16:36:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class RunStatus(str, Enum):
|
|
|
|
|
SUCCESS = "success"
|
|
|
|
|
FAILED = "failed"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolStatus(str, Enum):
|
|
|
|
|
SUCCESS = "success"
|
|
|
|
|
FAILURE = "failure"
|
|
|
|
|
PARTIAL = "partial"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorInfo(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
|
|
|
|
code: str
|
|
|
|
|
message: str
|
|
|
|
|
retryable: bool = False
|
|
|
|
|
details: dict[str, Any] | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolAgentOutput(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
|
|
|
|
tool_name: str
|
|
|
|
|
tool_call_id: str
|
|
|
|
|
tool_call_args: dict[str, Any] | None = None
|
|
|
|
|
status: ToolStatus
|
|
|
|
|
result: str
|
|
|
|
|
error: ErrorInfo | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkerAgentOutputLite(BaseModel):
|
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
|
|
|
|
status: RunStatus = RunStatus.SUCCESS
|
2026-04-06 01:28:10 +08:00
|
|
|
sign_level: Literal["上上签", "中上签", "中下签", "下下签"]
|
2026-04-03 16:56:47 +08:00
|
|
|
summary: str = Field(min_length=1, max_length=300)
|
|
|
|
|
conclusion: list[str] = Field(min_length=1, max_length=6)
|
|
|
|
|
focus_points: list[str] = Field(default_factory=list, max_length=6)
|
|
|
|
|
advice: list[str] = Field(min_length=1, max_length=6)
|
|
|
|
|
keywords: list[str] = Field(min_length=3, max_length=8)
|
|
|
|
|
answer: str = Field(min_length=1, max_length=4000)
|
2026-04-02 16:36:35 +08:00
|
|
|
error: ErrorInfo | None = None
|
|
|
|
|
|
2026-04-03 16:56:47 +08:00
|
|
|
# Backward-compatible shadow fields for legacy consumers.
|
|
|
|
|
key_points: list[str] = Field(default_factory=list, max_length=6)
|
|
|
|
|
result_type: str = Field(default="structured_payload")
|
|
|
|
|
suggested_actions: list[str] = Field(default_factory=list, max_length=6)
|
2026-04-06 01:28:10 +08:00
|
|
|
divination_derived: DerivedDivinationData | None = None
|
2026-04-03 16:56:47 +08:00
|
|
|
|
|
|
|
|
@model_validator(mode="after")
|
|
|
|
|
def sync_compatibility_fields(self) -> WorkerAgentOutputLite:
|
|
|
|
|
if not self.key_points and self.focus_points:
|
|
|
|
|
self.key_points = list(self.focus_points)
|
|
|
|
|
if not self.suggested_actions and self.advice:
|
|
|
|
|
self.suggested_actions = list(self.advice)
|
|
|
|
|
return self
|
|
|
|
|
|
2026-04-02 16:36:35 +08:00
|
|
|
|
|
|
|
|
class WorkerAgentOutputRich(WorkerAgentOutputLite):
|
|
|
|
|
ui_hints: UiHintsPayload | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AgentOutput(WorkerAgentOutputRich):
|
|
|
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WorkerAgentOutput = WorkerAgentOutputLite | WorkerAgentOutputRich
|
|
|
|
|
|
|
|
|
|
|
2026-04-03 16:56:47 +08:00
|
|
|
def resolve_worker_output_model() -> type[WorkerAgentOutputLite]:
|
|
|
|
|
return WorkerAgentOutputLite
|