ruff format
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user