fix: print编码防崩 + 未知工具时自动重注入tool schema
This commit is contained in:
@@ -78,6 +78,7 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
|
||||
|
||||
if outcome.next_prompt is None: return {'result': 'CURRENT_TASK_DONE', 'data': outcome.data}
|
||||
if outcome.should_exit: return {'result': 'EXITED', 'data': outcome.data}
|
||||
if outcome.next_prompt.startswith('未知工具'): client.last_tools = ''
|
||||
|
||||
next_prompt = ""
|
||||
if outcome.data is not None:
|
||||
|
||||
6
ga.py
6
ga.py
@@ -40,7 +40,8 @@ def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop
|
||||
try: line = line_bytes.decode('utf-8')
|
||||
except UnicodeDecodeError: line = line_bytes.decode('gbk', errors='ignore')
|
||||
logs.append(line)
|
||||
print(line, end="")
|
||||
try: print(line, end="")
|
||||
except: pass
|
||||
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
@@ -310,7 +311,8 @@ class GenericAgentHandler(BaseHandler):
|
||||
result["js_return"] += f"\n\n[已保存完整内容到 {abs_path}]"
|
||||
except:
|
||||
result['js_return'] += f"\n\n[保存失败,无法写入文件 {abs_path}]"
|
||||
print("Web Execute JS Result:", smart_format(result))
|
||||
try: print("Web Execute JS Result:", smart_format(result))
|
||||
except: pass
|
||||
yield f"JS 执行结果:\n{smart_format(result)}\n"
|
||||
next_prompt = self._get_anchor_prompt()
|
||||
return StepOutcome(smart_format(result, max_str_len=5000), next_prompt=next_prompt)
|
||||
|
||||
@@ -328,6 +328,7 @@ class ToolClient:
|
||||
except json.JSONDecodeError as e:
|
||||
print("[Warn] Failed to parse tool_use JSON:", json_str)
|
||||
tool_calls = [MockToolCall('bad_json', {'msg': f'Failed to parse tool_use JSON: {json_str[:200]}'})]
|
||||
self.last_tools = '' # llm肯定忘了tool schema了,再提供下
|
||||
except Exception as e:
|
||||
print("[Error] Exception during tool_use parsing:", str(e), data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user