From 39eb367866fed6d079c068e8f90fd831c3363f81 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 24 Nov 2025 14:00:16 +0800 Subject: [PATCH] perf: improve file structure - Implemented CozeAPIClient for file upload, image download, chat messaging, and context management. - Developed DashscopeAgentRunner for handling requests to the Dashscope API with streaming support. - Created DifyAgentRunner to manage interactions with the Dify API, including file uploads and workflow execution. - Introduced DifyAPIClient for making asynchronous requests to the Dify API. - Updated third-party agent imports to reflect new module structure. --- .../core/agent/runners/{ => coze}/coze_agent_runner.py | 10 +++++----- .../sources => agent/runners/coze}/coze_api_client.py | 0 .../runners/{ => dashscope}/dashscope_agent_runner.py | 8 ++++---- .../core/agent/runners/{ => dify}/dify_agent_runner.py | 10 +++++----- .../{utils => agent/runners/dify}/dify_api_client.py | 0 .../method/agent_sub_stages/third_party.py | 8 +++++--- 6 files changed, 19 insertions(+), 17 deletions(-) rename astrbot/core/agent/runners/{ => coze}/coze_agent_runner.py (98%) rename astrbot/core/{provider/sources => agent/runners/coze}/coze_api_client.py (100%) rename astrbot/core/agent/runners/{ => dashscope}/dashscope_agent_runner.py (98%) rename astrbot/core/agent/runners/{ => dify}/dify_agent_runner.py (97%) rename astrbot/core/{utils => agent/runners/dify}/dify_api_client.py (100%) diff --git a/astrbot/core/agent/runners/coze_agent_runner.py b/astrbot/core/agent/runners/coze/coze_agent_runner.py similarity index 98% rename from astrbot/core/agent/runners/coze_agent_runner.py rename to astrbot/core/agent/runners/coze/coze_agent_runner.py index 885eef69..a8300bb7 100644 --- a/astrbot/core/agent/runners/coze_agent_runner.py +++ b/astrbot/core/agent/runners/coze/coze_agent_runner.py @@ -11,12 +11,12 @@ from astrbot.core.provider.entities import ( LLMResponse, ProviderRequest, ) -from astrbot.core.provider.sources.coze_api_client import CozeAPIClient -from ..hooks import BaseAgentRunHooks -from ..response import AgentResponseData -from ..run_context import ContextWrapper, TContext -from .base import AgentResponse, AgentState, BaseAgentRunner +from ...hooks import BaseAgentRunHooks +from ...response import AgentResponseData +from ...run_context import ContextWrapper, TContext +from ..base import AgentResponse, AgentState, BaseAgentRunner +from .coze_api_client import CozeAPIClient if sys.version_info >= (3, 12): from typing import override diff --git a/astrbot/core/provider/sources/coze_api_client.py b/astrbot/core/agent/runners/coze/coze_api_client.py similarity index 100% rename from astrbot/core/provider/sources/coze_api_client.py rename to astrbot/core/agent/runners/coze/coze_api_client.py diff --git a/astrbot/core/agent/runners/dashscope_agent_runner.py b/astrbot/core/agent/runners/dashscope/dashscope_agent_runner.py similarity index 98% rename from astrbot/core/agent/runners/dashscope_agent_runner.py rename to astrbot/core/agent/runners/dashscope/dashscope_agent_runner.py index b0618780..7a095a60 100644 --- a/astrbot/core/agent/runners/dashscope_agent_runner.py +++ b/astrbot/core/agent/runners/dashscope/dashscope_agent_runner.py @@ -17,10 +17,10 @@ from astrbot.core.provider.entities import ( ProviderRequest, ) -from ..hooks import BaseAgentRunHooks -from ..response import AgentResponseData -from ..run_context import ContextWrapper, TContext -from .base import AgentResponse, AgentState, BaseAgentRunner +from ...hooks import BaseAgentRunHooks +from ...response import AgentResponseData +from ...run_context import ContextWrapper, TContext +from ..base import AgentResponse, AgentState, BaseAgentRunner if sys.version_info >= (3, 12): from typing import override diff --git a/astrbot/core/agent/runners/dify_agent_runner.py b/astrbot/core/agent/runners/dify/dify_agent_runner.py similarity index 97% rename from astrbot/core/agent/runners/dify_agent_runner.py rename to astrbot/core/agent/runners/dify/dify_agent_runner.py index 1433cfdf..c586cc55 100644 --- a/astrbot/core/agent/runners/dify_agent_runner.py +++ b/astrbot/core/agent/runners/dify/dify_agent_runner.py @@ -11,13 +11,13 @@ from astrbot.core.provider.entities import ( ProviderRequest, ) from astrbot.core.utils.astrbot_path import get_astrbot_data_path -from astrbot.core.utils.dify_api_client import DifyAPIClient from astrbot.core.utils.io import download_file -from ..hooks import BaseAgentRunHooks -from ..response import AgentResponseData -from ..run_context import ContextWrapper, TContext -from .base import AgentResponse, AgentState, BaseAgentRunner +from ...hooks import BaseAgentRunHooks +from ...response import AgentResponseData +from ...run_context import ContextWrapper, TContext +from ..base import AgentResponse, AgentState, BaseAgentRunner +from .dify_api_client import DifyAPIClient if sys.version_info >= (3, 12): from typing import override diff --git a/astrbot/core/utils/dify_api_client.py b/astrbot/core/agent/runners/dify/dify_api_client.py similarity index 100% rename from astrbot/core/utils/dify_api_client.py rename to astrbot/core/agent/runners/dify/dify_api_client.py diff --git a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py index a9fb67dc..a54aa52d 100644 --- a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py +++ b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/third_party.py @@ -3,9 +3,11 @@ from collections.abc import AsyncGenerator from typing import TYPE_CHECKING from astrbot.core import logger -from astrbot.core.agent.runners.coze_agent_runner import CozeAgentRunner -from astrbot.core.agent.runners.dashscope_agent_runner import DashscopeAgentRunner -from astrbot.core.agent.runners.dify_agent_runner import DifyAgentRunner +from astrbot.core.agent.runners.coze.coze_agent_runner import CozeAgentRunner +from astrbot.core.agent.runners.dashscope.dashscope_agent_runner import ( + DashscopeAgentRunner, +) +from astrbot.core.agent.runners.dify.dify_agent_runner import DifyAgentRunner from astrbot.core.message.components import Image from astrbot.core.message.message_event_result import ( MessageChain,