QuartzAgentScheduler
public class QuartzAgentScheduler implements AgentScheduler
io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:116–705Quartz 智能体调度器,承载智能体的部署、调度与服务化运行。位于 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
QuartzAgentSchedulerRegistryto bridge Quartz Jobs with Scheduler instances -
Supports
FIXED_DELAYmode 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 Detail
builder
public static Builder builder()
创建新的构建器实例用于 QuartzAgentScheduler。
Create a new Builder instance for QuartzAgentScheduler.
Builderio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:144–146schedule
public ScheduleAgentTask schedule(AgentConfig agentConfig)
设置调度。
Schedule an agent execution based on the provided configuration with default schedule.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentConfig | AgentConfig | 配置用于智能体到为已调度。The configuration for the agent to be scheduled |
ScheduleAgentTaskio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:154–156schedule
public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig)
执行调度相关操作。
Schedule an agent execution based on the provided configuration with no initial input.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentConfig | AgentConfig | 配置用于智能体到为已调度。The configuration for the agent to be scheduled |
scheduleConfig | ScheduleConfig | 调度配置(类型 `ScheduleConfig`)。The scheduling configuration (time, mode, etc.) |
ScheduleAgentTaskRuntimeException可能抛出 `RuntimeException`。if scheduling fails
io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:169–172schedule
public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig, Msg input)
执行调度相关操作。
Schedule an agent execution based on the provided configuration and initial input message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentConfig | AgentConfig | 配置用于智能体到为已调度。The configuration for the agent to be scheduled |
scheduleConfig | ScheduleConfig | 调度配置(类型 `ScheduleConfig`)。The scheduling configuration (time, mode, etc.) |
input | Msg | 输入消息(类型 `Msg`)。The initial message to pass to the agent when triggered (can be null) |
ScheduleAgentTaskRuntimeException可能抛出 `RuntimeException`。if scheduling fails or if the input message serialization fails
io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:194–316cancel
public boolean cancel(String name)
执行取消相关操作。
Cancel a scheduled agent task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体/任务到取消的名称。The name of the agent/task to cancel |
booleanio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:326–345getScheduledAgent
public QuartzScheduleAgentTask getScheduledAgent(String name)
获取已调度智能体。
Retrieve a scheduled agent task by name.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体的名称。The name of the agent |
QuartzScheduleAgentTaskio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:353–366getAllScheduleAgentTasks
public List<ScheduleAgentTask> getAllScheduleAgentTasks()
获取所有调度智能体任务。
Retrieve all scheduled agent tasks.
List<ScheduleAgentTask>io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:377–401shutdown
public void shutdown()
关闭资源并释放连接。
Shutdown the scheduler.
io/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:410–421getSchedulerType
public String getSchedulerType()
获取调度器类型。
Returns the scheduler type.
Stringio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:423–426pause
public boolean pause(String name)
设置该参数。
Pause a scheduled task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。The name of the agent/task to pause |
booleanio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:434–451resume
public boolean resume(String name)
设置恢复。
Resume a paused task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体/任务到恢复的名称。The name of the agent/task to resume |
booleanio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:459–476interrupt
public boolean interrupt(String name)
请求中断当前执行。
Interrupt a running task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体/任务到中断的名称。The name of the agent/task to interrupt |
booleanio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:484–501getStatus
public TriggerState getStatus(String name)
获取当前状态的已调度任务。
Get the current status of a scheduled task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 智能体/任务的名称。The name of the agent/task |
TriggerStateio/agentscope/extensions/scheduler/quartz/QuartzAgentScheduler.java:535–551嵌套类详情Nested Class Detail
Builder
public static class BuilderQuartzAgentScheduler的构建器。位于 io.agentscope.extensions.scheduler.quartz 包。核心成员包括 schedulerId、scheduler、autoStart、build。
Builder for QuartzAgentScheduler.