myagent-ai 1.15.18 → 1.15.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/web/api_server.py +96 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myagent-ai",
3
- "version": "1.15.18",
3
+ "version": "1.15.19",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
package/web/api_server.py CHANGED
@@ -5253,14 +5253,62 @@ class ApiServer:
5253
5253
  model_chain = self._build_model_chain(agent_cfg, agent_path)
5254
5254
  session_id = f"group_{gid}_{agent_path}"
5255
5255
 
5256
+ # [v1.15.18] 构建 Agent 专属系统提示词(与1:1聊天一致)
5257
+ _, agent_system_prompt = self._build_agent_chat_context(agent_path, agent_cfg, content)
5258
+
5259
+ # [v1.15.18] 构建群聊上下文:群信息 + 成员列表 + 发言者身份
5260
+ member_lines = []
5261
+ for m in group.members:
5262
+ mc = self._read_agent_config(m.agent_path)
5263
+ m_name = mc.get("name", m.agent_path) if mc else m.agent_path
5264
+ m_desc = mc.get("description", "") if mc else ""
5265
+ role_label = {"owner": "群主", "admin": "管理员"}.get(m.role, "成员")
5266
+ nick = f"(昵称: {m.nickname})" if m.nickname else ""
5267
+ line = f" - {m_name} [{m.agent_path}] ({role_label})"
5268
+ if m_desc:
5269
+ line += f" — {m_desc}"
5270
+ line += nick
5271
+ if m.muted:
5272
+ line += "(已禁言)"
5273
+ member_lines.append(line)
5274
+
5275
+ my_name = agent_cfg.get("name", agent_path) if agent_cfg else agent_path
5276
+ my_role = {"owner": "群主", "admin": "管理员"}.get(member.role, "成员")
5277
+ my_desc = agent_cfg.get("description", "") if agent_cfg else ""
5278
+
5279
+ group_context = (
5280
+ f"## 群聊上下文\n"
5281
+ f"- 群名称: {group.name}\n"
5282
+ f"- 群ID: {group.id}\n"
5283
+ f"- 群描述: {group.description}\n"
5284
+ f"- 当前发言者: 用户\n"
5285
+ f"- 你的身份: {my_name} ({my_role})"
5286
+ + (f" — {my_desc}" if my_desc else "")
5287
+ + f"\n- 群成员 ({len(group.members)}人):\n"
5288
+ + "\n".join(member_lines)
5289
+ + "\n\n注意:你只代表自己发言,回复时使用第一人称。"
5290
+ "如果消息不是跟你相关的,可以简短回复或不回复。"
5291
+ )
5292
+
5293
+ # 将群聊上下文追加到 agent_system_prompt
5294
+ if agent_system_prompt:
5295
+ agent_system_prompt += "\n\n" + group_context
5296
+ else:
5297
+ agent_system_prompt = group_context
5298
+
5256
5299
  # 构建部门上下文(如果此群属于某个部门)
5257
- agent_content = content
5258
5300
  dept_context = self._build_dept_context(gid, agent_path)
5259
5301
  if dept_context:
5260
- agent_content = dept_context + "\n\n---\n\n" + content
5302
+ agent_system_prompt += "\n\n" + dept_context
5303
+
5304
+ # 构建最终消息(用户原文不包含任何注入内容)
5305
+ agent_content = content
5261
5306
 
5262
5307
  if model_chain and self.core.llm:
5263
- response = await self._try_model_chain(model_chain, agent_content, session_id)
5308
+ response = await self._try_model_chain(
5309
+ model_chain, agent_content, session_id,
5310
+ agent_path=agent_path, agent_system_prompt=agent_system_prompt,
5311
+ )
5264
5312
  else:
5265
5313
  response = await self.core.process_message(agent_content, session_id)
5266
5314
 
@@ -5446,14 +5494,55 @@ class ApiServer:
5446
5494
  model_chain = self._build_model_chain(agent_cfg, agent_path)
5447
5495
  session_id = f"group_{group_id}_{agent_path}"
5448
5496
 
5449
- # 构建部门上下文
5450
- agent_content = description
5497
+ # [v1.15.18] 构建 Agent 专属系统提示词 + 群聊上下文(与发送群消息一致)
5498
+ _, agent_system_prompt = self._build_agent_chat_context(agent_path, agent_cfg, description)
5499
+
5500
+ # 构建群聊上下文
5501
+ member_lines = []
5502
+ for m in group.members:
5503
+ mc = self._read_agent_config(m.agent_path)
5504
+ m_name = mc.get("name", m.agent_path) if mc else m.agent_path
5505
+ m_desc = mc.get("description", "") if mc else ""
5506
+ role_label = {"owner": "群主", "admin": "管理员"}.get(m.role, "成员")
5507
+ line = f" - {m_name} [{m.agent_path}] ({role_label})"
5508
+ if m_desc:
5509
+ line += f" — {m_desc}"
5510
+ member_lines.append(line)
5511
+
5512
+ my_name = agent_cfg.get("name", agent_path) if agent_cfg else agent_path
5513
+ my_role = {"owner": "群主", "admin": "管理员"}.get(member.role, "成员")
5514
+ my_desc = agent_cfg.get("description", "") if agent_cfg else ""
5515
+
5516
+ group_context = (
5517
+ f"## 群聊上下文\n"
5518
+ f"- 群名称: {group.name}\n"
5519
+ f"- 群ID: {group.id}\n"
5520
+ f"- 群描述: {group.description}\n"
5521
+ f"- 当前发言者: 用户(重试任务)\n"
5522
+ f"- 你的身份: {my_name} ({my_role})"
5523
+ + (f" — {my_desc}" if my_desc else "")
5524
+ + f"\n- 群成员 ({len(group.members)}人):\n"
5525
+ + "\n".join(member_lines)
5526
+ + "\n\n注意:你只代表自己发言,回复时使用第一人称。"
5527
+ "如果消息不是跟你相关的,可以简短回复或不回复。"
5528
+ )
5529
+
5530
+ if agent_system_prompt:
5531
+ agent_system_prompt += "\n\n" + group_context
5532
+ else:
5533
+ agent_system_prompt = group_context
5534
+
5451
5535
  dept_context = self._build_dept_context(group_id, agent_path)
5452
5536
  if dept_context:
5453
- agent_content = dept_context + "\n\n---\n\n" + description
5537
+ agent_system_prompt += "\n\n" + dept_context
5538
+
5539
+ agent_content = description
5454
5540
 
5455
5541
  if model_chain and self.core.llm:
5456
- response = await self._try_model_chain(model_chain, agent_content, session_id)
5542
+ response = await self._try_model_chain(
5543
+ model_chain, agent_content, session_id,
5544
+ agent_path=agent_path, agent_system_prompt=agent_system_prompt,
5545
+ )
5457
5546
  else:
5458
5547
  response = await self.core.process_message(agent_content, session_id)
5459
5548