Class: Ralph::PromptTemplate
- Inherits:
-
Object
- Object
- Ralph::PromptTemplate
- Defined in:
- lib/ralph/prompt_template.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
-
#user_prompt ⇒ Object
readonly
Returns the value of attribute user_prompt.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_iteration(state, _agent) ⇒ Object
Build the full iteration prompt sent to the LLM.
- #context_section ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(user_prompt, context: nil, tasks: nil) ⇒ PromptTemplate
constructor
A new instance of PromptTemplate.
- #non_task_mode_prompt(state) ⇒ Object
- #task_mode_prompt(state) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(user_prompt, context: nil, tasks: nil) ⇒ PromptTemplate
Returns a new instance of PromptTemplate.
9 10 11 12 13 |
# File 'lib/ralph/prompt_template.rb', line 9 def initialize(user_prompt, context: nil, tasks: nil) @user_prompt = user_prompt @context = context @tasks = tasks end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/ralph/prompt_template.rb', line 7 def context @context end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
7 8 9 |
# File 'lib/ralph/prompt_template.rb', line 7 def tasks @tasks end |
#user_prompt ⇒ Object (readonly)
Returns the value of attribute user_prompt.
7 8 9 |
# File 'lib/ralph/prompt_template.rb', line 7 def user_prompt @user_prompt end |
Class Method Details
.inject(user_prompt, context:, tasks:) ⇒ Object
178 179 180 |
# File 'lib/ralph/prompt_template.rb', line 178 def inject(user_prompt, context:, tasks:) new(user_prompt, context: context, tasks: tasks) end |
Instance Method Details
#build_iteration(state, _agent) ⇒ Object
Build the full iteration prompt sent to the LLM. state is a Storage::State with iteration metadata. _agent is the agent config (reserved for future use).
97 98 99 100 101 102 103 |
# File 'lib/ralph/prompt_template.rb', line 97 def build_iteration(state, _agent) if state.tasks_mode task_mode_prompt(state) else non_task_mode_prompt(state) end end |
#context_section ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ralph/prompt_template.rb', line 18 def context_section @_context_section ||= if @context.present? " ## Additional Context (added by user mid-loop) #{@context.content} --- " else "" end end |
#empty? ⇒ Boolean
16 |
# File 'lib/ralph/prompt_template.rb', line 16 def empty? = @user_prompt.strip.empty? |
#non_task_mode_prompt(state) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ralph/prompt_template.rb', line 61 def non_task_mode_prompt(state) <<~PROMPT.strip # Ralph Wiggum Loop - Iteration #{state.iteration} You are in an iterative development loop. Work on the task below until you can genuinely complete it. #{context_section} ## Your Task #{@user_prompt} ## Instructions 1. Read the current state of files to understand what's been done 2. Track your progress and plan remaining work 3. Make progress on the task 4. Run tests/verification if applicable 5. When the task is GENUINELY COMPLETE, output: <promise>#{state.completion_promise}</promise> ## Critical Rules - ONLY output <promise>#{state.completion_promise}</promise> when the task is truly done - Do NOT lie or output false promises to exit the loop - If stuck, try a different approach - Check your work before claiming completion - The loop will continue until you succeed ## Current Iteration: #{state.iteration}#{state.max_iterations > 0 ? " / #{state.max_iterations}" : " (unlimited)"} (min: #{state.min_iterations || 1}) Now, work on the task. Good luck! PROMPT end |
#task_mode_prompt(state) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ralph/prompt_template.rb', line 33 def task_mode_prompt(state) tasks_section = build_tasks_section(state) <<~PROMPT.strip # Ralph Wiggum Loop - Iteration #{state.iteration} You are in an iterative development loop working through a task list. #{context_section}#{tasks_section} ## Your Main Goal #{@user_prompt} ## Critical Rules - Work on ONE task at a time from .ralph/ralph-tasks.md - ONLY output <promise>#{state.task_promise}</promise> when the current task is complete and marked in ralph-tasks.md - ONLY output <promise>#{state.completion_promise}</promise> when ALL tasks are truly done - Do NOT lie or output false promises to exit the loop - If stuck, try a different approach - Check your work before claiming completion ## Current Iteration: #{state.iteration}#{state.max_iterations > 0 ? " / #{state.max_iterations}" : " (unlimited)"} (min: #{state.min_iterations || 1}) Tasks Mode: ENABLED - Work on one task at a time from ralph-tasks.md Now, work on the current task. Good luck! PROMPT end |
#to_s ⇒ Object
15 |
# File 'lib/ralph/prompt_template.rb', line 15 def to_s = @user_prompt |