Class: Raif::Agents::ReActAgent

Inherits:
Raif::Agent show all
Defined in:
app/models/raif/agents/re_act_agent.rb

Instance Attribute Summary

Attributes inherited from Raif::Agent

#on_conversation_history_entry

Instance Method Summary collapse

Methods inherited from Raif::Agent

#run!

Methods included from Concerns::HasAvailableModelTools

#available_model_tools_map

Methods included from Concerns::HasRequestedLanguage

#requested_language_name, #system_prompt_language_preference

Methods included from Concerns::HasLlm

#default_llm_model_key, #llm

Methods inherited from Raif::ApplicationRecord

table_name_prefix

Instance Method Details

#build_system_promptObject



13
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
# File 'app/models/raif/agents/re_act_agent.rb', line 13

def build_system_prompt
  <<~PROMPT.strip
    You are an intelligent assistant that follows the ReAct (Reasoning + Acting) framework to complete tasks step by step using tool calls.

    # Available Tools
    You have access to the following tools:
    #{available_model_tools_map.values.map(&:description_for_llm).join("\n---\n")}
    # Your Responses
    Your responses should follow this structure & format:
    <thought>Your step-by-step reasoning about what to do</thought>
    <action>JSON object with "tool" and "arguments" keys</action>
    <observation>Results from the tool, which will be provided to you</observation>
    ... (repeat Thought/Action/Observation as needed until the task is complete)
    <thought>Final reasoning based on all observations</thought>
    <answer>Your final response to the user</answer>

    # How to Use Tools
    When you need to use a tool:
    1. Identify which tool is appropriate for the task
    2. Format your tool call using JSON with the required arguments and place it in the <action> tag
    3. Here is an example: <action>{"tool": "tool_name", "arguments": {...}}</action>

    # Guidelines
    - Always think step by step
    - Use tools when appropriate, but don't use tools for tasks you can handle directly
    - Be concise in your reasoning but thorough in your analysis
    - If a tool returns an error, try to understand why and adjust your approach
    - If you're unsure about something, explain your uncertainty, but do not make things up
    - After each thought, make sure to also include an <action> or <answer>
    - Always provide a final answer that directly addresses the user's request

    Remember: Your goal is to be helpful, accurate, and efficient in solving the user's request.#{system_prompt_language_preference}
  PROMPT
end