From 83288ca43e24f41599c05d51153b1bbe4a8a673f Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 1 Feb 2026 14:33:17 +0800 Subject: [PATCH] ruff format --- astrbot/core/astr_agent_tool_exec.py | 16 +++++----- astrbot/core/astr_main_agent.py | 4 +-- astrbot/core/core_lifecycle.py | 2 +- astrbot/core/cron/events.py | 1 + astrbot/core/cron/manager.py | 7 ++--- astrbot/core/db/po.py | 4 ++- .../method/agent_sub_stages/internal.py | 12 ++++---- astrbot/core/star/context.py | 2 +- astrbot/dashboard/routes/cron.py | 30 ++++++++++++++----- 9 files changed, 48 insertions(+), 30 deletions(-) diff --git a/astrbot/core/astr_agent_tool_exec.py b/astrbot/core/astr_agent_tool_exec.py index d238f757b..523f917eb 100644 --- a/astrbot/core/astr_agent_tool_exec.py +++ b/astrbot/core/astr_agent_tool_exec.py @@ -1,33 +1,33 @@ import asyncio import inspect +import json import traceback import typing as T import uuid -import json import mcp from astrbot import logger from astrbot.core.agent.handoff import HandoffTool from astrbot.core.agent.mcp_client import MCPTool -from astrbot.core.agent.run_context import ContextWrapper from astrbot.core.agent.message import Message +from astrbot.core.agent.run_context import ContextWrapper from astrbot.core.agent.tool import FunctionTool, ToolSet from astrbot.core.agent.tool_executor import BaseFunctionToolExecutor from astrbot.core.astr_agent_context import AstrAgentContext +from astrbot.core.astr_main_agent_resources import ( + BACKGROUND_TASK_RESULT_WOKE_SYSTEM_PROMPT, + SEND_MESSAGE_TO_USER_TOOL, +) from astrbot.core.cron.events import CronMessageEvent from astrbot.core.message.message_event_result import ( CommandResult, MessageChain, MessageEventResult, ) -from astrbot.core.provider.entites import ProviderRequest from astrbot.core.platform.message_session import MessageSession +from astrbot.core.provider.entites import ProviderRequest from astrbot.core.provider.register import llm_tools -from astrbot.core.astr_main_agent_resources import ( - BACKGROUND_TASK_RESULT_WOKE_SYSTEM_PROMPT, - SEND_MESSAGE_TO_USER_TOOL, -) class FunctionToolExecutor(BaseFunctionToolExecutor[AstrAgentContext]): @@ -154,9 +154,9 @@ class FunctionToolExecutor(BaseFunctionToolExecutor[AstrAgentContext]): **tool_args, ): from astrbot.core.astr_main_agent import ( - build_main_agent, MainAgentBuildConfig, _get_session_conv, + build_main_agent, ) # run the tool diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index e58625bf1..169556047 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -26,9 +26,9 @@ from astrbot.core.astr_main_agent_resources import ( FILE_UPLOAD_TOOL, KNOWLEDGE_BASE_QUERY_TOOL, LIVE_MODE_SYSTEM_PROMPT, + LLM_SAFETY_MODE_SYSTEM_PROMPT, LOCAL_EXECUTE_SHELL_TOOL, LOCAL_PYTHON_TOOL, - LLM_SAFETY_MODE_SYSTEM_PROMPT, PYTHON_TOOL, SANDBOX_MODE_PROMPT, TOOL_CALL_PROMPT, @@ -59,7 +59,7 @@ class MainAgentBuildConfig: tool_call_timeout: int """The timeout (in seconds) for a tool call. - When the tool call exceeds this time, + When the tool call exceeds this time, a timeout error as a tool result will be returned. """ tool_schema_mode: str = "full" diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index c44d366a5..f619b64af 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -21,11 +21,11 @@ from astrbot.core import LogBroker, LogManager from astrbot.core.astrbot_config_mgr import AstrBotConfigManager from astrbot.core.config.default import VERSION from astrbot.core.conversation_mgr import ConversationManager +from astrbot.core.cron import CronJobManager from astrbot.core.db import BaseDatabase from astrbot.core.knowledge_base.kb_mgr import KnowledgeBaseManager from astrbot.core.persona_mgr import PersonaManager from astrbot.core.pipeline.scheduler import PipelineContext, PipelineScheduler -from astrbot.core.cron import CronJobManager from astrbot.core.platform.manager import PlatformManager from astrbot.core.platform_message_history_mgr import PlatformMessageHistoryManager from astrbot.core.provider.manager import ProviderManager diff --git a/astrbot/core/cron/events.py b/astrbot/core/cron/events.py index 21c92e5a0..d4f0e01e2 100644 --- a/astrbot/core/cron/events.py +++ b/astrbot/core/cron/events.py @@ -1,6 +1,7 @@ import time import uuid from typing import Any + from astrbot.core.message.components import Plain from astrbot.core.message.message_event_result import MessageChain from astrbot.core.platform.astr_message_event import AstrMessageEvent diff --git a/astrbot/core/cron/manager.py b/astrbot/core/cron/manager.py index 64b3e2a21..06e88649e 100644 --- a/astrbot/core/cron/manager.py +++ b/astrbot/core/cron/manager.py @@ -1,7 +1,8 @@ import asyncio import json +from collections.abc import Awaitable, Callable from datetime import datetime, timezone -from typing import Any, Awaitable, Callable +from typing import TYPE_CHECKING, Any from zoneinfo import ZoneInfo from apscheduler.schedulers.asyncio import AsyncIOScheduler @@ -15,8 +16,6 @@ from astrbot.core.db.po import CronJob from astrbot.core.platform.message_session import MessageSession from astrbot.core.provider.entites import ProviderRequest -from typing import TYPE_CHECKING - if TYPE_CHECKING: from astrbot.core.star.context import Context @@ -242,9 +241,9 @@ class CronJobManager: ): """Woke the main agent to handle the cron job message.""" from astrbot.core.astr_main_agent import ( - build_main_agent, MainAgentBuildConfig, _get_session_conv, + build_main_agent, ) from astrbot.core.astr_main_agent_resources import ( PROACTIVE_AGENT_CRON_WOKE_SYSTEM_PROMPT, diff --git a/astrbot/core/db/po.py b/astrbot/core/db/po.py index b037bf983..8068864d0 100644 --- a/astrbot/core/db/po.py +++ b/astrbot/core/db/po.py @@ -157,7 +157,9 @@ class CronJob(TimestampMixin, SQLModel, table=True): ) name: str = Field(max_length=255, nullable=False) description: str | None = Field(default=None, sa_type=Text) - job_type: str = Field(max_length=32, nullable=False) # basic | active_agent | background + job_type: str = Field( + max_length=32, nullable=False + ) # basic | active_agent | background cron_expression: str | None = Field(default=None, max_length=255) timezone: str | None = Field(default=None, max_length=64) payload: dict = Field(default_factory=dict, sa_type=JSON) diff --git a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py index f67164821..6c6b72dff 100644 --- a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py +++ b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py @@ -3,10 +3,16 @@ import asyncio import base64 from collections.abc import AsyncGenerator +from dataclasses import replace from astrbot.core import logger from astrbot.core.agent.message import Message from astrbot.core.agent.response import AgentStats +from astrbot.core.astr_main_agent import ( + MainAgentBuildConfig, + MainAgentBuildResult, + build_main_agent, +) from astrbot.core.message.components import File, Image from astrbot.core.message.message_event_result import ( MessageChain, @@ -25,12 +31,6 @@ from astrbot.core.utils.session_lock import session_lock_manager from .....astr_agent_run_util import run_agent, run_live_agent from ....context import PipelineContext, call_event_hook from ...stage import Stage -from astrbot.core.astr_main_agent import ( - MainAgentBuildConfig, - MainAgentBuildResult, - build_main_agent, -) -from dataclasses import replace class InternalAgentSubStage(Stage): diff --git a/astrbot/core/star/context.py b/astrbot/core/star/context.py index a89f5db37..fee20640a 100644 --- a/astrbot/core/star/context.py +++ b/astrbot/core/star/context.py @@ -10,9 +10,9 @@ from astrbot.core.agent.message import Message from astrbot.core.agent.runners.tool_loop_agent_runner import ToolLoopAgentRunner from astrbot.core.agent.tool import ToolSet from astrbot.core.astrbot_config_mgr import AstrBotConfigManager -from astrbot.core.cron.manager import CronJobManager from astrbot.core.config.astrbot_config import AstrBotConfig from astrbot.core.conversation_mgr import ConversationManager +from astrbot.core.cron.manager import CronJobManager from astrbot.core.db import BaseDatabase from astrbot.core.knowledge_base.kb_mgr import KnowledgeBaseManager from astrbot.core.message.message_event_result import MessageChain diff --git a/astrbot/dashboard/routes/cron.py b/astrbot/dashboard/routes/cron.py index ae4f8e206..df3110770 100644 --- a/astrbot/dashboard/routes/cron.py +++ b/astrbot/dashboard/routes/cron.py @@ -10,7 +10,9 @@ from .route import Response, Route, RouteContext class CronRoute(Route): - def __init__(self, context: RouteContext, core_lifecycle: AstrBotCoreLifecycle) -> None: + def __init__( + self, context: RouteContext, core_lifecycle: AstrBotCoreLifecycle + ) -> None: super().__init__(context) self.core_lifecycle = core_lifecycle self.routes = [ @@ -32,7 +34,9 @@ class CronRoute(Route): try: cron_mgr = self.core_lifecycle.cron_manager if cron_mgr is None: - return jsonify(Response().error("Cron manager not initialized").__dict__) + return jsonify( + Response().error("Cron manager not initialized").__dict__ + ) job_type = request.args.get("type") jobs = await cron_mgr.list_jobs(job_type) data = [self._serialize_job(j) for j in jobs] @@ -45,7 +49,9 @@ class CronRoute(Route): try: cron_mgr = self.core_lifecycle.cron_manager if cron_mgr is None: - return jsonify(Response().error("Cron manager not initialized").__dict__) + return jsonify( + Response().error("Cron manager not initialized").__dict__ + ) payload = await request.json if not isinstance(payload, dict): @@ -62,7 +68,11 @@ class CronRoute(Route): enabled = bool(payload.get("enabled", True)) if not cron_expression or not session: - return jsonify(Response().error("cron_expression and session are required").__dict__) + return jsonify( + Response() + .error("cron_expression and session are required") + .__dict__ + ) job_payload = { "session": session, @@ -73,7 +83,9 @@ class CronRoute(Route): if job_type != "active_agent": return jsonify( - Response().error("Only active_agent jobs are supported now.").__dict__ + Response() + .error("Only active_agent jobs are supported now.") + .__dict__ ) job = await cron_mgr.add_active_job( @@ -94,7 +106,9 @@ class CronRoute(Route): try: cron_mgr = self.core_lifecycle.cron_manager if cron_mgr is None: - return jsonify(Response().error("Cron manager not initialized").__dict__) + return jsonify( + Response().error("Cron manager not initialized").__dict__ + ) payload = await request.json if not isinstance(payload, dict): @@ -122,7 +136,9 @@ class CronRoute(Route): try: cron_mgr = self.core_lifecycle.cron_manager if cron_mgr is None: - return jsonify(Response().error("Cron manager not initialized").__dict__) + return jsonify( + Response().error("Cron manager not initialized").__dict__ + ) await cron_mgr.delete_job(job_id) return jsonify(Response().ok(message="deleted").__dict__) except Exception as e: # noqa: BLE001