{"record":{"id":"9a2abdb75c0eb749","repo":"datawhalechina/hello-agents","slug":"error-9a2abd","errorCode":null,"errorMessage":"已达到四次模型调用上限","messagePattern":"已达到四次模型调用上限","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/Henry2513-MeetingActionAgent/main.ipynb","lineNumber":302,"sourceCode":"   \"id\": \"d3d42947\",\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class CallBudget:\\n\",\n    \"    # 初始化模型调用次数上限。\\n\",\n    \"    def __init__(self, maximum: int = 4) -> None:\\n\",\n    \"        self.maximum = maximum\\n\",\n    \"        self.used = 0\\n\",\n    \"\\n\",\n    \"    # 计算剩余的模型调用次数。\\n\",\n    \"    @property\\n\",\n    \"    def remaining(self) -> int:\\n\",\n    \"        return self.maximum - self.used\\n\",\n    \"\\n\",\n    \"    # 在次数限制内执行一次 Agent 调用。\\n\",\n    \"    def run(self, agent, prompt: str) -> str:\\n\",\n    \"        if self.remaining <= 0:\\n\",\n    \"            raise RuntimeError(\\\"已达到四次模型调用上限\\\")\\n\",\n    \"        self.used += 1\\n\",\n    \"        return agent.run(prompt)\\n\",\n    \"\\n\",\n    \"\\n\",\n    \"# 调用 Agent 并将响应解析为指定的数据模型。\\n\",\n    \"def run_structured(\\n\",\n    \"    agent,\\n\",\n    \"    prompt: str,\\n\",\n    \"    model_type: type[BaseModel],\\n\",\n    \"    budget: CallBudget,\\n\",\n    \") -> BaseModel:\\n\",\n    \"    schema = json.dumps(model_type.model_json_schema(), ensure_ascii=False)\\n\",\n    \"    full_prompt = f\\\"{prompt}\\\\n\\\\n必须遵循以下 JSON Schema：\\\\n{schema}\\\"\\n\",\n    \"    raw_response = budget.run(agent, full_prompt)\\n\",\n    \"    try:\\n\",\n    \"        return parse_model_response(raw_response, model_type)\\n\",\n    \"    except ValueError as error:\\n\",\n    \"        if budget.remaining <= 0:\\n\",","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Henry2513-MeetingActionAgent/main.ipynb#L284-L320","documentation":"A RuntimeError raised by CallBudget.run when the agent has already consumed its maximum (default 4) LLM calls. The budget object exists to hard-cap model invocations in the notebook pipeline (draft → review → repair loop), so exceeding it is by design a stop, not a crash: remaining = maximum - used, and any run() with remaining <= 0 raises before invoking the agent.","triggerScenarios":"More than 4 budget.run(...) calls in one pipeline execution: e.g. minutes drafting consumes calls, the review agent consumes more, and JSON-repair retries consume the rest — the 5th call raises. Composing multiple run_structured steps against one shared CallBudget is the classic way to exhaust it.","commonSituations":"Frequent JSON validation failures forcing repeated repair prompts (each costs one call); low-quality model output causing a repair loop; adding a new agent stage to the pipeline without raising the budget; shared budget across minutes + review agents in a refactor.","solutions":["Inspect where calls go: every budget.run invocation (initial drafts, reviews, repairs) counts against the same maximum — reduce repair-triggering failures by strengthening the prompt's JSON instruction (include the schema, demand raw JSON only).","Raise the cap if the pipeline legitimately needs more stages: CallBudget(maximum=6).","Give each pipeline stage its own CallBudget instead of sharing one, so one stage's repairs cannot starve another.","Switch to a model/provider JSON mode to cut repair calls to near zero."],"exampleFix":"# before\nbudget = CallBudget()  # maximum=4, exhausted by repairs\n\n# after\nbudget = CallBudget(maximum=6)\nminutes_budget = CallBudget(maximum=4)\nreview_budget = CallBudget(maximum=2)","handlingStrategy":"validation","validationCode":"if budget.remaining <= 0:\n    raise RuntimeError(\"no LLM calls left; raise CallBudget.maximum or add a stage budget\")","typeGuard":"def can_run(budget: \"CallBudget\") -> bool:\n    return budget.remaining > 0","tryCatchPattern":"try:\n    out = budget.run(agent, prompt)\nexcept RuntimeError as e:\n    if \"上限\" in str(e):\n        budget.maximum += 2  # or re-plan pipeline\n        out = budget.run(agent, prompt)\n    else: raise","preventionTips":["Size CallBudget.maximum to pipeline stages plus repair headroom (e.g. stages + 2).","Use one budget per agent stage so repairs cannot starve other stages.","Reduce repair-consuming failures: schema-in-prompt, JSON mode, adequate max_tokens."],"tags":["budget","llm","runtimeerror","pipeline"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}