55 lines
2.9 KiB
Python
55 lines
2.9 KiB
Python
"""大周天内驱力模型(database-schema §22;intrinsic-drive §5)。
|
||
|
||
好奇问题记录「匮乏感」,探索性次生目标由好奇问题转化而来、可审核(candidate →
|
||
approved/deferred/rejected)。``cycle_id`` 关联触发本次的大周天循环。
|
||
"""
|
||
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import DateTime, Float, ForeignKey, String, Text
|
||
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
||
from app.core.ids import new_curiosity_id, new_subgoal_id
|
||
from app.core.time import utc_now
|
||
from app.db.base import Base
|
||
|
||
|
||
class CuriosityQuestion(Base):
|
||
"""好奇问题(缺口记录,无审核状态)。"""
|
||
|
||
__tablename__ = "curiosity_questions"
|
||
|
||
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_curiosity_id)
|
||
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
|
||
cycle_id: Mapped[str] = mapped_column(String(80), ForeignKey("big_cycles.id"), index=True)
|
||
question: Mapped[str] = mapped_column(Text, nullable=False)
|
||
source: Mapped[str] = mapped_column(String(60), nullable=False, default="reflection")
|
||
related_entities_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
|
||
expected_value: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
|
||
urgency: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
|
||
risk_level: Mapped[str] = mapped_column(String(8), nullable=False, default="L4")
|
||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
|
||
|
||
|
||
class ExploratorySubgoal(Base):
|
||
"""探索性次生目标(可审核,本期不自动执行)。"""
|
||
|
||
__tablename__ = "exploratory_subgoals"
|
||
|
||
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_subgoal_id)
|
||
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
|
||
cycle_id: Mapped[str] = mapped_column(String(80), ForeignKey("big_cycles.id"), index=True)
|
||
parent_goal_id: Mapped[str | None] = mapped_column(String(80))
|
||
curiosity_question_id: Mapped[str] = mapped_column(
|
||
String(80), ForeignKey("curiosity_questions.id"), index=True
|
||
)
|
||
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
||
description: Mapped[str] = mapped_column(Text, nullable=False)
|
||
expected_information_gain: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
|
||
interruption_cost: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
|
||
risk_level: Mapped[str] = mapped_column(String(8), nullable=False, default="L4")
|
||
status: Mapped[str] = mapped_column(String(40), nullable=False, default="candidate", index=True)
|
||
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||
reviewed_by: Mapped[str] = mapped_column(String(80), nullable=False, default="system")
|
||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
|