pub struct ReActStep {
pub thought: String,
pub action: String,
pub observation: String,
pub step_duration_ms: u64,
}Expand description
A single ReAct step: Thought → Action → Observation.
Fields§
§thought: StringAgent’s reasoning about the current state.
action: StringThe action taken (tool name + JSON arguments, or “FINAL_ANSWER”).
observation: StringThe result of the action.
step_duration_ms: u64Wall-clock duration of this individual step in milliseconds. Covers the time from the start of the inference call to the end of the tool invocation (or FINAL_ANSWER detection). Zero for steps that were constructed outside the loop (e.g., in tests).
Implementations§
Source§impl ReActStep
impl ReActStep
Sourcepub fn new(
thought: impl Into<String>,
action: impl Into<String>,
observation: impl Into<String>,
) -> Self
pub fn new( thought: impl Into<String>, action: impl Into<String>, observation: impl Into<String>, ) -> Self
Construct a step with zero step_duration_ms.
Primarily useful in tests that need to build [AgentSession] values
without running the full ReAct loop.
Sourcepub fn is_final_answer(&self) -> bool
pub fn is_final_answer(&self) -> bool
Returns true if this step’s action is a FINAL_ANSWER.
Sourcepub fn is_tool_call(&self) -> bool
pub fn is_tool_call(&self) -> bool
Returns true if this step’s action is a tool call (not a FINAL_ANSWER).
Sourcepub fn with_duration(self, ms: u64) -> Self
pub fn with_duration(self, ms: u64) -> Self
Set the step_duration_ms field, returning self for chaining.
Useful in tests and benchmarks that need to build AgentSession values
with realistic timings without running the full ReAct loop.
Sourcepub fn observation_is_empty(&self) -> bool
pub fn observation_is_empty(&self) -> bool
Return true if the observation string is empty.
Useful for identifying steps where the tool produced no output.
Sourcepub fn thought_word_count(&self) -> usize
pub fn thought_word_count(&self) -> usize
Return the approximate number of whitespace-separated words in the thought string.
Returns 0 for steps with an empty thought.
Sourcepub fn observation_word_count(&self) -> usize
pub fn observation_word_count(&self) -> usize
Return the number of whitespace-delimited words in the observation string.
Returns 0 for empty or whitespace-only observations.
Sourcepub fn thought_is_empty(&self) -> bool
pub fn thought_is_empty(&self) -> bool
Return true if the thought string is empty or whitespace-only.
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Return a concise single-line summary of this step.
Format: "[{kind}] thought={thought_preview} action={action_preview} obs={obs_preview}"
where each preview is at most 40 bytes, truncated with … if longer.
{kind} is "FINAL" for a final-answer step and "TOOL" otherwise.
Intended for logging and debugging — not a stable serialization format.
Sourcepub fn combined_byte_length(&self) -> usize
pub fn combined_byte_length(&self) -> usize
Return the total byte length of thought, action, and observation
combined.
Useful for estimating token cost or bounding memory usage per step.
Sourcepub fn action_is_empty(&self) -> bool
pub fn action_is_empty(&self) -> bool
Return true if the action string is empty or whitespace-only.
Sourcepub fn total_word_count(&self) -> usize
pub fn total_word_count(&self) -> usize
Return the total number of words across thought, action, and
observation, counted by whitespace splitting.
Useful for estimating the token cost of a complete ReAct step.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Return true if all three fields — thought, action, and
observation — are non-empty.
A “complete” step is one where the model has produced a thought, taken an action, and received an observation. Incomplete steps (missing any field) typically indicate a parsing failure or an in-progress cycle.
Sourcepub fn observation_starts_with(&self, prefix: &str) -> bool
pub fn observation_starts_with(&self, prefix: &str) -> bool
Return true if the observation field starts with the given prefix.
Useful for quick pattern checks on the model’s last observation without allocating a new string.
Sourcepub fn action_word_count(&self) -> usize
pub fn action_word_count(&self) -> usize
Return the number of whitespace-delimited words in the action field.
Returns 0 for an empty action.
Sourcepub fn thought_byte_len(&self) -> usize
pub fn thought_byte_len(&self) -> usize
Return the number of bytes in the thought field (UTF-8 encoded length).
Sourcepub fn action_byte_len(&self) -> usize
pub fn action_byte_len(&self) -> usize
Return the number of bytes in the action field (UTF-8 encoded length).
Sourcepub fn has_empty_fields(&self) -> bool
pub fn has_empty_fields(&self) -> bool
Return true if any of thought, action, or observation is empty.
Useful for detecting incomplete or partially-populated steps before processing them further.
Sourcepub fn observation_byte_len(&self) -> usize
pub fn observation_byte_len(&self) -> usize
Return the number of bytes in the observation field (UTF-8 encoded length).
Sourcepub fn all_fields_have_words(&self) -> bool
pub fn all_fields_have_words(&self) -> bool
Return true if all three fields (thought, action, observation)
each contain at least one whitespace-delimited word.