[GH-ISSUE #340] gemini-cli-oauth和claude-kiro-oauth似乎没有完整兼容openai的协议 #241

Open
opened 2026-02-27 07:18:37 +03:00 by kerem · 3 comments
Owner

Originally created by @hb-0 on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/justlovemaki/AIClient-2-API/issues/340

在autogen、nanobot中会出错,如:
nanobot Sorry, I encountered an error: expected string or bytes-like object, got 'list'
但在opencode、cherry studio中可以使用

Originally created by @hb-0 on GitHub (Feb 26, 2026). Original GitHub issue: https://github.com/justlovemaki/AIClient-2-API/issues/340 在autogen、nanobot中会出错,如: ` nanobot Sorry, I encountered an error: expected string or bytes-like object, got 'list' ` 但在opencode、cherry studio中可以使用
Author
Owner

@justlovemaki commented on GitHub (Feb 26, 2026):

#128

<!-- gh-comment-id:3965568719 --> @justlovemaki commented on GitHub (Feb 26, 2026): #128
Author
Owner

@hb-0 commented on GitHub (Feb 26, 2026):

#128

环境信息 (Environment):
aiclient2api部署在arm架构linux上
使用api的机器为mac 苹果芯片

复现步骤 (Steps to Reproduce):
autogen中出错:
运行以下代码:

import asyncio
from pathlib import Path

from autogen_core.models import ModelInfo
from autogen_core.tools import FunctionTool

from autogen_ext.models.openai import OpenAIChatCompletionClient

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination


def make_model_client():
    return OpenAIChatCompletionClient(
        # model="kimi-k2.5",
        model="claude-4-6-sonnet",
        # model="gpt-5.3-codex",
        model_info=ModelInfo(
            vision=False,
            function_calling=True,      # 你要让它能调用 write_file,必须 True
            json_output=False,          # 兼容接口更稳
            structured_output=False,
            family="openai",
            max_tokens=8192,
        ),
    )


def write_file(path: str, content: str) -> str:
    """
    给 Agent 用的写文件工具。
    """
    p = Path(path)
    p.parent.mkdir(parents=True, exist_ok=True)
    p.write_text(content, encoding="utf-8")
    return f"WROTE {p.resolve()} ({len(content)} chars)"


async def main():
    model_client = make_model_client()

    write_file_tool = FunctionTool(
        write_file,
        name="write_file",
        description="Write a text file. Args: path(str), content(str).",
    )

    pm = AssistantAgent(
        name="PM",
        model_client=model_client,
        system_message=(
            "你是产品经理。把需求写成简短 PRD(输入/输出/边界/验收)。"
            "不要写文件。"
        ),
    )

    architect = AssistantAgent(
        name="Architect",
        model_client=model_client,
        system_message=(
            "你是架构师。给出实现方案(参数设计、排序规则、稳定性、内存/大文件策略)。"
            "不要写文件。"
        ),
    )

    coder = AssistantAgent(
        name="Coder",
        model_client=model_client,
        tools=[write_file_tool],  # ✅ 必须是 list[Tool]
        system_message=(
            "你是程序员。\n"
            "需要生成代码时,通过工具调用:write_file('文件名', <完整代码>)\n"
            "写完文件后,在聊天里简短说明如何运行,但不要把整段代码再打印一遍。"
        ),
    )

    tester = AssistantAgent(
        name="Tester",
        model_client=model_client,
        tools=[write_file_tool],
        system_message=(
             "你是测试工程师。你必须写 pytest 测试文件。\n"
            "最后一行输出:FINAL_DONE"
        ),
    )

    team = RoundRobinGroupChat(
        participants=[pm, architect, coder, tester],
        max_turns=12,
        termination_condition=TextMentionTermination("FINAL_DONE"),
        name="SortLinesTeam",
    )

    task = (
        "做一个命令行 Todo 应用(Python):支持 add/list/done/delete,"
        "本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。"
    )

    stream = team.run_stream(task=task)
    await Console(stream)

    print("\n✅ 期望生成文件:sort_lines.py, test_sort_lines.py")
    print("   检查:ls -la sort_lines.py test_sort_lines.py")


if __name__ == "__main__":
    asyncio.run(main())

环境变量:PYTHONUNBUFFERED=1;OPENAI_API_KEY=xxx;OPENAI_BASE_URL=http://xxx:3000/claude-kiro-oauth/v1

pyproject.toml:

[project]
name = "autogen"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.13"
dependencies = [
    "autogen-agentchat>=0.7.5",
    "autogen-ext>=0.7.5",
    "openai>=2.24.0",
    "pyautogen>=0.10.0",
    "tiktoken>=0.12.0",
]

[dependency-groups]
dev = [
    "pytest>=9.0.2",
]

现象描述 (Symptoms, not Guesses):
报错如下:

openai.AuthenticationError: Error code: 401 - {'error': {'code': 'authentication_error', 'message': 'Invalid Anthropic API Key', 'type': 'invalid_request_error', 'param': None}}

你做过的尝试:
本来在Opencode中使用也是不行的,但偶然间将api key留空,在header中添加Authorization: Bearer xxxx,突然就可以了。

PS:代码中如果是model="gpt-5.3-codex",就会报:

Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='content', input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list])
  return self.__pydantic_serializer__.to_python(
Error processing publish message for PM_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 67, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 485, in on_message_impl
    return await h(self, message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 268, in wrapper
    return_value = await func(self, message, ctx)  # type: ignore
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request
    async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
    ...<4 lines>...
            await self._log_message(msg)
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream
    async for inference_output in self._call_llm(
    ...<15 lines>...
            yield inference_output
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm
    model_result = await model_client.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create
    response = CreateResult(
        finish_reason=normalize_stop_reason(finish_reason),
    ...<4 lines>...
        thought=thought,
    )
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
Error processing publish message for Architect_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for Coder_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for Tester_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/test2.py", line 109, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/huangbin/workspace/autogen/test2.py", line 102, in main
    await Console(stream)
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/ui/_console.py", line 117, in Console
    async for message in stream:
    ...<81 lines>...
                    total_usage.prompt_tokens += message.models_usage.prompt_tokens
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat.py", line 554, in run_stream
    raise RuntimeError(str(message.error))
RuntimeError: ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
Traceback:
Traceback (most recent call last):

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request
    async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
    ...<4 lines>...
            await self._log_message(msg)

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream
    async for inference_output in self._call_llm(
    ...<15 lines>...
            yield inference_output

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm
    model_result = await model_client.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create
    response = CreateResult(
        finish_reason=normalize_stop_reason(finish_reason),
    ...<4 lines>...
        thought=thought,
    )

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)

pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
<!-- gh-comment-id:3965813775 --> @hb-0 commented on GitHub (Feb 26, 2026): > [#128](https://github.com/justlovemaki/AIClient-2-API/issues/128) 环境信息 (Environment): aiclient2api部署在arm架构linux上 使用api的机器为mac 苹果芯片 复现步骤 (Steps to Reproduce): autogen中出错: 运行以下代码: ``` import asyncio from pathlib import Path from autogen_core.models import ModelInfo from autogen_core.tools import FunctionTool from autogen_ext.models.openai import OpenAIChatCompletionClient from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.teams import RoundRobinGroupChat from autogen_agentchat.ui import Console from autogen_agentchat.conditions import TextMentionTermination def make_model_client(): return OpenAIChatCompletionClient( # model="kimi-k2.5", model="claude-4-6-sonnet", # model="gpt-5.3-codex", model_info=ModelInfo( vision=False, function_calling=True, # 你要让它能调用 write_file,必须 True json_output=False, # 兼容接口更稳 structured_output=False, family="openai", max_tokens=8192, ), ) def write_file(path: str, content: str) -> str: """ 给 Agent 用的写文件工具。 """ p = Path(path) p.parent.mkdir(parents=True, exist_ok=True) p.write_text(content, encoding="utf-8") return f"WROTE {p.resolve()} ({len(content)} chars)" async def main(): model_client = make_model_client() write_file_tool = FunctionTool( write_file, name="write_file", description="Write a text file. Args: path(str), content(str).", ) pm = AssistantAgent( name="PM", model_client=model_client, system_message=( "你是产品经理。把需求写成简短 PRD(输入/输出/边界/验收)。" "不要写文件。" ), ) architect = AssistantAgent( name="Architect", model_client=model_client, system_message=( "你是架构师。给出实现方案(参数设计、排序规则、稳定性、内存/大文件策略)。" "不要写文件。" ), ) coder = AssistantAgent( name="Coder", model_client=model_client, tools=[write_file_tool], # ✅ 必须是 list[Tool] system_message=( "你是程序员。\n" "需要生成代码时,通过工具调用:write_file('文件名', <完整代码>)\n" "写完文件后,在聊天里简短说明如何运行,但不要把整段代码再打印一遍。" ), ) tester = AssistantAgent( name="Tester", model_client=model_client, tools=[write_file_tool], system_message=( "你是测试工程师。你必须写 pytest 测试文件。\n" "最后一行输出:FINAL_DONE" ), ) team = RoundRobinGroupChat( participants=[pm, architect, coder, tester], max_turns=12, termination_condition=TextMentionTermination("FINAL_DONE"), name="SortLinesTeam", ) task = ( "做一个命令行 Todo 应用(Python):支持 add/list/done/delete," "本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。" ) stream = team.run_stream(task=task) await Console(stream) print("\n✅ 期望生成文件:sort_lines.py, test_sort_lines.py") print(" 检查:ls -la sort_lines.py test_sort_lines.py") if __name__ == "__main__": asyncio.run(main()) ``` 环境变量:PYTHONUNBUFFERED=1;OPENAI_API_KEY=xxx;OPENAI_BASE_URL=http://xxx:3000/claude-kiro-oauth/v1 pyproject.toml: ``` [project] name = "autogen" version = "0.1.0" description = "Add your description here" requires-python = ">=3.13" dependencies = [ "autogen-agentchat>=0.7.5", "autogen-ext>=0.7.5", "openai>=2.24.0", "pyautogen>=0.10.0", "tiktoken>=0.12.0", ] [dependency-groups] dev = [ "pytest>=9.0.2", ] ``` 现象描述 (Symptoms, not Guesses): 报错如下: ``` openai.AuthenticationError: Error code: 401 - {'error': {'code': 'authentication_error', 'message': 'Invalid Anthropic API Key', 'type': 'invalid_request_error', 'param': None}} ``` 你做过的尝试: 本来在Opencode中使用也是不行的,但偶然间将api key留空,在header中添加Authorization: Bearer xxxx,突然就可以了。 PS:代码中如果是model="gpt-5.3-codex",就会报: ``` Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings: PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='content', input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]) return self.__pydantic_serializer__.to_python( Error processing publish message for PM_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 67, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 485, in on_message_impl return await h(self, message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 268, in wrapper return_value = await func(self, message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token): ...<4 lines>... await self._log_message(msg) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream async for inference_output in self._call_llm( ...<15 lines>... yield inference_output File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm model_result = await model_client.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create response = CreateResult( finish_reason=normalize_stop_reason(finish_reason), ...<4 lines>... thought=thought, ) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing Error processing publish message for Architect_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Error processing publish message for Coder_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Error processing publish message for Tester_74ea525a-3777-4099-b0d2-76142d339a83/74ea525a-3777-4099-b0d2-76142d339a83 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/test2.py", line 109, in <module> asyncio.run(main()) ~~~~~~~~~~~^^^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 195, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/Users/huangbin/workspace/autogen/test2.py", line 102, in main await Console(stream) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/ui/_console.py", line 117, in Console async for message in stream: ...<81 lines>... total_usage.prompt_tokens += message.models_usage.prompt_tokens File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat.py", line 554, in run_stream raise RuntimeError(str(message.error)) RuntimeError: ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing Traceback: Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token): ...<4 lines>... await self._log_message(msg) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream async for inference_output in self._call_llm( ...<15 lines>... yield inference_output File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm model_result = await model_client.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create response = CreateResult( finish_reason=normalize_stop_reason(finish_reason), ...<4 lines>... thought=thought, ) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing ```
Author
Owner

@hb-0 commented on GitHub (Feb 27, 2026):

代码改为如下后:

import asyncio
import os
from pathlib import Path

from autogen_core.models import ModelInfo
from autogen_core.tools import FunctionTool

from autogen_ext.models.openai import OpenAIChatCompletionClient

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination


def make_model_client():
    api_key = os.getenv("OPENAI_API_KEY")
    base_url = os.getenv("OPENAI_BASE_URL")

    if not api_key:
        raise ValueError("OPENAI_API_KEY 环境变量未设置")
    if not base_url:
        raise ValueError("OPENAI_BASE_URL 环境变量未设置")

    return OpenAIChatCompletionClient(
        model="claude-4-6-sonnet",
        api_key=api_key,
        base_url=base_url,
        model_info=ModelInfo(
            vision=False,
            function_calling=True,
            json_output=False,
            structured_output=False,
            family="openai",
            max_tokens=8192,
        ),
    )


def write_file(path: str, content: str) -> str:
    """
    给 Agent 用的写文件工具。
    """
    p = Path(path)
    p.parent.mkdir(parents=True, exist_ok=True)
    p.write_text(content, encoding="utf-8")
    return f"WROTE {p.resolve()} ({len(content)} chars)"


async def main():
    model_client = make_model_client()

    write_file_tool = FunctionTool(
        write_file,
        name="write_file",
        description="Write a text file. Args: path(str), content(str).",
    )

    pm = AssistantAgent(
        name="PM",
        model_client=model_client,
        system_message=(
            "你是产品经理。把需求写成简短 PRD(输入/输出/边界/验收)。不要写文件。"
        ),
    )

    architect = AssistantAgent(
        name="Architect",
        model_client=model_client,
        system_message=(
            "你是架构师。给出实现方案(参数设计、排序规则、稳定性、内存/大文件策略)。"
            "不要写文件。"
        ),
    )

    coder = AssistantAgent(
        name="Coder",
        model_client=model_client,
        tools=[write_file_tool],  # ✅ 必须是 list[Tool]
        system_message=(
            "你是程序员。\n"
            "需要生成代码时,通过工具调用:write_file('文件名', <完整代码>)\n"
            "写完文件后,在聊天里简短说明如何运行,但不要把整段代码再打印一遍。"
        ),
    )

    tester = AssistantAgent(
        name="Tester",
        model_client=model_client,
        tools=[write_file_tool],
        system_message=(
            "你是测试工程师。你必须写 pytest 测试文件。\n最后一行输出:FINAL_DONE"
        ),
    )

    team = RoundRobinGroupChat(
        participants=[pm, architect, coder, tester],
        max_turns=12,
        termination_condition=TextMentionTermination("FINAL_DONE"),
        name="SortLinesTeam",
    )

    task = (
        "做一个命令行 Todo 应用(Python):支持 add/list/done/delete,"
        "本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。"
    )

    stream = team.run_stream(task=task)
    await Console(stream)

    print("\n✅ 期望生成文件:sort_lines.py, test_sort_lines.py")
    print("   检查:ls -la sort_lines.py test_sort_lines.py")


if __name__ == "__main__":
    asyncio.run(main())

不报authentication_error了,但报:

/Users/huangbin/.local/bin/uv run /Users/huangbin/workspace/autogen/.venv/bin/python /Users/huangbin/workspace/autogen/test2.py 
---------- TextMessage (user) ----------
做一个命令行 Todo 应用(Python):支持 add/list/done/delete,本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。
/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='content', input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list])
  return self.__pydantic_serializer__.to_python(
Error processing publish message for PM_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 67, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 485, in on_message_impl
    return await h(self, message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 268, in wrapper
    return_value = await func(self, message, ctx)  # type: ignore
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request
    async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
    ...<4 lines>...
            await self._log_message(msg)
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream
    async for inference_output in self._call_llm(
    ...<15 lines>...
            yield inference_output
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm
    model_result = await model_client.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create
    response = CreateResult(
        finish_reason=normalize_stop_reason(finish_reason),
    ...<4 lines>...
        thought=thought,
    )
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
Error processing publish message for Architect_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for Coder_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for Tester_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl
    return await self.on_unhandled_message(message, ctx)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message
    raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Traceback (most recent call last):
  File "/Users/huangbin/workspace/autogen/test2.py", line 116, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/huangbin/workspace/autogen/test2.py", line 109, in main
    await Console(stream)
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/ui/_console.py", line 117, in Console
    async for message in stream:
    ...<81 lines>...
                    total_usage.prompt_tokens += message.models_usage.prompt_tokens
  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat.py", line 554, in run_stream
    raise RuntimeError(str(message.error))
RuntimeError: ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
Traceback:
Traceback (most recent call last):

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request
    async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
    ...<4 lines>...
            await self._log_message(msg)

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream
    async for inference_output in self._call_llm(
    ...<15 lines>...
            yield inference_output

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm
    model_result = await model_client.create(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create
    response = CreateResult(
        finish_reason=normalize_stop_reason(finish_reason),
    ...<4 lines>...
        thought=thought,
    )

  File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)

pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult
content.str
  Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.12/v/string_type
content.list[FunctionCall].0.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].0.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.id
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.arguments
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
content.list[FunctionCall].1.name
  Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing


<!-- gh-comment-id:3970138864 --> @hb-0 commented on GitHub (Feb 27, 2026): 代码改为如下后: ``` import asyncio import os from pathlib import Path from autogen_core.models import ModelInfo from autogen_core.tools import FunctionTool from autogen_ext.models.openai import OpenAIChatCompletionClient from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.teams import RoundRobinGroupChat from autogen_agentchat.ui import Console from autogen_agentchat.conditions import TextMentionTermination def make_model_client(): api_key = os.getenv("OPENAI_API_KEY") base_url = os.getenv("OPENAI_BASE_URL") if not api_key: raise ValueError("OPENAI_API_KEY 环境变量未设置") if not base_url: raise ValueError("OPENAI_BASE_URL 环境变量未设置") return OpenAIChatCompletionClient( model="claude-4-6-sonnet", api_key=api_key, base_url=base_url, model_info=ModelInfo( vision=False, function_calling=True, json_output=False, structured_output=False, family="openai", max_tokens=8192, ), ) def write_file(path: str, content: str) -> str: """ 给 Agent 用的写文件工具。 """ p = Path(path) p.parent.mkdir(parents=True, exist_ok=True) p.write_text(content, encoding="utf-8") return f"WROTE {p.resolve()} ({len(content)} chars)" async def main(): model_client = make_model_client() write_file_tool = FunctionTool( write_file, name="write_file", description="Write a text file. Args: path(str), content(str).", ) pm = AssistantAgent( name="PM", model_client=model_client, system_message=( "你是产品经理。把需求写成简短 PRD(输入/输出/边界/验收)。不要写文件。" ), ) architect = AssistantAgent( name="Architect", model_client=model_client, system_message=( "你是架构师。给出实现方案(参数设计、排序规则、稳定性、内存/大文件策略)。" "不要写文件。" ), ) coder = AssistantAgent( name="Coder", model_client=model_client, tools=[write_file_tool], # ✅ 必须是 list[Tool] system_message=( "你是程序员。\n" "需要生成代码时,通过工具调用:write_file('文件名', <完整代码>)\n" "写完文件后,在聊天里简短说明如何运行,但不要把整段代码再打印一遍。" ), ) tester = AssistantAgent( name="Tester", model_client=model_client, tools=[write_file_tool], system_message=( "你是测试工程师。你必须写 pytest 测试文件。\n最后一行输出:FINAL_DONE" ), ) team = RoundRobinGroupChat( participants=[pm, architect, coder, tester], max_turns=12, termination_condition=TextMentionTermination("FINAL_DONE"), name="SortLinesTeam", ) task = ( "做一个命令行 Todo 应用(Python):支持 add/list/done/delete," "本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。" ) stream = team.run_stream(task=task) await Console(stream) print("\n✅ 期望生成文件:sort_lines.py, test_sort_lines.py") print(" 检查:ls -la sort_lines.py test_sort_lines.py") if __name__ == "__main__": asyncio.run(main()) ``` 不报authentication_error了,但报: ``` /Users/huangbin/.local/bin/uv run /Users/huangbin/workspace/autogen/.venv/bin/python /Users/huangbin/workspace/autogen/test2.py ---------- TextMessage (user) ---------- 做一个命令行 Todo 应用(Python):支持 add/list/done/delete,本地 JSON 文件持久化(默认 todos.json),要求基本错误处理和单元测试。 /Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py:464: UserWarning: Pydantic serializer warnings: PydanticSerializationUnexpectedValue(Expected `str` - serialized value may not be as expected [field_name='content', input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list]) return self.__pydantic_serializer__.to_python( Error processing publish message for PM_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 67, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 485, in on_message_impl return await h(self, message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 268, in wrapper return_value = await func(self, message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token): ...<4 lines>... await self._log_message(msg) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream async for inference_output in self._call_llm( ...<15 lines>... yield inference_output File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm model_result = await model_client.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create response = CreateResult( finish_reason=normalize_stop_reason(finish_reason), ...<4 lines>... thought=thought, ) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing Error processing publish message for Architect_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Error processing publish message for Coder_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Error processing publish message for Tester_a92400b2-a200-4c0b-b135-795aeb08a585/a92400b2-a200-4c0b-b135-795aeb08a585 Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 606, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_base_agent.py", line 119, in on_message return await self.on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 72, in on_message_impl return await super().on_message_impl(message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_core/_routed_agent.py", line 486, in on_message_impl return await self.on_unhandled_message(message, ctx) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 195, in on_unhandled_message raise ValueError(f"Unhandled message in agent container: {type(message)}") ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'> Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/test2.py", line 116, in <module> asyncio.run(main()) ~~~~~~~~~~~^^^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 195, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/Users/huangbin/.local/share/uv/python/cpython-3.13.10-macos-aarch64-none/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/Users/huangbin/workspace/autogen/test2.py", line 109, in main await Console(stream) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/ui/_console.py", line 117, in Console async for message in stream: ...<81 lines>... total_usage.prompt_tokens += message.models_usage.prompt_tokens File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat.py", line 554, in run_stream raise RuntimeError(str(message.error)) RuntimeError: ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing Traceback: Traceback (most recent call last): File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/teams/_group_chat/_chat_agent_container.py", line 133, in handle_request async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token): ...<4 lines>... await self._log_message(msg) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 953, in on_messages_stream async for inference_output in self._call_llm( ...<15 lines>... yield inference_output File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 1109, in _call_llm model_result = await model_client.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) ^ File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/autogen_ext/models/openai/_openai_client.py", line 801, in create response = CreateResult( finish_reason=normalize_stop_reason(finish_reason), ...<4 lines>... thought=thought, ) File "/Users/huangbin/workspace/autogen/.venv/lib/python3.13/site-packages/pydantic/main.py", line 250, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 7 validation errors for CreateResult content.str Input should be a valid string [type=string_type, input_value=[{'type': 'text', 'text':...场景有明确提示'}], input_type=list] For further information visit https://errors.pydantic.dev/2.12/v/string_type content.list[FunctionCall].0.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].0.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.id Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.arguments Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing content.list[FunctionCall].1.name Field required [type=missing, input_value={'type': 'text', 'text': ...场景有明确提示'}, input_type=dict] For further information visit https://errors.pydantic.dev/2.12/v/missing ```
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AIClient-2-API-justlovemaki#241
No description provided.