From 6091bf0c6f212daba39fa374eb1178498c332132 Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Thu, 23 Apr 2026 17:21:05 +0800 Subject: [PATCH] fix: add requests to pip install & tune max_turns/prompt --- README.md | 4 ++-- agentmain.py | 2 +- ga.py | 6 +++--- llmcore.py | 17 +++++------------ 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 28f1882..d9e5149 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ git clone https://github.com/lsdefine/GenericAgent.git cd GenericAgent # 2. Install minimal dependencies -pip install streamlit pywebview +pip install requests streamlit pywebview # 3. Configure API Key cp mykey_template.py mykey.py @@ -283,7 +283,7 @@ git clone https://github.com/lsdefine/GenericAgent.git cd GenericAgent # 2. 安装最小依赖 -pip install streamlit pywebview +pip install requests streamlit pywebview # 3. 配置 API Key cp mykey_template.py mykey.py diff --git a/agentmain.py b/agentmain.py index 5c6052b..cd8b5f6 100644 --- a/agentmain.py +++ b/agentmain.py @@ -141,7 +141,7 @@ class GeneraticAgent: 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! 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: full_resp = ""; last_pos = 0 for chunk in gen: diff --git a/ga.py b/ga.py index 6f66edb..0aa87a0 100644 --- a/ga.py +++ b/ga.py @@ -417,7 +417,7 @@ class GenericAgentHandler(BaseHandler): 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 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 def _check_plan_completion(self): 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 = smart_format(summary, max_str_len=100) 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,不允许继续重试。" elif turn % 7 == 0: 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: 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') injprompt = consume_file(self.parent.task_dir, '_intervene') diff --git a/llmcore.py b/llmcore.py index 0c988e1..e770a40 100644 --- a/llmcore.py +++ b/llmcore.py @@ -315,8 +315,7 @@ def _stamp_oai_cache_markers(messages, model): def _openai_stream(api_base, api_key, messages, model, api_mode='chat_completions', *, temperature=0.5, max_tokens=None, tools=None, reasoning_effort=None, - max_retries=0, connect_timeout=10, read_timeout=300, proxies=None, - stream=True): + max_retries=0, connect_timeout=10, read_timeout=300, proxies=None, stream=True): """Shared OpenAI-compatible streaming request with retry. Yields text chunks, returns list[content_block].""" ml = model.lower() if 'kimi' in ml or 'moonshot' in ml: temperature = 1 @@ -912,19 +911,13 @@ class MixinSession: THINKING_PROMPT_ZH = """ ### 行动规范(持续有效) -每次回复请先在回复文字中包含: -1. 在 标签中先分析现状和策略 -2. 在 中输出极简单行(<30字)物理快照:上次结果新信息+本次意图。此内容进入长期工作记忆。 -再进行回答。 -\n**除了最后回答,必须进行工具调用!** +每次回复请先在回复文字中包含一个 中输出极简单行(<30字)物理快照:上次结果新信息+本次意图。此内容进入长期工作记忆。 +\n**若用户需求未完成,必须进行工具调用!** """.strip() THINKING_PROMPT_EN = """ ### Action Protocol (always in effect) -The reply body should first include: -1. Analyze the current situation and strategy inside -2. Output a minimal one-line (<30 words) physical snapshot in : 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!** +The reply body should first include a minimal one-line (<30 words) physical snapshot in : new info from last result + current intent. This goes into long-term working memory. +\n**If the user's request is not yet complete, tool calls are required!** """.strip() class NativeToolClient: