初始化提交
This commit is contained in:
commit
887c1f449e
963 files changed
+166869
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"""太一枢(Goal Orchestrator)领域逻辑。
|
||||
|
||||
v1 落地 §7.1 最小闭环 + §7.2 预留扩展:
|
||||
- 从用户消息提取会话目标写入 ``run.goal``,并注入运行契约。
|
||||
- 活跃目标按优先级排序(``prioritize_active_goals``),供运行时注入。
|
||||
|
||||
目标持久化体系(``goals`` 表)、调度与冲突裁决属 §7.2 / §7.3。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.modules.goal_orchestrator.extract import (
|
||||
extract_session_goal,
|
||||
format_goal_directive,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"extract_session_goal",
|
||||
"format_goal_directive",
|
||||
"prioritize_active_goals",
|
||||
"complete_session_goal",
|
||||
]
|
||||
|
||||
|
||||
def prioritize_active_goals(
|
||||
goals: list[dict],
|
||||
) -> list[dict]:
|
||||
"""活跃目标优先级排序。
|
||||
|
||||
按以下规则返回排序后的目标列表(最高优先级在前):
|
||||
1. ``priority`` 越小越优先(低数值 = 高优先级)
|
||||
2. ``priority`` 相同时 ``progress`` 越低越优先(未完成的优先)
|
||||
3. 层级越靠前越优先(L0 > L1 > L2 > L3 > L4)
|
||||
|
||||
Args:
|
||||
goals: 活跃目标字典列表,每个字典包含 ``title`` / ``level`` / ``priority`` / ``progress``。
|
||||
|
||||
Returns:
|
||||
排序后的目标列表。
|
||||
"""
|
||||
LEVEL_ORDER = {"L0": 0, "L1": 1, "L2": 2, "L3": 3, "L4": 4}
|
||||
|
||||
def _sort_key(g: dict) -> tuple:
|
||||
priority = g.get("priority")
|
||||
if priority is None:
|
||||
priority = 100
|
||||
progress = g.get("progress", 0) or 0
|
||||
level = LEVEL_ORDER.get(str(g.get("level", "")), 99)
|
||||
return (0 if priority is not None else 1, priority, level, progress)
|
||||
|
||||
return sorted(goals, key=_sort_key)
|
||||
|
||||
|
||||
def complete_session_goal(
|
||||
goal: dict,
|
||||
) -> dict:
|
||||
"""将会话目标标记为完成。
|
||||
|
||||
Args:
|
||||
goal: 会话目标字典,包含 ``id`` / ``title`` / ``level`` / ``status``。
|
||||
|
||||
Returns:
|
||||
更新后的目标字典(status=completed, progress=1.0)。
|
||||
"""
|
||||
return {
|
||||
**goal,
|
||||
"status": "completed",
|
||||
"progress": 1.0,
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
"""太一会话目标提取(纯函数,无 IO)。
|
||||
|
||||
从用户消息提取会话目标(L2)。v1 采用规则提取——用户消息本身即目标的最直接
|
||||
表达,清理与截断后写入 ``run.goal`` 并注入运行契约。LLM 提取为后续增强。
|
||||
"""
|
||||
|
||||
_MAX_GOAL_CHARS = 120
|
||||
|
||||
|
||||
def extract_session_goal(content: str) -> str:
|
||||
"""从用户消息内容提取会话目标摘要。
|
||||
|
||||
规则:去除首尾空白,超长截断到 ``_MAX_GOAL_CHARS``;空内容返回空串。
|
||||
"""
|
||||
goal = (content or "").strip()
|
||||
if not goal:
|
||||
return ""
|
||||
return goal[:_MAX_GOAL_CHARS]
|
||||
|
||||
|
||||
def format_goal_directive(goal: str) -> str:
|
||||
"""把会话目标格式化为运行契约的 system instruction 片段;空目标返回空串。"""
|
||||
if not goal:
|
||||
return ""
|
||||
return f"当前会话目标:{goal}"
|
||||
Reference in new issue
Block a user