add long term objective

This commit is contained in:
bridge
2025-11-19 00:04:38 +08:00
parent 8a4e5ddd87
commit d2cf568154
10 changed files with 291 additions and 18 deletions

View File

@@ -148,9 +148,21 @@ class AvatarLoadMixin:
# 设置行动与AI
avatar.thinking = data.get("thinking", "")
avatar.objective = data.get("objective", "")
avatar.short_term_objective = data.get("short_term_objective", data.get("objective", "")) # 兼容旧存档
avatar._action_cd_last_months = data.get("_action_cd_last_months", {})
# 加载长期目标
long_term_objective_data = data.get("long_term_objective")
if long_term_objective_data:
from src.classes.long_term_objective import LongTermObjective
avatar.long_term_objective = LongTermObjective(
content=long_term_objective_data.get("content", ""),
origin=long_term_objective_data.get("origin", "llm"),
set_year=long_term_objective_data.get("set_year", 100)
)
else:
avatar.long_term_objective = None
# 重建planned_actions
planned_actions_data = data.get("planned_actions", [])
avatar.planned_actions = [ActionPlan.from_dict(plan_data) for plan_data in planned_actions_data]

View File

@@ -95,7 +95,12 @@ class AvatarSaveMixin:
"current_action": current_action_dict,
"planned_actions": planned_actions_list,
"thinking": self.thinking,
"objective": self.objective,
"short_term_objective": self.short_term_objective,
"long_term_objective": {
"content": self.long_term_objective.content,
"origin": self.long_term_objective.origin,
"set_year": self.long_term_objective.set_year
} if self.long_term_objective else None,
"_action_cd_last_months": self._action_cd_last_months,
}

View File

@@ -13,6 +13,7 @@ from src.utils.config import CONFIG
from src.run.log import get_logger
from src.classes.fortune import try_trigger_fortune
from src.classes.celestial_phenomenon import get_random_celestial_phenomenon
from src.classes.long_term_objective import process_avatar_long_term_objective
class Simulator:
def __init__(self, world: World):
@@ -33,9 +34,9 @@ class Simulator:
ai = llm_ai
decide_results = await ai.decide(self.world, avatars_to_decide)
for avatar, result in decide_results.items():
action_name_params_pairs, avatar_thinking, objective, _event = result
action_name_params_pairs, avatar_thinking, short_term_objective, _event = result
# 仅入队计划,不在此处添加开始事件,避免与提交阶段重复
avatar.load_decide_result_chain(action_name_params_pairs, avatar_thinking, objective)
avatar.load_decide_result_chain(action_name_params_pairs, avatar_thinking, short_term_objective)
def _phase_commit_next_plans(self):
"""
@@ -135,6 +136,18 @@ class Simulator:
events.append(event)
return events
async def _phase_long_term_objective_thinking(self):
"""
长期目标思考阶段
检查角色是否需要生成/更新长期目标
"""
events = []
for avatar in list(self.world.avatar_manager.avatars.values()):
event = await process_avatar_long_term_objective(avatar)
if event:
events.append(event)
return events
def _phase_update_celestial_phenomenon(self):
"""
更新天地灵机:
@@ -209,6 +222,9 @@ class Simulator:
"""
events = [] # list of Event
# 0.5 长期目标思考阶段(在决策之前)
events.extend(await self._phase_long_term_objective_thinking())
# 1. 决策阶段
await self._phase_decide_actions()