rLLM Data Structures API
Module:
rllm.agents.agent
Reference API for the core rollout and training data structures used across rLLM workflows.
Step
rllm.agents.agent.Step
dataclass
Atomic unit of one model interaction in a rollout.
A step stores token-level fields from the rollout engine (prompt_ids,
response_ids, logprobs) together with execution context and training
signals.
Attributes:
| Name | Type | Description |
|---|---|---|
prompt_ids |
list[int] | list[Any]
|
Input token IDs for this model call. |
response_ids |
list[int]
|
Generated token IDs for this model call. |
logprobs |
list[float]
|
Token-level log probabilities aligned with |
chat_completions |
list[dict[str, str]]
|
Chat message history at this step. |
observation |
Any
|
Environment/workflow observation before generation. |
thought |
str
|
Optional model reasoning text. |
action |
Any
|
Parsed action emitted from the model response. |
model_response |
str
|
Raw response content from the model. |
model_output |
ModelOutput | None
|
Original rollout engine output payload. |
info |
dict
|
Additional per-step metadata. |
reward |
float
|
Step-level reward signal. |
done |
bool
|
Whether this step ends the trajectory. |
mc_return |
float
|
Monte-Carlo return (if computed by workflow logic). |
advantage |
list[float] | float | None
|
Step advantage signal; can be scalar or token-level list. |
Source code in rllm/agents/agent.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
Trajectory
rllm.agents.agent.Trajectory
dataclass
Ordered sequence of steps for one role/agent thread.
A trajectory is the primary container for per-role rollout history and trajectory-level reward.
Attributes:
| Name | Type | Description |
|---|---|---|
uid |
str
|
Unique trajectory identifier. |
name |
str
|
Role/name for grouping and metrics (for example, |
task |
Any
|
Task payload associated with the trajectory. |
steps |
list[Step]
|
Ordered list of step records. |
reward |
float | None
|
Optional trajectory-level reward. |
info |
dict
|
Additional trajectory metadata. |
Source code in rllm/agents/agent.py
from_dict
classmethod
Create Trajectory from dictionary, properly deserializing Step objects.
Source code in rllm/agents/agent.py
is_cumulative
Returns True if for every step after the first, its chat_completions is an exact superset of the previous step's chat_completions (i.e., the previous chat_completions is a prefix).
Source code in rllm/agents/agent.py
Episode
rllm.agents.agent.Episode
dataclass
Workflow-level rollout output containing one or more trajectories.
Episode is the unit returned by Workflow.run(...) and usually represents
one (task_id, rollout_idx) execution.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Rollout identifier, typically |
task |
Any
|
Original task payload. |
termination_reason |
TerminationReason | None
|
Workflow termination status. |
is_correct |
bool
|
Workflow-level correctness flag. |
trajectories |
list[Trajectory]
|
Trajectories generated in this rollout. |
metrics |
dict
|
Workflow-defined episode metrics. |
info |
dict
|
Additional episode metadata. |
Source code in rllm/agents/agent.py
from_dict
classmethod
Create Episode from dictionary, properly deserializing Trajectory objects.
Source code in rllm/agents/agent.py
TrajectoryGroup
rllm.agents.agent.TrajectoryGroup
dataclass
A group of trajectories for advantage computation.
Unlike Episode (which represents raw rollout data), TrajectoryGroup is specifically structured for advantage computation. All trajectories in a group will have their rewards compared to compute advantages (e.g., via GRPO).
Attributes:
| Name | Type | Description |
|---|---|---|
trajectories |
list[Trajectory]
|
List of trajectories to compare for advantage computation |
group_id |
str
|
Optional identifier for the group (e.g., "task1:agent_0") |
metadata |
list[dict]
|
List of metadata for each trajectory in the group |