Class RunExecutionContext
java.lang.Object
io.agentscope.core.training.runner.RunExecutionContext
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
CopyOnWriteArrayListto store msg_ids - Supports concurrent additions (although currently executed synchronously)
- See Also:
-
Automatically generates Task IDManages multiple Runs for the same TaskStores execution contexts for all Runs
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddMsg(io.agentscope.core.message.Msg msg) Add MessagevoidAdd Message IDstatic RunExecutionContextCreate new Run execution contextbooleanlongGet Run execution durationintGet Messages countList<io.agentscope.core.message.Msg>Get all MessagesintGet Message IDs countGet all Message IDsgetRunId()Get Run IDlongGet Run start timeGet Task IDinthashCode()booleanCheck if messages have been collectedbooleanCheck if msg_ids have been collectedvoidsetMessages(List<io.agentscope.core.message.Msg> messages) Batch set Messages (usually obtained from agent memory)toString()
-
Method Details
-
create
Create new Run execution contextUsage scenario: Created by TrainingRouter after intercepting Agent call.
- Parameters:
taskId- Task IDrunId- Run ID- Returns:
- Run execution context instance
- Throws:
IllegalArgumentException- if taskId or runId is null/empty
-
addMsgId
Add Message IDMessage 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
Get all Message IDsReturn 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
Get Task ID- Returns:
- Task ID
-
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 MessageThread-safe: This method can be called concurrently.
- Parameters:
msg- Message (ignored if null)
-
setMessages
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
Get all MessagesReturn 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
-
equals
-
hashCode
public int hashCode()
-