Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-225

ReAct Step Parse

Problem

Parse a ReAct step from text line by line. Lines starting with 'Thought:', 'Action:', and 'Action Input:' populate the corresponding keys, and later lines overwrite earlier ones.

Return a dictionary with keys thought, action, and action_input, each defaulting to an empty string.

Hint

splitlines avoids needing escape characters, and the last matching line wins.

Test cases

case 1
in: ["Thought: need info\nAction: search\nAction Input: cats"]
expected: {"thought":"need info","action":"search","action_input":"cats"}
case 2
in: ["Action: finish"]
expected: {"thought":"","action":"finish","action_input":""}
case 3
in: [""]
expected: {"thought":"","action":"","action_input":""}
case 4
in: ["Thought: a\nThought: b"]
expected: {"thought":"b","action":"","action_input":""}
Starter codePython
def react_step_parse(text):
    # Your code here
    pass

4 test cases · run your code against them in the editor