Annotation Interface Lifecycle


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface Lifecycle
Marks a method as a lifecycle callback for agent initialization and cleanup.

Lifecycle methods are called automatically during agent state transitions.

Usage


 public class ResearchAgent extends Agent {

     @Lifecycle(phase = Phase.INIT)
     public void loadResources() {
         // Load configuration, connect to services
     }

     @Lifecycle(phase = Phase.START, order = 1)
     public void connectToDatabase() {
         // Establish database connection
     }

     @Lifecycle(phase = Phase.START, order = 2)
     public void warmupCache() {
         // Populate cache
     }

     @Lifecycle(phase = Phase.STOP)
     public void cleanup() {
         // Release resources
     }

     @Lifecycle(phase = Phase.ERROR)
     public void handleError(Throwable error) {
         // Error recovery logic
     }
 }
 

Lifecycle Phases

  1. INIT - Agent instantiation, configuration loading
  2. START - Agent activation, resource acquisition
  3. PAUSE - Temporary suspension
  4. RESUME - Resume from pause
  5. STOP - Normal shutdown
  6. DESTROY - Final cleanup, resource release
  7. ERROR - Error handling callback
Author:
TnsAI Team
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Agent lifecycle phases.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Lifecycle phase this method handles.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether to run asynchronously.
    Description of what this lifecycle method does.
    int
    Execution order within the same phase.
    boolean
    Whether failure should prevent agent startup.
    int
    Timeout for lifecycle method execution in milliseconds.
  • Element Details

    • phase

      Lifecycle phase this method handles.
      Returns:
      lifecycle phase
    • order

      int order
      Execution order within the same phase.

      Lower values execute first. Default is 100.

      Returns:
      order value
      Default:
      100
    • required

      boolean required
      Whether failure should prevent agent startup.

      Only applies to INIT and START phases.

      Returns:
      true if required for startup
      Default:
      true
    • timeout

      int timeout
      Timeout for lifecycle method execution in milliseconds.

      0 means no timeout.

      Returns:
      timeout in ms
      Default:
      0
    • async

      boolean async
      Whether to run asynchronously.
      Returns:
      true for async execution
      Default:
      false
    • description

      String description
      Description of what this lifecycle method does.
      Returns:
      description
      Default:
      ""