#12Which ReAct step are we on?Easy

Which ReAct step are we on?

Background

ReAct's "memory" is just the growing messages list. The agent (and the mock LLM) figure out which step they're on by counting the observations appended so far — each is a user message whose content starts with "OBSERVATION:".

step = len([m for m in messages
            if m["role"] == "user" and m["content"].startswith("OBSERVATION:")])

Problem statement

Implement count_observations(messages) returning the number of observation messages.

Input

  • messages — list of {"role", "content"} dicts.

Output

Returns an int: how many user messages start with "OBSERVATION:".

Examples

Example 1

Input:  [
          {"role": "system", "content": "..."},
          {"role": "user", "content": "Compare X and Y"},
          {"role": "assistant", "content": "SEARCH: X"},
          {"role": "user", "content": "OBSERVATION:\n- X is ..."},
        ]
Output: 1

Constraints

  • Count only role == "user" messages whose content starts with "OBSERVATION:".
  • The original user query (no OBSERVATION: prefix) does not count.

Notes

  • This count is the step number — no separate counter needed. The conversation history is the state.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Reference example: one observation
  • Sample: two observations across steps
  • Example: three observations