Skip to content

当llm调用工具时把function.name设置成None会崩溃 #8546

@bytecategory

Description

@bytecategory
[2026-06-03 04:47:02.677] [Core][INFO][runners.tool_loop_agent_runner:1042]: 使用工具:None,参数:{'code': '\nimport re, json\n\nwith open(\'/root/3.txt\', \'r\', encoding=\'utf-8\') as f:\n    text = f.read()\n\n# split by blank lines (one or more)\nchunks = re.split(r\'\\n\\s*\\n\', text.strip())\nprint("chunk count:", len(chunks))\n\nurl_re = re.compile(r\'^https://x\\.com/bytecategory/status/(\\d+)\\s*$\')\n\nposts = []\nleftover = []\nfor chunk in chunks:\n    lines = chunk.split(\'\\n\')\n    # find the LAST url line in chunk\n    url_idx = None\n    for i in range(len(lines)-1, -1, -1):\n        if url_re.match(lines[i].strip()):\n            url_idx = i\n            break\n    if url_idx is None:\n        leftover.append(chunk[:120])\n        continue\n    url = lines[url_idx].strip()\n    status_id = url_re.match(url).group(1)\n    content_lines = lines[:url_idx]\n    # strip trailing/leading empties\n    while content_lines and content_lines[0].strip() == \'\':\n        content_lines.pop(0)\n    while content_lines and content_lines[-1].strip() == \'\':\n        content_lines.pop()\n    content = \'\\n\'.join(content_lines)\n    posts.append({\'id\': status_id, \'url\': url, \'content\': content})\n\nprint("post count:", len(posts))\nprint("leftover chunks:", len(leftover))\nfor l in leftover[:5]:\n    print("--", repr(l[:200]))\n\n# show first 3 and last 3\nfor p in posts[:3]:\n    print("---")\n    print(p[\'id\'])\n    print(p[\'content\'][:200])\nprint("=====")\nfor p in posts[-3:]:\n    print("---")\n    print(p[\'id\'])\n    print(p[\'content\'][:200])\n\nwith open(\'/tmp/posts.json\', \'w\', encoding=\'utf-8\') as f:\n    json.dump(posts, f, ensure_ascii=False, indent=2)\nprint("written:", len(posts))\n'}

[2026-06-03 04:47:02.678] [Core][WARN][v4.25.2] [runners.tool_loop_agent_runner:1045]: 未找到指定的工具: None,将跳过。

[2026-06-03 04:47:02.684] [Core][ERRO][v4.25.2] [core.astr_agent_run_util:310]: Traceback (most recent call last):
  File "/root/AstrBot/astrbot/core/astr_agent_run_util.py", line 156, in run_agent
    async for resp in agent_runner.step():
  File "/root/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 904, in step
    tool_calls=llm_resp.to_openai_to_calls_model(),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/AstrBot/astrbot/core/provider/entities.py", line 477, in to_openai_to_calls_model
    function=ToolCall.FunctionBody(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 263, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for FunctionBody
name
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.13/v/string_type

然后她就忘记了我问了什么 回答道
The workspace is empty, so I don’t have the source file from the previous attempt. Could you share:

The file containing the posts (you can upload it, or tell me where it lives on the system)

Any specific requirements for the Next.js app (styling preferences, routing structure, etc.)

Once I have the source file, I’ll parse it fully first to map out all posts and their structure, then scaffold the Next.js app around that data.
必须得在 astrbot/core/provider/entities.py 里加上

if not self.tools_call_name[idx]:
   continue

这两行,continue得换成错误提示信息. 就这样吧 损失了20几元.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.priority: p0

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions