AS AgentScopeAPI 手册 / API Reference

QuartzAgentScheduler

public class QuartzAgentScheduler implements AgentScheduler
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:116–705

Quartz 智能体调度器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.extensions.scheduler.quartz 包,实现 AgentScheduler。核心成员包括 builder、schedule、cancel、getScheduledAgent、getAllScheduleAgentTasks、shutdown。

AgentScheduler implementation based on Quartz Scheduler.

This scheduler integrates with Quartz to provide robust task scheduling capabilities for agents within the application. It supports various scheduling modes and lifecycle management.

Key Features:

  • In-memory or persistent scheduling (configurable via Quartz properties)

  • Support for cron expressions, fixed rate, and fixed delay execution

  • Full lifecycle management: schedule, pause, resume, cancel

  • Thread-safe task management

Prerequisites:

  • Quartz dependencies must be on the classpath

  • Proper configuration of Quartz properties if using persistence

Usage Example:

`// 1. Create scheduler
AgentScheduler scheduler = QuartzAgentScheduler.builder()
.autoStart(true)
.build();

// 2. Create agent configuration
AgentConfig agentConfig = AgentConfig.builder()
.name("MyAgent")
.description("My scheduled agent")
.agentFactory(() -> ReActAgent.builder()
.name("MyAgent")
.model(model)
.toolkit(toolkit)
.build())
.build();

// 3. Configure schedule
ScheduleConfig scheduleConfig = ScheduleConfig.builder()
.scheduleMode(ScheduleMode.CRON)
.cronExpression("0 0 8 * * ?") // Run at 8:00 AM every day
.build();

// 4. Schedule the agent
ScheduleAgentTask task = scheduler.schedule(agentConfig, scheduleConfig);

// 5. Manage task
scheduler.pause("MyAgent");
scheduler.resume("MyAgent");
scheduler.cancel("MyAgent");
`

Important Notes:

  • Uses a QuartzAgentSchedulerRegistry to bridge Quartz Jobs with Scheduler instances

  • Supports FIXED_DELAY mode by manually rescheduling triggers after job completion

  • Each scheduler instance has a unique ID to support multiple schedulers in the same JVM

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
`QuartzAgentScheduler`的构建器。
Builder for `QuartzAgentScheduler`.

方法摘要Method Summary

方法Method说明Description
public static Builder builder()
static
创建新的构建器实例用于 QuartzAgentScheduler。
Create a new Builder instance for QuartzAgentScheduler.
public ScheduleAgentTask schedule(AgentConfig agentConfig)
设置调度。
Schedule an agent execution based on the provided configuration with default schedule.
public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig)
执行调度相关操作。
Schedule an agent execution based on the provided configuration with no initial input.
public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig, Msg input)
执行调度相关操作。
Schedule an agent execution based on the provided configuration and initial input message.
public boolean cancel(String name)
执行取消相关操作。
Cancel a scheduled agent task.
public QuartzScheduleAgentTask getScheduledAgent(String name)
获取已调度智能体。
Retrieve a scheduled agent task by name.
public List<ScheduleAgentTask> getAllScheduleAgentTasks()
获取所有调度智能体任务。
Retrieve all scheduled agent tasks.
public void shutdown()
关闭资源并释放连接。
Shutdown the scheduler.
public String getSchedulerType()
获取调度器类型。
Returns the scheduler type.
public boolean pause(String name)
设置该参数。
Pause a scheduled task.
public boolean resume(String name)
设置恢复。
Resume a paused task.
public boolean interrupt(String name)
请求中断当前执行。
Interrupt a running task.
public TriggerState getStatus(String name)
获取当前状态的已调度任务。
Get the current status of a scheduled task.

方法详情Method Detail

builder

public static Builder builder()
static

创建新的构建器实例用于 QuartzAgentScheduler。

Create a new Builder instance for QuartzAgentScheduler.

返回Returns Builder
一种新的构建器。A new Builder
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:144–146

schedule

public ScheduleAgentTask schedule(AgentConfig agentConfig)

设置调度。

Schedule an agent execution based on the provided configuration with default schedule.

参数Parameters
名称Name类型Type说明Description
agentConfigAgentConfig配置用于智能体到为已调度。The configuration for the agent to be scheduled
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。A task handle for the scheduled agent
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:154–156

schedule

public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig)

执行调度相关操作。

Schedule an agent execution based on the provided configuration with no initial input.

参数Parameters
名称Name类型Type说明Description
agentConfigAgentConfig配置用于智能体到为已调度。The configuration for the agent to be scheduled
scheduleConfigScheduleConfig调度配置(类型 `ScheduleConfig`)。The scheduling configuration (time, mode, etc.)
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。A task handle for the scheduled agent
抛出Throws
  • RuntimeException 可能抛出 `RuntimeException`。if scheduling fails
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:169–172

schedule

public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig, Msg input)

执行调度相关操作。

Schedule an agent execution based on the provided configuration and initial input message.

参数Parameters
名称Name类型Type说明Description
agentConfigAgentConfig配置用于智能体到为已调度。The configuration for the agent to be scheduled
scheduleConfigScheduleConfig调度配置(类型 `ScheduleConfig`)。The scheduling configuration (time, mode, etc.)
inputMsg输入消息(类型 `Msg`)。The initial message to pass to the agent when triggered (can be null)
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。A task handle for the scheduled agent
抛出Throws
  • RuntimeException 可能抛出 `RuntimeException`。if scheduling fails or if the input message serialization fails
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:194–316

cancel

public boolean cancel(String name)

执行取消相关操作。

Cancel a scheduled agent task.

参数Parameters
名称Name类型Type说明Description
nameString智能体/任务到取消的名称。The name of the agent/task to cancel
返回Returns boolean
返回布尔值,表示判断结果。`true` if the task was found and cancelled, `false` otherwise
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:326–345

getScheduledAgent

public QuartzScheduleAgentTask getScheduledAgent(String name)

获取已调度智能体。

Retrieve a scheduled agent task by name.

参数Parameters
名称Name类型Type说明Description
nameString智能体的名称。The name of the agent
返回Returns QuartzScheduleAgentTask
返回QuartzScheduleAgentTask。The task handle, or `null` if not found
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:353–366

getAllScheduleAgentTasks

public List<ScheduleAgentTask> getAllScheduleAgentTasks()

获取所有调度智能体任务。

Retrieve all scheduled agent tasks.

返回Returns List<ScheduleAgentTask>
一种列出的所有任务托管通过此调度器。A list of all tasks managed by this scheduler
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:377–401

shutdown

public void shutdown()

关闭资源并释放连接。

Shutdown the scheduler.

另见See also @see Scheduler#shutdown(boolean)
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:410–421

getSchedulerType

public String getSchedulerType()

获取调度器类型。

Returns the scheduler type.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:423–426

pause

public boolean pause(String name)

设置该参数。

Pause a scheduled task.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name of the agent/task to pause
返回Returns boolean
返回布尔值,表示判断结果。`true` if successfully paused, `false` otherwise
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:434–451

resume

public boolean resume(String name)

设置恢复。

Resume a paused task.

参数Parameters
名称Name类型Type说明Description
nameString智能体/任务到恢复的名称。The name of the agent/task to resume
返回Returns boolean
返回布尔值,表示判断结果。`true` if successfully resumed, `false` otherwise
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:459–476

interrupt

public boolean interrupt(String name)

请求中断当前执行。

Interrupt a running task.

参数Parameters
名称Name类型Type说明Description
nameString智能体/任务到中断的名称。The name of the agent/task to interrupt
返回Returns boolean
返回布尔值,表示判断结果。`true` if the interrupt signal was sent, `false` otherwise
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:484–501

getStatus

public TriggerState getStatus(String name)

获取当前状态的已调度任务。

Get the current status of a scheduled task.

参数Parameters
名称Name类型Type说明Description
nameString智能体/任务的名称。The name of the agent/task
返回Returns TriggerState
返回TriggerState。The Quartz TriggerState, or `null` if not found
源码Source io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:535–551

嵌套类详情Nested Class Detail

Builder

public static class Builder

QuartzAgentScheduler的构建器。位于 io.agentscope.extensions.scheduler.quartz 包。核心成员包括 schedulerId、scheduler、autoStart、build。

Builder for QuartzAgentScheduler.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.