Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions agentmain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys, threading, queue, time, json, re, random, locale
import os, sys, threading, queue, time, json, re, random, locale, readline
os.environ.setdefault('GA_LANG', 'zh' if any(k in (locale.getlocale()[0] or '').lower() for k in ('zh', 'chinese')) else 'en')
if sys.stdout is None: sys.stdout = open(os.devnull, "w")
elif hasattr(sys.stdout, 'reconfigure'): sys.stdout.reconfigure(errors='replace')
Expand Down Expand Up @@ -111,8 +111,17 @@ def _handle_slash_cmd(self, raw_query, display_queue):
setattr(self.llmclient.backend, k, v)
display_queue.put({'done': smart_format(f"✅ session.{k} = {repr(v)}", max_str_len=500), 'source': 'system'})
return None
if raw_query.strip() == '/resume':
return r'用re.findall(r"<history>\\n\[(?:USER\|Agent)\].*?</history>", content, re.DOTALL) 扫temp/model_responses/下时间最近的10个文件(除本PID),取每文件最后一个匹配(注意JSON里换行是字面\\n)作为该会话内容,按mtime倒序,每个用一句话总结聊了什么让我选择;选定后再简单读该文件末尾作为聊天基础'
if raw_query.strip() == '/new':
from frontends.continue_cmd import reset_conversation
msg = reset_conversation(self)
display_queue.put({'done': msg, 'source': 'system'})
return None
if raw_query.strip() in ('/resume', '/continue') or re.match(r'/continue\s+\d+', raw_query.strip()):
if raw_query.strip() == '/resume':
return r'用re.findall(r"<history>\\n\[(?:USER\|Agent)\].*?</history>", content, re.DOTALL) 扫temp/model_responses/下时间最近的10个文件(除本PID),取每文件最后一个匹配(注意JSON里换行是字面\\n)作为该会话内容,按mtime倒序,每个用一句话总结聊了什么让我选择;选定后再简单读该文件末尾作为聊天基础'
from frontends.continue_cmd import handle as continue_handle
result = continue_handle(self, raw_query, display_queue)
return result
return raw_query

def run(self):
Expand All @@ -127,8 +136,7 @@ def run(self):
self.history.append(f"[USER]: {rquery}")

sys_prompt = get_system_prompt() + getattr(self.llmclient.backend, 'extra_sys_prompt', '')
script_dir = os.path.dirname(os.path.abspath(__file__))
handler = GenericAgentHandler(self, self.history, os.path.join(script_dir, 'temp'))
handler = GenericAgentHandler(self, self.history, os.getcwd())
if self.handler and 'key_info' in self.handler.working:
ki = re.sub(r'\n\[SYSTEM\] 此为.*?工作记忆[。\n]*', '', self.handler.working['key_info']) # 去旧
handler.working['key_info'] = ki
Expand Down
21 changes: 21 additions & 0 deletions assets/sys_prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@
调用工具前在 <thinking> 内推演:当前阶段、上步结果是否符合预期、下步策略。
- 探测优先:失败时先充分获取信息(日志/状态/上下文),关键信息存入工作记忆,再决定重试或换方案。不可逆操作先询问用户。
- 失败升级:1次→读错误理解原因,2次→探测环境状态,3次→深度分析后换方案或问用户。禁止无新信息的重复操作。

## 输出格式规范
你在终端环境中运行,终端无法渲染markdown。严格遵守以下格式:
- 禁止使用markdown语法(**粗体**、##标题、```代码块```、>引用等)
- 标题/分区用:━━━ 标题 ━━━
- 分割线用:──────────────
- 无序列表用:▸ 条目
- 有序列表用:① ② ③
- 引用/备注用:┃ 内容
- 强调关键词用:【关键词】
- 表格用 box-drawing 字符绘制,遵守对齐规则:
每个中文字符/全角符号占2个半角空格宽度。表头和数据行严格对齐│竖线。同一列内,短内容用半角空格补齐到该列最大宽度。
每行数据之间用├─┼─┤分隔。正确示例:
┌──────────┬──────────┐
│ 名称 │ 状态 │
├──────────┼──────────┤
│ test │ ok │
├──────────┼──────────┤
│ 部署 │ 完成 │
└──────────┴──────────┘
如果某列内容中英混杂严重难以对齐,则对该列改用缩进列表。
8 changes: 5 additions & 3 deletions ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,11 @@ def get_global_memory():
suffix = '_en' if os.environ.get('GA_LANG', '') == 'en' else ''
with open(os.path.join(script_dir, 'memory/global_mem_insight.txt'), 'r', encoding='utf-8', errors='replace') as f: insight = f.read()
with open(os.path.join(script_dir, f'assets/insight_fixed_structure{suffix}.txt'), 'r', encoding='utf-8') as f: structure = f.read()
prompt += f'cwd = {os.path.join(script_dir, "temp")} (./)\n'
prompt += f"\n[Memory] (../memory)\n"
prompt += structure + '\n../memory/global_mem_insight.txt:\n'
structure = structure.replace('../', script_dir + '/')
insight = insight.replace('../', script_dir + '/')
prompt += f'cwd = {os.getcwd()} (./)\n'
prompt += f"\n[Memory] ({os.path.join(script_dir, 'memory')})\n"
prompt += structure + f'\n{os.path.join(script_dir, "memory/global_mem_insight.txt")}:\n'
prompt += insight + "\n"
except FileNotFoundError: pass
return prompt