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::AgentInferenceStats

#total_completion_tokens, #total_cost, #total_output_token_cost, #total_prompt_token_cost, #total_prompt_tokens, #total_tokens_sum

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/raif/agents/re_act_agent.rb', line 46

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