AS AgentScopeAPI 手册 / API Reference

AgentScheduler

public interface AgentScheduler
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:77–190

定义智能体调度器契约的接口。位于 io.agentscope.extensions.scheduler 包。核心成员包括 schedule、cancel、getScheduledAgent、getAllScheduleAgentTasks、shutdown、getSchedulerType。

Core interface for scheduling agents to run at specified times or intervals.

This interface defines the fundamental operations for scheduling agents, including registering tasks with various scheduling configurations (cron expressions, fixed rates, fixed delays), managing task lifecycle (pause, resume, cancel), and querying scheduled agents.

Implementations can be based on different scheduling frameworks such as:

  • Spring TaskScheduler - Lightweight implementation for simple scenarios

  • Quartz Scheduler - Enterprise-grade implementation with persistence and clustering

  • External schedulers - Integration with distributed scheduling systems (XXL-Job, etc.)

Design Principles:

  • Task-centric - Returns ScheduleAgentTask for task lifecycle management

  • Framework agnostic - Core interface can be implemented with any scheduling backend

  • Extensible - Support for custom scheduling strategies through configuration

  • Stateful - Track task execution history, metrics, and current status

Usage Example:

`AgentScheduler scheduler = new XxlJobAgentScheduler(executor);

// Create agent configuration
AgentConfig agentConfig = AgentConfig.builder()
.name("MyAgent")
.model(model)
.toolkit(toolkit)
.sysPrompt("You are a helpful assistant")
.build();

// Create schedule configuration
ScheduleConfig scheduleConfig = ScheduleConfig.builder()
.cron("0 0 8 * * ?")
.build();

// Schedule the agent and get a task handle
ScheduleAgentTask task = scheduler.schedule(agentConfig, scheduleConfig);

// Control the task
task.run(); // Manual execution
task.cancel(); // Cancel scheduling

// Or cancel through scheduler
scheduler.cancel(task.getName());
`

方法摘要Method Summary

方法Method说明Description
public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig)
执行调度相关操作。
Schedule an agent to run according to the specified configuration.
default public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig, Msg input)
default
执行调度相关操作。
Schedule an agent to run with an initial input message.
public boolean cancel(String name)
执行取消相关操作。
Cancel and remove a scheduled task permanently.
public ScheduleAgentTask getScheduledAgent(String name)
获取已调度智能体。
Retrieve a scheduled task by its name.
public List<ScheduleAgentTask> getAllScheduleAgentTasks()
获取所有调度智能体任务。
Retrieve all scheduled tasks managed by this scheduler.
public void shutdown()
关闭资源并释放连接。
Gracefully shutdown the scheduler.
public String getSchedulerType()
获取调度器类型。
Get the type identifier of this scheduler implementation.

方法详情Method Detail

schedule

public ScheduleAgentTask schedule(AgentConfig agentConfig, ScheduleConfig scheduleConfig)

执行调度相关操作。

Schedule an agent to run according to the specified configuration.

参数Parameters
名称Name类型Type说明Description
agentConfigAgentConfig智能体配置(类型 `AgentConfig`)。The agent configuration defining how to create agents (can be AgentConfig or RuntimeAgentConfig)
scheduleConfigScheduleConfig调度配置(类型 `ScheduleConfig`)。The scheduling configuration including timing and execution policies
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。The ScheduleAgentTask handle for controlling the scheduled task
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if agentConfig or scheduleConfig is null or invalid
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:104

schedule

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

执行调度相关操作。

Schedule an agent to run with an initial input message.

参数Parameters
名称Name类型Type说明Description
agentConfigAgentConfig智能体配置(类型 `AgentConfig`)。The agent configuration defining how to create agents (can be AgentConfig or RuntimeAgentConfig)
scheduleConfigScheduleConfig调度配置(类型 `ScheduleConfig`)。The scheduling configuration including timing and execution policies
inputMsg输入消息(类型 `Msg`)。The initial message to pass to the agent when triggered (can be null)
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。The ScheduleAgentTask handle for controlling the scheduled task
抛出Throws
  • UnsupportedOperationException 可能抛出 `UnsupportedOperationException`。if the specific scheduler implementation does not support initial input
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:122–126

cancel

public boolean cancel(String name)

执行取消相关操作。

Cancel and remove a scheduled task permanently.

参数Parameters
名称Name类型Type说明Description
nameString已调度任务到取消的名称。The name of the scheduled task to cancel
返回Returns boolean
返回布尔值,表示判断结果。true if the task was successfully cancelled, false if not found or already removed
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:141

getScheduledAgent

public ScheduleAgentTask getScheduledAgent(String name)

获取已调度智能体。

Retrieve a scheduled task by its name.

参数Parameters
名称Name类型Type说明Description
nameString已调度任务的名称。The name of the scheduled task
返回Returns ScheduleAgentTask
返回ScheduleAgentTask。The ScheduleAgentTask if found, or null if no task with the given name is scheduled
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:156

getAllScheduleAgentTasks

public List<ScheduleAgentTask> getAllScheduleAgentTasks()

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

Retrieve all scheduled tasks managed by this scheduler.

返回Returns List<ScheduleAgentTask>
返回列出。A list of all ScheduleAgentTask instances
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:167

shutdown

public void shutdown()

关闭资源并释放连接。

Gracefully shutdown the scheduler.

源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:179

getSchedulerType

public String getSchedulerType()

获取调度器类型。

Get the type identifier of this scheduler implementation.

返回Returns String
返回字符串结果。The scheduler type identifier
源码Source io/agentscope/extensions/scheduler/AgentScheduler.java:189
基于官方固定版本源码静态生成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.