fix: add requests to pip install & tune max_turns/prompt

This commit is contained in:
Jiaqing Liang
2026-04-23 17:21:05 +08:00
parent fd4c833511
commit 6091bf0c6f
4 changed files with 11 additions and 18 deletions

View File

@@ -79,7 +79,7 @@ git clone https://github.com/lsdefine/GenericAgent.git
cd GenericAgent cd GenericAgent
# 2. Install minimal dependencies # 2. Install minimal dependencies
pip install streamlit pywebview pip install requests streamlit pywebview
# 3. Configure API Key # 3. Configure API Key
cp mykey_template.py mykey.py cp mykey_template.py mykey.py
@@ -283,7 +283,7 @@ git clone https://github.com/lsdefine/GenericAgent.git
cd GenericAgent cd GenericAgent
# 2. 安装最小依赖 # 2. 安装最小依赖
pip install streamlit pywebview pip install requests streamlit pywebview
# 3. 配置 API Key # 3. 配置 API Key
cp mykey_template.py mykey.py cp mykey_template.py mykey.py

View File

@@ -141,7 +141,7 @@ class GeneraticAgent:
if 'gpt' in self.get_llm_name(model=True): handler._done_hooks.append('请确定任务是否完成如果完成请给出信息完整的简报回答如未完成需要继续工具调用直到完成任务确实需要问用户应使用ask_user工具') if 'gpt' in self.get_llm_name(model=True): handler._done_hooks.append('请确定任务是否完成如果完成请给出信息完整的简报回答如未完成需要继续工具调用直到完成任务确实需要问用户应使用ask_user工具')
# although new handler, the **full** history is in llmclient, so it is full history! # although new handler, the **full** history is in llmclient, so it is full history!
gen = agent_runner_loop(self.llmclient, sys_prompt, user_input, gen = agent_runner_loop(self.llmclient, sys_prompt, user_input,
handler, TOOLS_SCHEMA, max_turns=40, verbose=self.verbose) handler, TOOLS_SCHEMA, max_turns=70, verbose=self.verbose)
try: try:
full_resp = ""; last_pos = 0 full_resp = ""; last_pos = 0
for chunk in gen: for chunk in gen:

6
ga.py
View File

@@ -417,7 +417,7 @@ class GenericAgentHandler(BaseHandler):
def _in_plan_mode(self): return self.working.get('in_plan_mode') def _in_plan_mode(self): return self.working.get('in_plan_mode')
def _exit_plan_mode(self): self.working.pop('in_plan_mode', None) def _exit_plan_mode(self): self.working.pop('in_plan_mode', None)
def enter_plan_mode(self, plan_path): def enter_plan_mode(self, plan_path):
self.working['in_plan_mode'] = plan_path; self.max_turns = 80 self.working['in_plan_mode'] = plan_path; self.max_turns = 100
print(f"[Info] Entered plan mode with plan file: {plan_path}"); return plan_path print(f"[Info] Entered plan mode with plan file: {plan_path}"); return plan_path
def _check_plan_completion(self): def _check_plan_completion(self):
if not os.path.isfile(p:=self._in_plan_mode() or ''): return None if not os.path.isfile(p:=self._in_plan_mode() or ''): return None
@@ -525,7 +525,7 @@ class GenericAgentHandler(BaseHandler):
next_prompt += "\n[DANGER] 上一轮遗漏了<summary>,需要按协议在<summary>中输出极简单行摘要!" next_prompt += "\n[DANGER] 上一轮遗漏了<summary>,需要按协议在<summary>中输出极简单行摘要!"
summary = smart_format(summary, max_str_len=100) summary = smart_format(summary, max_str_len=100)
self.history_info.append(f'[Agent] {summary}') self.history_info.append(f'[Agent] {summary}')
if turn % 35 == 0 and 'plan' not in str(self.working.get('related_sop')): if turn % 65 == 0 and 'plan' not in str(self.working.get('related_sop')):
next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。你必须总结情况进行ask_user不允许继续重试。" next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。你必须总结情况进行ask_user不允许继续重试。"
elif turn % 7 == 0: elif turn % 7 == 0:
next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。禁止无效重试。若无有效进展必须切换策略1. 探测物理边界 2. 请求用户协助。如有需要,可调用 update_working_checkpoint 保存关键上下文。" next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。禁止无效重试。若无有效进展必须切换策略1. 探测物理边界 2. 请求用户协助。如有需要,可调用 update_working_checkpoint 保存关键上下文。"
@@ -533,7 +533,7 @@ class GenericAgentHandler(BaseHandler):
if (_plan := self._in_plan_mode()) and turn >= 10 and turn % 5 == 0: if (_plan := self._in_plan_mode()) and turn >= 10 and turn % 5 == 0:
next_prompt = f"[Plan Hint] 你正在计划模式。必须 file_read({_plan}) 确认当前步骤,回复开头引用:📌 当前步骤:...\n\n" + next_prompt next_prompt = f"[Plan Hint] 你正在计划模式。必须 file_read({_plan}) 确认当前步骤,回复开头引用:📌 当前步骤:...\n\n" + next_prompt
if _plan and turn >= 70: next_prompt += f"\n\n[DANGER] Plan模式已运行 {turn} 轮,已达上限。必须 ask_user 汇报进度并确认是否继续。" if _plan and turn >= 90: next_prompt += f"\n\n[DANGER] Plan模式已运行 {turn} 轮,已达上限。必须 ask_user 汇报进度并确认是否继续。"
injkeyinfo = consume_file(self.parent.task_dir, '_keyinfo') injkeyinfo = consume_file(self.parent.task_dir, '_keyinfo')
injprompt = consume_file(self.parent.task_dir, '_intervene') injprompt = consume_file(self.parent.task_dir, '_intervene')

View File

@@ -315,8 +315,7 @@ def _stamp_oai_cache_markers(messages, model):
def _openai_stream(api_base, api_key, messages, model, api_mode='chat_completions', *, def _openai_stream(api_base, api_key, messages, model, api_mode='chat_completions', *,
temperature=0.5, max_tokens=None, tools=None, reasoning_effort=None, temperature=0.5, max_tokens=None, tools=None, reasoning_effort=None,
max_retries=0, connect_timeout=10, read_timeout=300, proxies=None, max_retries=0, connect_timeout=10, read_timeout=300, proxies=None, stream=True):
stream=True):
"""Shared OpenAI-compatible streaming request with retry. Yields text chunks, returns list[content_block].""" """Shared OpenAI-compatible streaming request with retry. Yields text chunks, returns list[content_block]."""
ml = model.lower() ml = model.lower()
if 'kimi' in ml or 'moonshot' in ml: temperature = 1 if 'kimi' in ml or 'moonshot' in ml: temperature = 1
@@ -912,19 +911,13 @@ class MixinSession:
THINKING_PROMPT_ZH = """ THINKING_PROMPT_ZH = """
### 行动规范(持续有效) ### 行动规范(持续有效)
每次回复请先在回复文字中包含 每次回复请先在回复文字中包含一个<summary></summary> 中输出极简单行(<30字物理快照上次结果新信息+本次意图。此内容进入长期工作记忆。
1. 在 <thinking></thinking> 标签中先分析现状和策略 \n**若用户需求未完成,必须进行工具调用!**
2. 在 <summary></summary> 中输出极简单行(<30字物理快照上次结果新信息+本次意图。此内容进入长期工作记忆。
再进行回答。
\n**除了最后回答,必须进行工具调用!**
""".strip() """.strip()
THINKING_PROMPT_EN = """ THINKING_PROMPT_EN = """
### Action Protocol (always in effect) ### Action Protocol (always in effect)
The reply body should first include: The reply body should first include a minimal one-line (<30 words) physical snapshot in <summary></summary>: new info from last result + current intent. This goes into long-term working memory.
1. Analyze the current situation and strategy inside <thinking></thinking> \n**If the user's request is not yet complete, tool calls are required!**
2. Output a minimal one-line (<30 words) physical snapshot in <summary></summary>: new info from last result + current intent. This goes into long-term working memory.
Then reply.
\n**Tool calls are required for every turn except the final answer!**
""".strip() """.strip()
class NativeToolClient: class NativeToolClient: