666ghj commited on
Commit
5fabca4
·
1 Parent(s): 53f0f05

Refactor content handling in activity logging and simulation scripts

Browse files

- Removed content truncation logic from the AgentActivity class, allowing full content to be logged for posts, comments, and quotes.
- Updated the `fetch_new_actions_from_db` function to retain complete content in action arguments, enhancing data accuracy.
- Adjusted simulation scripts to ensure that full content is sent during action creation, improving the representation of agent activities.

backend/app/services/zep_graph_memory_updater.py CHANGED
@@ -63,9 +63,6 @@ class AgentActivity:
63
  def _describe_create_post(self) -> str:
64
  content = self.action_args.get("content", "")
65
  if content:
66
- # 截取内容,避免过长
67
- if len(content) > 300:
68
- content = content[:300] + "..."
69
  return f"发布了一条帖子:「{content}」"
70
  return "发布了一条帖子"
71
 
@@ -86,7 +83,7 @@ class AgentActivity:
86
  content = self.action_args.get("content", "")
87
  if quoted_id:
88
  if content:
89
- return f"引用帖子#{quoted_id}并评论:「{content[:100]}{'...' if len(content) > 100 else ''}」"
90
  return f"引用了帖子#{quoted_id}"
91
  return "引用了一条帖子"
92
 
@@ -98,8 +95,6 @@ class AgentActivity:
98
  content = self.action_args.get("content", "")
99
  post_id = self.action_args.get("post_id", "")
100
  if content:
101
- if len(content) > 200:
102
- content = content[:200] + "..."
103
  base = f"评论道:「{content}」"
104
  if post_id:
105
  base = f"在帖子#{post_id}下{base}"
 
63
  def _describe_create_post(self) -> str:
64
  content = self.action_args.get("content", "")
65
  if content:
 
 
 
66
  return f"发布了一条帖子:「{content}」"
67
  return "发布了一条帖子"
68
 
 
83
  content = self.action_args.get("content", "")
84
  if quoted_id:
85
  if content:
86
+ return f"引用帖子#{quoted_id}并评论:「{content}」"
87
  return f"引用了帖子#{quoted_id}"
88
  return "引用了一条帖子"
89
 
 
95
  content = self.action_args.get("content", "")
96
  post_id = self.action_args.get("post_id", "")
97
  if content:
 
 
98
  base = f"评论道:「{content}」"
99
  if post_id:
100
  base = f"在帖子#{post_id}下{base}"
backend/scripts/run_parallel_simulation.py CHANGED
@@ -251,12 +251,10 @@ def fetch_new_actions_from_db(
251
  except json.JSONDecodeError:
252
  action_args = {}
253
 
254
- # 精简 action_args,只保留关键字段
255
  simplified_args = {}
256
  if 'content' in action_args:
257
- content = action_args['content']
258
- # 截断过长的内容
259
- simplified_args['content'] = content[:200] + '...' if len(content) > 200 else content
260
  if 'post_id' in action_args:
261
  simplified_args['post_id'] = action_args['post_id']
262
  if 'comment_id' in action_args:
@@ -492,7 +490,7 @@ async def run_twitter_simulation(
492
  agent_id=agent_id,
493
  agent_name=agent_names.get(agent_id, f"Agent_{agent_id}"),
494
  action_type="CREATE_POST",
495
- action_args={"content": content[:100] + "..." if len(content) > 100 else content}
496
  )
497
  total_actions += 1
498
  initial_action_count += 1
@@ -677,7 +675,7 @@ async def run_reddit_simulation(
677
  agent_id=agent_id,
678
  agent_name=agent_names.get(agent_id, f"Agent_{agent_id}"),
679
  action_type="CREATE_POST",
680
- action_args={"content": content[:100] + "..." if len(content) > 100 else content}
681
  )
682
  total_actions += 1
683
  initial_action_count += 1
 
251
  except json.JSONDecodeError:
252
  action_args = {}
253
 
254
+ # 精简 action_args,只保留关键字段(保留完整内容,不截断)
255
  simplified_args = {}
256
  if 'content' in action_args:
257
+ simplified_args['content'] = action_args['content']
 
 
258
  if 'post_id' in action_args:
259
  simplified_args['post_id'] = action_args['post_id']
260
  if 'comment_id' in action_args:
 
490
  agent_id=agent_id,
491
  agent_name=agent_names.get(agent_id, f"Agent_{agent_id}"),
492
  action_type="CREATE_POST",
493
+ action_args={"content": content}
494
  )
495
  total_actions += 1
496
  initial_action_count += 1
 
675
  agent_id=agent_id,
676
  agent_name=agent_names.get(agent_id, f"Agent_{agent_id}"),
677
  action_type="CREATE_POST",
678
+ action_args={"content": content}
679
  )
680
  total_actions += 1
681
  initial_action_count += 1