diff --git a/agent_loop.py b/agent_loop.py index 23af155..7eab55d 100644 --- a/agent_loop.py +++ b/agent_loop.py @@ -91,5 +91,5 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema, next_prompt += f"\n{datastr}\n\n\n" next_prompt += outcome.next_prompt next_prompt = handler.next_prompt_patcher(next_prompt, None, turn+1) - messages = [{"role": "user", "content": next_prompt}] + messages = [{"role": "user", "content": next_prompt}] # just new message, history is kept in *Session return {'result': 'MAX_TURNS_EXCEEDED'} diff --git a/assets/tools_schema.json b/assets/tools_schema.json index e628b0d..0dffa87 100644 --- a/assets/tools_schema.json +++ b/assets/tools_schema.json @@ -1,7 +1,7 @@ [ {"type": "function", "function": { "name": "code_run", - "description": "代码执行器。优先python,系统操作用powershell。禁同时调用多个。为免转义问题,代码放正文 ```python/powershell 块中。禁硬编码大量数据", + "description": "代码执行器。优先使用python。禁同时调用多个。为免转义问题,代码放正文 ```python/powershell 块中。禁硬编码大量数据", "parameters": {"type": "object", "properties": { "script": {"type": "string", "description": "[Optional] 要执行的代码。为免转义建议留空,改用正文代码块(与此参数互斥)"}, "type": {"type": "string", "enum": ["python", "powershell"], "description": "代码类型", "default": "python"}, diff --git a/llmcore.py b/llmcore.py index b280d74..3d81db5 100644 --- a/llmcore.py +++ b/llmcore.py @@ -814,26 +814,20 @@ class MixinSession: @property def primary(self): return self._sessions[0] def _raw_ask(self, *args, **kwargs): - last_err = None for attempt in range(self._retries + 1): gen = self._orig_raw_asks[attempt % len(self._sessions)](*args, **kwargs) - try: first = next(gen) - except StopIteration as e: return e.value or [] - if isinstance(first, str) and first.startswith('Error:'): - last_err = first - for _ in gen: pass # drain - if attempt < self._retries: - delay = min(30, self._base_delay * (2 ** attempt)) - print(f'[MixinSession] {first[:80]}, retry {attempt+1}/{self._retries} in {delay:.1f}s') - time.sleep(delay); continue - else: - yield first - try: - while True: yield next(gen) - except StopIteration as e: return e.value or [] - yield last_err or 'Error: all retries exhausted' - return [{'type': 'text', 'text': last_err}] - + last_chunk, return_val, yielded = None, [], False + try: + while True: + chunk = next(gen); last_chunk = chunk + if not yielded and isinstance(chunk, str) and chunk.startswith('Error:'): continue + yield chunk; yielded = True + except StopIteration as e: return_val = e.value or [] + if isinstance(last_chunk, str) and last_chunk.startswith('Error:') and attempt < self._retries: + delay = min(30, self._base_delay * (2 ** attempt)) + print(f'[MixinSession] {last_chunk[:80]}, retry {attempt+1}/{self._retries} in {delay:.1f}s') + time.sleep(delay); continue + return return_val class NativeToolClient: THINKING_PROMPT = """