datawhalechina/hello-agents · error · HelloAgentsException

流式工具调用失败: {str(e)}

Error message

流式工具调用失败: {str(e)}

What it means

In enhanced_llm.py, the streaming tool-call loop wraps its entire body in try/except Exception and re-raises as HelloAgentsException('流式工具调用失败: ...'). The original exception text is preserved in the message, so the real cause is whatever the streaming SDK call raised: provider auth errors, rate limits, malformed tool-call deltas, network resets, or bugs in delta-handling code. Because the except swallows the type, callers cannot narrow on the original exception class.

Source

Thrown at Co-creation-projects/tino-chen-HelloClaw/src/agent/enhanced_llm.py:236

                        if tc_delta.function and tc_delta.function.arguments:
                            args_delta = tc_delta.function.arguments
                            result.add_tool_call_delta(idx, args_delta)
                            yield StreamToolEvent(
                                event_type=StreamToolEventType.TOOL_CALL_DELTA,
                                tool_call_index=idx,
                                tool_arguments_delta=args_delta
                            )

                # 处理结束原因
                if choice.finish_reason:
                    result.finish_reason = choice.finish_reason
                    yield StreamToolEvent(
                        event_type=StreamToolEventType.FINISH,
                        finish_reason=choice.finish_reason
                    )

        except Exception as e:
            raise HelloAgentsException(f"流式工具调用失败: {str(e)}")

        # 保存累积结果供后续使用
        self._last_stream_tool_result = result

    def get_last_stream_tool_result(self) -> Optional[StreamToolCallResult]:
        """
        获取最后一次流式工具调用的累积结果

        Returns:
            StreamToolCallResult 或 None
        """
        return self._last_stream_tool_result

View on GitHub (pinned to 606a07d341)

Solutions

  1. Read the wrapped text — it contains the provider/SDK error verbatim; fix that first (key, quota, model name, base_url).
  2. Retry with exponential backoff for transient 429/5xx/network-reset causes; make the retry re-open the stream, not resume it.
  3. Pin compatible SDK versions (openai/hello-agents) if the message shows AttributeError/KeyError on chunk fields.
  4. Increase the client read timeout for long tool-call generations.
  5. Change the wrapper to `raise HelloAgentsException(...) from e` so the traceback retains the original exception for diagnosis.

Example fix

# before
except Exception as e:
    raise HelloAgentsException(f"流式工具调用失败: {str(e)}")
# after
except Exception as e:
    raise HelloAgentsException(f"流式工具调用失败: {str(e)}") from e  # keeps original traceback
Defensive patterns

Strategy: retry

Validate before calling

import os
required = ["LLM_API_KEY"]  # adjust to this deployment's env names
missing = [k for k in required if not os.getenv(k)]
if missing:
    raise SystemExit(f"missing env: {missing}")

Try / catch

from hello_agents import HelloAgentsException
import time

for attempt in range(3):
    try:
        result = consume_stream(llm.stream_tool_call(...))
        break
    except HelloAgentsException as e:
        msg = str(e)
        if any(t in msg for t in ("429", "rate", "timeout", "reset")) and attempt < 2:
            time.sleep(2 ** attempt)  # transient — back off and re-open the stream
            continue
        raise  # auth/validation errors are not retryable

Prevention

When it happens

Trigger: Invalid/expired API key when the stream request is opened; HTTP 429/5xx from the provider mid-stream; tool_calls deltas arriving in an order the accumulation logic does not expect (index/id None); connection reset or read timeout while yielding chunks; an SDK version change in the stream chunk schema causing AttributeError inside the loop.

Common situations: Long streaming sessions hitting provider timeouts; switching LLM providers/base_url without updating SDK assumptions; concurrent streams exceeding rate limits; hello-agents/OpenAI SDK version mismatch after upgrade.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/c69be86f2fe1dfe1. Report an issue: GitHub.