Interface ScheduleAgentTask<T>

All Known Implementing Classes:
BaseScheduleAgentTask

public interface ScheduleAgentTask<T>
Interface representing a scheduled agent task.

This interface defines the core operations for managing and controlling scheduled agent tasks. It provides a clean separation between task scheduling concerns and agent execution logic.

Design Principles:

  • Single Responsibility - Focuses solely on task lifecycle management
  • Interface Segregation - Minimal interface with only essential operations
  • Framework Agnostic - Can be implemented with any scheduling backend

Usage Example:


 // Schedule an agent task
 AgentConfig config = AgentConfig.builder()
     .name("MyAgent")
     .model(myModel)
     .build();

 ScheduleAgentTask task = scheduler.schedule(config, scheduleConfig);

 // Control the task
 String taskId = task.getId();
 String taskName = task.getName();

 // Manually trigger execution
 task.run();

 // Cancel the task
 task.cancel();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancel this scheduled task permanently.
    Get the unique identifier of this scheduled task.
    Get the name of this scheduled task.
    reactor.core.publisher.Mono<T>
    run(io.agentscope.core.message.Msg... msgs)
    Execute the scheduled task immediately.
  • Method Details

    • getId

      String getId()
      Get the unique identifier of this scheduled task.

      The ID is typically generated by the scheduler implementation and remains constant throughout the task's lifecycle. It can be used to uniquely identify and retrieve the task from the scheduler.

      Returns:
      The unique task identifier
    • getName

      String getName()
      Get the name of this scheduled task.

      The name is derived from the agent configuration and is used for human-readable identification. It may not be unique if multiple tasks are created from the same agent configuration.

      Returns:
      The task name
    • run

      reactor.core.publisher.Mono<T> run(io.agentscope.core.message.Msg... msgs)
      Execute the scheduled task immediately.

      This method triggers a manual execution of the task outside of its regular schedule. The execution will:

      • Create a fresh agent instance using the configured AgentConfig
      • Execute the agent's logic with the provided input messages
      • Track execution metrics (execution count, etc.)
      • Return the agent's response as a Mono

      Thread Safety: Implementations should ensure this method is thread-safe and can be called concurrently with scheduled executions.

      Parameters:
      msgs - The input messages to pass to the agent (optional, can be empty)
      Returns:
      A Mono that emits the agent's response message when execution completes
      Throws:
      IllegalStateException - if the task has been cancelled
      RuntimeException - if the execution fails
    • cancel

      void cancel()
      Cancel this scheduled task permanently.

      After cancellation:

      • No further scheduled executions will occur
      • The task will be removed from the scheduler
      • Calling run(Msg...) may throw an IllegalStateException
      • This operation is typically irreversible

      If the task is currently executing, the behavior depends on the scheduler implementation - it may wait for completion or attempt to interrupt execution.

      Calling cancel on an already cancelled task should be idempotent (no-op).