42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""运行时契约。"""
|
||
|
||
from typing import Any
|
||
|
||
from pydantic import BaseModel, ConfigDict, Field
|
||
|
||
from app.modules.agent import AgentDefinition
|
||
|
||
|
||
class RuntimeContract(BaseModel):
|
||
"""从业务上下文传递给 LLM 基础设施的结构化契约。"""
|
||
|
||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||
|
||
character_id: str
|
||
session_id: str
|
||
run_id: str
|
||
model_hint: str
|
||
agent: AgentDefinition | None = None
|
||
system_instructions: list[str] = Field(default_factory=list)
|
||
# 卡的 system_prompt(酒馆):作道体增补层注入,绝不覆盖恒定层(§6 安全边界)
|
||
system_prompt: str | None = None
|
||
session_goal: str | None = None
|
||
personality_summary: str | None = None
|
||
# 道体核心使命(设计理念 §2.1):对应太一 highest goal 的恒定快照,组装时不可被覆盖。
|
||
mission: str | None = None
|
||
# 道体安全边界:人物自身基础行为约束(区别于司命 safety_constraints 的动态治理)
|
||
safety_guidelines: str | None = None
|
||
# 世谱(Lorebook)注入:before/after 相对 personality_summary 的位置(酒馆 before_char/after_char)
|
||
lorebook_before: str | None = None
|
||
lorebook_after: str | None = None
|
||
emotion_state: str | None = None
|
||
memory_context: str | None = None
|
||
temporal_context: str | None = None
|
||
active_goals: str | None = Field(
|
||
default=None,
|
||
description="格式化后的活跃目标上下文(由 build_goals_context 生成)。",
|
||
)
|
||
recent_messages: list[Any] = Field(default_factory=list)
|
||
safety_constraints: list[str] = Field(default_factory=list)
|
||
trace_id: str
|