AS AgentScopeAPI 手册 / API Reference

BaseScheduleAgentTask

public class BaseScheduleAgentTask implements ScheduleAgentTask<Msg>
源码Source 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

构造器Constructor说明Description
public BaseScheduleAgentTask(RuntimeAgentConfig agentConfig, ScheduleConfig scheduleConfig, AgentScheduler scheduler)
初始化 `BaseScheduleAgentTask` 实例。
Constructor for BaseScheduleAgentTask.

方法摘要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.

参数Parameters
名称Name类型Type说明Description
agentConfigRuntimeAgentConfig智能体配置(类型 `RuntimeAgentConfig`)。The runtime agent configuration containing model, toolkit, and hooks
scheduleConfigScheduleConfig调度配置(类型 `ScheduleConfig`)。The schedule configuration defining timing and execution policies
schedulerAgentScheduler调度器(类型 `AgentScheduler`)。The scheduler managing this task
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:108–118

方法详情Method Detail

getId

public String getId()

获取标识。

Get the unique identifier of this scheduled task.

返回Returns String
返回字符串结果。The unique task identifier
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:129–132

getName

public String getName()

获取名称的此已调度任务。

Get the name of this scheduled task.

返回Returns String
任务名称。The task name
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:141–144

run

public Mono<Msg> run(Msg... msgs)

设置运行。

Execute the scheduled task immediately.

参数Parameters
名称Name类型Type说明Description
msgs varargsMsg...消息列表(类型 `Msg...`)。The input messages to pass to the agent (optional, can be empty or null)
返回Returns Mono<Msg>
返回Mono。A Mono that emits the agent's response message when execution completes
抛出Throws
  • IllegalStateException 可能抛出 `IllegalStateException`。if the task has been cancelled
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:156–169

cancel

public void cancel()

执行取消相关操作。

Cancel this scheduled task permanently.

源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:178–182

isCancelled

public boolean isCancelled()

判断是否已取消。

Check if this task has been cancelled.

返回Returns boolean
返回布尔值,表示判断结果。true if the task is cancelled, false otherwise
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:193–195

getScheduleConfig

public ScheduleConfig getScheduleConfig()

获取调度配置。

Get the schedule configuration used for this agent.

返回Returns ScheduleConfig
ScheduleConfig 用于此已调度智能体。The ScheduleConfig for this scheduled agent
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:205–207

getAgentConfig

public RuntimeAgentConfig getAgentConfig()

获取运行时智能体配置。

Get the runtime agent configuration.

返回Returns RuntimeAgentConfig
RuntimeAgentConfig 实例。The RuntimeAgentConfig instance
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:217–219

getExecutionCount

public long getExecutionCount()

获取执行数量。

Get the total number of times this task has been executed.

返回Returns long
返回数值结果。The total execution count (starts at 0)
源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:266–268

incrementExecutionCount

public void incrementExecutionCount()

执行 incrementExecutionCount 方法。

Increment the execution count.

源码Source io/agentscope/extensions/scheduler/BaseScheduleAgentTask.java:276–278
基于官方固定版本源码静态生成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.