From e4761dab069889b06930284b222c0a2bb59847d4 Mon Sep 17 00:00:00 2001 From: 666ghj <670939375@qq.com> Date: Fri, 5 Dec 2025 16:26:04 +0800 Subject: [PATCH] Enhance action logging in simulation scripts - Added logging for the start and end of round 0 in both Twitter and Reddit simulations, improving traceability of initial events. - Updated the logging mechanism to record round end even when no active agents are present, ensuring comprehensive action tracking. - Introduced initial action count tracking to provide insights into the number of actions taken during the initial phase of simulations. --- backend/scripts/run_parallel_simulation.py | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/backend/scripts/run_parallel_simulation.py b/backend/scripts/run_parallel_simulation.py index 3d706c5..9277aba 100644 --- a/backend/scripts/run_parallel_simulation.py +++ b/backend/scripts/run_parallel_simulation.py @@ -469,6 +469,11 @@ async def run_twitter_simulation( event_config = config.get("event_config", {}) initial_posts = event_config.get("initial_posts", []) + # 记录 round 0 开始(初始事件阶段) + if action_logger: + action_logger.log_round_start(0, 0) # round 0, simulated_hour 0 + + initial_action_count = 0 if initial_posts: initial_actions = {} for post in initial_posts: @@ -490,6 +495,7 @@ async def run_twitter_simulation( action_args={"content": content[:100] + "..." if len(content) > 100 else content} ) total_actions += 1 + initial_action_count += 1 except Exception: pass @@ -497,6 +503,10 @@ async def run_twitter_simulation( await env.step(initial_actions) log_info(f"已发布 {len(initial_actions)} 条初始帖子") + # 记录 round 0 结束 + if action_logger: + action_logger.log_round_end(0, initial_action_count) + # 主模拟循环 time_config = config.get("time_config", {}) total_hours = time_config.get("total_simulation_hours", 72) @@ -521,12 +531,16 @@ async def run_twitter_simulation( env, config, simulated_hour, round_num ) - if not active_agents: - continue - + # 无论是否有活跃agent,都记录round开始 if action_logger: action_logger.log_round_start(round_num + 1, simulated_hour) + if not active_agents: + # 没有活跃agent时也记录round结束(actions_count=0) + if action_logger: + action_logger.log_round_end(round_num + 1, 0) + continue + actions = {agent: LLMAction() for _, agent in active_agents} await env.step(actions) @@ -632,6 +646,11 @@ async def run_reddit_simulation( event_config = config.get("event_config", {}) initial_posts = event_config.get("initial_posts", []) + # 记录 round 0 开始(初始事件阶段) + if action_logger: + action_logger.log_round_start(0, 0) # round 0, simulated_hour 0 + + initial_action_count = 0 if initial_posts: initial_actions = {} for post in initial_posts: @@ -661,6 +680,7 @@ async def run_reddit_simulation( action_args={"content": content[:100] + "..." if len(content) > 100 else content} ) total_actions += 1 + initial_action_count += 1 except Exception: pass @@ -668,6 +688,10 @@ async def run_reddit_simulation( await env.step(initial_actions) log_info(f"已发布 {len(initial_actions)} 条初始帖子") + # 记录 round 0 结束 + if action_logger: + action_logger.log_round_end(0, initial_action_count) + # 主模拟循环 time_config = config.get("time_config", {}) total_hours = time_config.get("total_simulation_hours", 72) @@ -692,12 +716,16 @@ async def run_reddit_simulation( env, config, simulated_hour, round_num ) - if not active_agents: - continue - + # 无论是否有活跃agent,都记录round开始 if action_logger: action_logger.log_round_start(round_num + 1, simulated_hour) + if not active_agents: + # 没有活跃agent时也记录round结束(actions_count=0) + if action_logger: + action_logger.log_round_end(round_num + 1, 0) + continue + actions = {agent: LLMAction() for _, agent in active_agents} await env.step(actions)