Skip to content

fix: 兼容openai适配器的非标返回#6450

Closed
a61995987 wants to merge 3 commits intoAstrBotDevs:devfrom
a61995987:fix-兼容openai适配器的非标返回

Hidden character warning

The head ref may contain hidden characters: "fix-\u517c\u5bb9openai\u9002\u914d\u5668\u7684\u975e\u6807\u8fd4\u56de"
Closed

fix: 兼容openai适配器的非标返回#6450
a61995987 wants to merge 3 commits intoAstrBotDevs:devfrom
a61995987:fix-兼容openai适配器的非标返回

Conversation

@a61995987
Copy link
Copy Markdown
Contributor

@a61995987 a61995987 commented Mar 16, 2026

fix:兼容openai适配器的非标返回
PR(#5610)的分散提交

Modifications / 改动点

fix:兼容openai适配器的非标返回:
修改文件:astrbot\core\provider\sources\openai_source.py

在_query_stream方法中的async for chunk in stream循环中增加了兼容非标准返回处理的处理 补全可能缺失的补全tool_call.type字段

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Mar 16, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @a61995987, your pull request is larger than the review limit of 150000 diff characters

@a61995987 a61995987 changed the base branch from master to dev March 16, 2026 14:59
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Mar 16, 2026
@a61995987
Copy link
Copy Markdown
Contributor Author

不好意思 刚刚提交错分支了 现已修改

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the internal architecture for managing computer-use tools, making the system more modular and robust. It also addresses a critical compatibility issue with non-standard OpenAI adapter responses, ensuring smoother operation with various LLM providers. Furthermore, the dashboard receives several quality-of-life improvements, enhancing user experience for configuration, persona management, and API key handling.

Highlights

  • Computer-Use Tool Refactoring: Decoupled computer-use tool injection logic from the main agent, introducing a new ToolProvider protocol and ComputerToolProvider to manage local and sandbox tools. This improves modularity and consistency in tool registration and system prompt injection.
  • OpenAI Adapter Compatibility Fix: Implemented a compatibility fix for non-standard OpenAI adapter returns, specifically addressing missing tool_call.type fields in streaming responses from certain aggregation platforms.
  • Dashboard WebUI Enhancements: Improved the dashboard's WebUI deployment and configuration, including a new API store for managing backend URLs and presets, enhanced port checking, and refined URL display for various network configurations.
  • Persona Management Features: Added a new feature to the dashboard allowing users to clone existing personas, improving flexibility and ease of setup for new agent configurations.
  • API Key Management Improvements: Enhanced API key management in the dashboard with updated expiry options, clearer scope descriptions, and improved handling of API key creation and revocation.
  • Streaming Response Logic for Media: Introduced logic to disable streaming responses for webchat when models are expected to output image modalities, ensuring proper handling of non-streamable media content.
Changelog
  • .envrc
    • Added git pull and git status commands.
  • .gitignore
    • Added .serena to ignored files.
  • .python-version
    • Ensured newline at end of file for Python version specification.
  • README.md
    • Updated language links, project description, key features, deployment methods, supported platforms, and contribution guidelines.
  • README_fr.md
    • Updated language links, project description, key features, deployment methods, supported platforms, and contribution guidelines.
  • README_ja.md
    • Updated language links, project description, key features, deployment methods, supported platforms, and contribution guidelines.
  • README_ru.md
    • Updated language links, project description, key features, deployment methods, supported platforms, and contribution guidelines.
  • README_zh-TW.md
    • Updated language links, project description, key features, deployment methods, supported platforms, and contribution guidelines.
  • README_zh.md
    • Updated deployment instructions and contribution guidelines.
  • astrbot/cli/init.py
    • Updated version retrieval to use importlib.metadata for better package management.
  • astrbot/cli/commands/cmd_init.py
    • Modified dashboard installation logic to prompt user for WebUI integration and extract to the data subdirectory.
  • astrbot/cli/commands/cmd_run.py
    • Added --backend-only option and host/port environment variables for dashboard control.
  • astrbot/cli/utils/basic.py
    • Adjusted dashboard download path to astrbot_root / 'data' and added error handling for dashboard installation.
  • astrbot/core/agent/mcp_client.py
    • Added a source attribute to MCPTool to indicate its origin.
  • astrbot/core/agent/runners/tool_loop_agent_runner.py
    • Improved handling of image content from tool calls by caching and providing LLM visibility, and iterated through all content items in tool results.
  • astrbot/core/agent/tool.py
    • Added a source attribute to FunctionTool and a normalize method to ToolSet for deterministic serialization.
  • astrbot/core/astr_agent_run_util.py
    • Added _extract_final_streaming_chain to process message chains and modified run_agent to yield final media chains in streaming mode.
  • astrbot/core/astr_agent_tool_exec.py
    • Refactored computer-use tool management to use ComputerToolProvider and added sandbox capability checks for browser tools.
  • astrbot/core/astr_main_agent.py
    • Decoupled computer-use tool injection, moved prompts to a dedicated module, and added logic to disable streaming for webchat image output.
  • astrbot/core/computer/booters/base.py
    • Introduced abstract methods for get_default_tools, get_default_prompts, get_tools, and get_system_prompt_parts.
  • astrbot/core/computer/booters/boxlite.py
    • Implemented tool and prompt methods for Boxlite booter and improved logging for file operations and health checks.
  • astrbot/core/computer/booters/constants.py
    • Added new file defining constants for booter types.
  • astrbot/core/computer/booters/shipyard.py
    • Implemented tool and prompt methods for Shipyard booter and improved logging for sandbox creation and file operations.
  • astrbot/core/computer/booters/shipyard_neo.py
    • Implemented tool and prompt methods for Shipyard Neo booter, including browser tools and Neo lifecycle prompts, and improved logging.
  • astrbot/core/computer/computer_client.py
    • Refactored to expose unified tool query API, moved Bay credentials discovery, and improved logging for sandbox operations.
  • astrbot/core/computer/computer_tool_provider.py
    • Added new file for ComputerToolProvider to manage computer-use tools based on session context.
  • astrbot/core/computer/prompts.py
    • Added new file for computer-specific system prompt constants.
  • astrbot/core/computer/tools/shell.py
    • Added tool call timeout to shell execution.
  • astrbot/core/config/default.py
    • Updated version and __version__ retrieval to use importlib.metadata.
  • astrbot/core/cron/cron_tool_provider.py
    • Added new file for CronToolProvider to manage cron job tools.
  • astrbot/core/cron/manager.py
    • Updated prompt constants and integrated ComputerToolProvider into MainAgentBuildConfig.
  • astrbot/core/persona_mgr.py
    • Added clone_persona method to duplicate existing personas.
  • astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py
    • Integrated the new ToolProvider system and adjusted streaming logic based on effective streaming response.
  • astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py
    • Modified file sending logic to use OneBot V11 file API for better compatibility.
  • astrbot/core/provider/func_tool_manager.py
    • Added register_internal_tools method to register built-in tools from various providers.
  • astrbot/core/provider/sources/gemini_source.py
    • Modified _prepare_query_config to downgrade image modalities to text for streaming requests.
  • astrbot/core/provider/sources/openai_source.py
    • Added compatibility for missing tool_call.type fields in streaming responses from OpenAI-compatible adapters.
  • astrbot/core/star/context.py
    • Called register_internal_tools during initialization to ensure built-in tools are available.
  • astrbot/core/tool_provider.py
    • Added new file defining the ToolProvider protocol and ToolProviderContext for decoupled tool injection.
  • astrbot/core/tools/cron_tools.py
    • Added get_all_tools function to return all cron-related tools.
  • astrbot/core/tools/kb_query.py
    • Added new file for knowledge base query tool and retrieval logic.
  • astrbot/core/tools/prompts.py
    • Added new file for system prompt constants, consolidating various agent-level prompts.
  • astrbot/core/tools/send_message.py
    • Added new file for SendMessageToUserTool to handle proactive message delivery.
  • astrbot/core/utils/io.py
    • Added asyncio and ipaddress imports, get_public_ip_address function, and enhanced dashboard download caching logic.
  • astrbot/dashboard/routes/init.py
    • Imported new routes (LiveChatRoute, T2iRoute) and Response, RouteContext.
  • astrbot/dashboard/routes/persona.py
    • Added clone_persona route for persona duplication.
  • astrbot/dashboard/routes/route.py
    • Added to_json method to Response for consistent JSON serialization.
  • astrbot/dashboard/routes/static_file.py
    • Added a check to prevent re-registering the index route.
  • astrbot/dashboard/routes/tools.py
    • Added source field to tool list display and prevented toggling of internal tools.
  • astrbot/dashboard/server.py
    • Refactored dashboard initialization, added WebUI enable check, improved port checking, and enhanced URL display for various network configurations.
  • dashboard/.gitignore
    • Added bun.lock and pmpm-lock.yaml to ignored files.
  • dashboard/env.d.ts
    • Added *.vue module declaration for TypeScript.
  • dashboard/package.json
    • Updated eslint and vue-tsc versions, removed unused dependencies like sass-loader and vuetify-loader.
  • dashboard/pnpm-lock.yaml
    • Updated dependency lock file.
  • dashboard/public/config.json
    • Added new file for API base URL configuration presets.
  • dashboard/src/components/chat/LiveMode.vue
    • Updated WebSocket URL construction to dynamically use the API base URL and added axios import.
  • dashboard/src/components/chat/StandaloneChat.vue
    • Changed disabled prop for ChatInput and updated file handling in handleFileSelect to iterate over FileList.
  • dashboard/src/components/extension/componentPanel/components/ToolTable.vue
    • Added display for internal tools and disabled the toggle switch for them.
  • dashboard/src/components/extension/componentPanel/types.ts
    • Added source field to ToolItem interface.
  • dashboard/src/i18n/locales/en-US/core/header.json
    • Added 'Log Out' translation.
  • dashboard/src/i18n/locales/en-US/features/auth.json
    • Added server configuration translations.
  • dashboard/src/i18n/locales/en-US/features/persona.json
    • Added persona cloning translations.
  • dashboard/src/i18n/locales/en-US/features/settings.json
    • Added network, style, reset, and logout settings translations.
  • dashboard/src/i18n/locales/en-US/features/welcome.json
    • Added backend URL configuration step to the onboarding process.
  • dashboard/src/i18n/locales/ru-RU/features/persona.json
    • Added persona cloning translations.
  • dashboard/src/i18n/locales/zh-CN/core/header.json
    • Added '退出登录' translation.
  • dashboard/src/i18n/locales/zh-CN/features/auth.json
    • Added server configuration translations.
  • dashboard/src/i18n/locales/zh-CN/features/persona.json
    • Added persona cloning translations.
  • dashboard/src/i18n/locales/zh-CN/features/settings.json
    • Added network, style, reset, and logout settings translations.
  • dashboard/src/i18n/locales/zh-CN/features/welcome.json
    • Added backend URL configuration step to the onboarding process.
  • dashboard/src/layouts/full/vertical-header/VerticalHeader.vue
    • Added a logout button, updated the view mode toggle, and adjusted the desktop update dialog logic.
  • dashboard/src/main.ts
    • Refactored API base URL handling, added config.json loading, and API store initialization.
  • dashboard/src/stores/api.ts
    • Added new file for API store to manage base URL and presets.
  • dashboard/src/stores/personaStore.ts
    • Added clonePersona action to handle persona duplication.
  • dashboard/src/views/Settings.vue
    • Added server address configuration, theme color customization, and a logout button.
  • dashboard/src/views/WelcomePage.vue
    • Added a backend configuration step to the onboarding process.
  • dashboard/src/views/authentication/auth/LoginPage.vue
    • Added a server configuration dialog for API base URL settings.
  • dashboard/src/views/persona/PersonaCard.vue
    • Added an emit event for cloning a persona.
  • dashboard/src/views/persona/PersonaManager.vue
    • Added a dialog and logic for cloning personas.
  • dashboard/tsconfig.json
    • Updated TypeScript compiler options for better compatibility and strictness.
  • dashboard/tsconfig.vite-config.json
    • Updated TypeScript compiler options for Vite configuration.
  • dashboard/vite.config.ts
    • Changed server.host to :: for IPv6 support and updated chunkSizeWarningLimit.
  • docs/refactor-neo-decouple.md
    • Added new documentation detailing the refactoring of Neo tool decoupling.
  • main.py
    • Improved dashboard download logic to retry with the latest version if a specific version download fails.
  • pyproject.toml
    • Updated project version to 4.21.0 and added quart-cors dependency.
  • requirements.txt
    • Updated and regenerated the list of Python dependencies.
  • tests/test_booter_decoupling.py
    • Added new test file to verify the booter decoupling refactoring.
  • tests/test_computer_config.py
    • Updated tests for Bay credentials discovery and computer configuration logging.
  • tests/test_profile_aware_tools.py
    • Updated tests for profile-aware tools in the context of the new tool provider system.
  • tests/test_tool_loop_agent_runner.py
    • Added a test case for run_agent to ensure it emits final media chains in streaming mode.
  • tests/unit/test_astr_main_agent.py
    • Added tests for disabling streaming for webchat image output based on model metadata and provider configuration.
  • tests/unit/test_gemini_source.py
    • Added new test file to verify Gemini source behavior, specifically regarding image modalities in streaming requests.
  • tests/unit/test_internal_agent_sub_stage.py
    • Added new test file to verify the internal agent sub-stage's handling of streaming flags and tool injection.
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/deploy-dashboard.yml
    • .github/workflows/smoke_test.yml
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a compatibility fix for non-standard API responses from OpenAI adapters, specifically addressing cases where the tool_call.type field might be missing or empty. The changes correctly identify and补全 (complete) this field to 'function' when a function call is present, preventing AssertionErrors in the OpenAI SDK. The implementation is clear, well-commented, and enhances the robustness of the system when integrating with various OpenAI-compatible platforms. No critical or high-severity issues were found.

@a61995987 a61995987 closed this Mar 16, 2026
@a61995987 a61995987 reopened this Mar 16, 2026
@a61995987 a61995987 changed the title Fix 兼容openai适配器的非标返回 fix: 兼容openai适配器的非标返回 Mar 16, 2026
@Soulter
Copy link
Copy Markdown
Member

Soulter commented Mar 27, 2026

#6829 fixed.

@Soulter Soulter closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants