BaseScheduleAgentTask
public class BaseScheduleAgentTask implements ScheduleAgentTask<Msg>
io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:92–279基类调度智能体任务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.extensions.scheduler 包,实现 ScheduleAgentTask<Msg>。核心成员包括 getId、getName、run、cancel、isCancelled、getScheduleConfig。
Default implementation of ScheduleAgentTask.
This class represents a scheduled agent task that manages the lifecycle and execution
of agents according to a schedule. It uses AgentConfig to dynamically create
fresh Agent instances for each execution, providing better state isolation and resource management.
Key Features:
-
Dynamic Agent Creation - Creates fresh Agent instances for each execution
-
State Isolation - Each execution gets a clean Agent state
-
Task Control - Provides methods to run and cancel the scheduled task
-
Status Monitoring - Access to execution metrics and scheduling information
-
Thread Safety - Safe for concurrent access from multiple threads
Usage Example:
`// Create agent configuration
AgentConfig agentConfig = AgentConfig.builder()
.name("MyAgent")
.model(model)
.toolkit(toolkit)
.build();
// Schedule the agent
ScheduleConfig scheduleConfig = ScheduleConfig.builder()
.cron("0 0 8 * * ?")
.build();
ScheduleAgentTask task = scheduler.schedule(agentConfig, scheduleConfig);
// Control the task
String taskId = task.getId();
String taskName = task.getName();
// Manually trigger execution
task.run();
// Cancel the task
task.cancel();
// Query execution info (if cast to BaseScheduleAgentTask)
if (task instanceof BaseScheduleAgentTask baseTask) {
boolean cancelled = baseTask.isCancelled();
long count = baseTask.getExecutionCount();
}
`
Thread Safety: This class is designed to be thread-safe as scheduling operations may be triggered from different threads. Each execution creates a new Agent instance, ensuring thread-safe execution.
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String getId() | 获取标识。 Get the unique identifier of this scheduled task. |
public String getName() | 获取名称的此已调度任务。 Get the name of this scheduled task. |
public Mono<Msg> run(Msg... msgs) | 设置运行。 Execute the scheduled task immediately. |
public void cancel() | 执行取消相关操作。 Cancel this scheduled task permanently. |
public boolean isCancelled() | 判断是否已取消。 Check if this task has been cancelled. |
public ScheduleConfig getScheduleConfig() | 获取调度配置。 Get the schedule configuration used for this agent. |
public RuntimeAgentConfig getAgentConfig() | 获取运行时智能体配置。 Get the runtime agent configuration. |
public long getExecutionCount() | 获取执行数量。 Get the total number of times this task has been executed. |
public void incrementExecutionCount() | 执行 `incrementExecutionCount` 方法。 Increment the execution count. |
构造器详情Constructor Detail
BaseScheduleAgentTask
public BaseScheduleAgentTask(RuntimeAgentConfig agentConfig, ScheduleConfig scheduleConfig, AgentScheduler scheduler)
初始化 BaseScheduleAgentTask 实例。
Constructor for BaseScheduleAgentTask.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentConfig | RuntimeAgentConfig | 智能体配置(类型 `RuntimeAgentConfig`)。The runtime agent configuration containing model, toolkit, and hooks |
scheduleConfig | ScheduleConfig | 调度配置(类型 `ScheduleConfig`)。The schedule configuration defining timing and execution policies |
scheduler | AgentScheduler | 调度器(类型 `AgentScheduler`)。The scheduler managing this task |
io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:108–118方法详情Method Detail
getId
public String getId()
获取标识。
Get the unique identifier of this scheduled task.
Stringio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:129–132getName
public String getName()
获取名称的此已调度任务。
Get the name of this scheduled task.
Stringio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:141–144run
public Mono<Msg> run(Msg... msgs)
设置运行。
Execute the scheduled task immediately.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs varargs | Msg... | 消息列表(类型 `Msg...`)。The input messages to pass to the agent (optional, can be empty or null) |
Mono<Msg>IllegalStateException可能抛出 `IllegalStateException`。if the task has been cancelled
io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:156–169cancel
public void cancel()
执行取消相关操作。
Cancel this scheduled task permanently.
io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:178–182isCancelled
public boolean isCancelled()
判断是否已取消。
Check if this task has been cancelled.
booleanio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:193–195getScheduleConfig
public ScheduleConfig getScheduleConfig()
获取调度配置。
Get the schedule configuration used for this agent.
ScheduleConfigio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:205–207getAgentConfig
public RuntimeAgentConfig getAgentConfig()
获取运行时智能体配置。
Get the runtime agent configuration.
RuntimeAgentConfigio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:217–219getExecutionCount
public long getExecutionCount()
获取执行数量。
Get the total number of times this task has been executed.
longio/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:266–268incrementExecutionCount
public void incrementExecutionCount()
执行 incrementExecutionCount 方法。
Increment the execution count.
io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:276–278