Class RunExecutionContext

java.lang.Object
io.agentscope.core.training.runner.RunExecutionContext

public class RunExecutionContext extends Object
Run Execution Context

Encapsulates the complete execution information for a single Run.

Core Concepts:

  • Task: Represents a user's original request (business-level unique identifier)
  • Run: A specific execution of the same Task (experiment/training level)
  • RunExecutionContext: Encapsulates the execution context for one Run

Relationship Example:

 Task "task-001" (User asks: "What's the weather today?")
   ├─ Run "0" → RunExecutionContext (msgIds=[msg-1, msg-2], msgs=[...], reward=0.8)
   ├─ Run "1" → RunExecutionContext (msgIds=[msg-3, msg-4], msgs=[...], reward=0.9)
   └─ Run "2" → RunExecutionContext (msgIds=[msg-5, msg-6], msgs=[...], reward=0.85)
 

Data Contents:

  • Task ID: Unique identifier for user request
  • Run ID: The Nth execution of this Task (incrementing from "0")
  • msg_ids: All message IDs from LLM interactions in this Run (returned from Trinity API)
  • msgs: All messages from Agent memory in this Run (raw data for reward calculation)
  • Timing info: Start time and duration of this Run

Lifecycle:

 1. TrainingRouter creates RunExecutionContext (corresponds to one Run)
 2. Passed to TrinityModelAdapter (automatically collects msg_ids)
 3. Shadow Agent execution completes, all data collected
 4. TrainingRouter calculates reward
 5. TrainingRouter submits Feedback using (taskId, runId, msg_ids, reward)
 6. Registered to TaskExecutionRegistry (optional, for later queries)
 

Thread Safety:

  • Uses CopyOnWriteArrayList to store msg_ids
  • Supports concurrent additions (although currently executed synchronously)
See Also:
  • Method Details

    • create

      public static RunExecutionContext create(String taskId, String runId)
      Create new Run execution context

      Usage scenario: Created by TrainingRouter after intercepting Agent call.

      Parameters:
      taskId - Task ID
      runId - Run ID
      Returns:
      Run execution context instance
      Throws:
      IllegalArgumentException - if taskId or runId is null/empty
    • addMsgId

      public void addMsgId(String msgId)
      Add Message ID

      Message ID is extracted from Trinity Chat API response (response.getId()).

      Thread-safe: This method can be called concurrently.

      Parameters:
      msgId - Message ID (ignored if null or empty)
    • getMsgIds

      public List<String> getMsgIds()
      Get all Message IDs

      Return value: Returns a new List copy to prevent external modification.

      Returns:
      Message IDs list (unmodifiable)
    • getMsgIdCount

      public int getMsgIdCount()
      Get Message IDs count
      Returns:
      Number of msg_ids
    • getTaskId

      public String getTaskId()
      Get Task ID
      Returns:
      Task ID
    • getRunId

      public String getRunId()
      Get Run ID
      Returns:
      Run ID
    • getStartTime

      public long getStartTime()
      Get Run start time
      Returns:
      Start time (millisecond timestamp)
    • getDuration

      public long getDuration()
      Get Run execution duration
      Returns:
      Execution duration (milliseconds)
    • hasMsgIds

      public boolean hasMsgIds()
      Check if msg_ids have been collected
      Returns:
      true if at least one msg_id exists
    • addMsg

      public void addMsg(io.agentscope.core.message.Msg msg)
      Add Message

      Thread-safe: This method can be called concurrently.

      Parameters:
      msg - Message (ignored if null)
    • setMessages

      public void setMessages(List<io.agentscope.core.message.Msg> messages)
      Batch set Messages (usually obtained from agent memory)

      Clears existing messages and adds new message list.

      Thread-safe: This method can be called concurrently.

      Parameters:
      messages - Message list (clears existing messages if null or empty)
    • getMessages

      public List<io.agentscope.core.message.Msg> getMessages()
      Get all Messages

      Return value: Returns a new List copy to prevent external modification.

      Returns:
      Messages list (unmodifiable)
    • getMessageCount

      public int getMessageCount()
      Get Messages count
      Returns:
      Number of msgs
    • hasMessages

      public boolean hasMessages()
      Check if messages have been collected
      Returns:
      true if at least one message exists
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object