reActStrategy

fun reActStrategy(reasoningInterval: Int = 1, name: String = "re_act"): AIAgentStrategy<String, String>(source)

Creates a ReAct AI agent strategy that alternates between reasoning and execution stages to dynamically process tasks and request outputs from an LLM.

Return

An instance of AIAgentStrategy that defines the ReAct strategy.

+-------+ +---------------+ +---------------+ +--------+ | Start | ----------> | CallLLMReason | ----------> | CallLLMAction | ----------> | Finish | +-------+ +---------------+ +---------------+ +--------+ ^ | Finished? Yes | | No | v +-----------------------+ | ExecuteTool | +-----------------------+

Example execution flow of a banking agent with ReAct strategy:

  1. Start: User asks "How much did I spend last month?"

  2. Reasoning Phase: CallLLMReason: "I need to follow these steps:

    1. Get all transactions from last month

    2. Filter out deposits (positive amounts)

    3. Calculate total spending"

  3. Action & Execution Phase 1: CallLLMAction: {tool: "get_transactions", args: {startDate: "2025-05-19", endDate: "2025-06-18"}} ExecuteTool Result: {date: "2025-05-25", amount: -100.00, description: "Grocery Store"}, {date: "2025-05-31", amount: +1000.00, description: "Salary Deposit"}, {date: "2025-06-10", amount: -500.00, description: "Rent Payment"}, {date: "2025-06-13", amount: -200.00, description: "Utilities"}

  4. Reasoning Phase: CallLLMReason: "I have the transactions. Now I need to:

    1. Remove the salary deposit of +1000.00

    2. Sum up the remaining transactions"

  5. Action & Execution Phase 2: CallLLMAction: {tool: "calculate_sum", args: {amounts: -100.00, -500.00, -200.00}} ExecuteTool Result: -800.00

  6. Final Response: Assistant: "You spent $800.00 last month on groceries, rent, and utilities."

  7. Finish: Execution complete

Parameters

reasoningInterval

Specifies the interval for reasoning steps.