Module: ComposableAgents::PromptRenderingStrategy::Markdown
- Included in:
- MarkdownHeavy
- Defined in:
- lib/composable_agents/prompt_rendering_strategy/markdown.rb
Overview
Render prompt as Markdown documents
Internal collapse
-
#artifact_ref(artifact_name) ⇒ String
Get the artifact reference name communicated to the assistant.
-
#missing_output_user_instructions(missing_output_artifacts) ⇒ Object
Get user instructions for missing output artifacts.
-
#render_instruction_ordered_list(instruction) ⇒ String
Render an instruction of type ordered_list.
-
#render_instruction_text(instruction) ⇒ String
Render an instruction of type text.
-
#render_instructions_list(instructions) ⇒ String
Render a list of rendered instructions.
-
#render_system_prompt(rendered_instructions) ⇒ String
Render the system prompt.
-
#render_user_prompt(rendered_instructions, input_artifacts:) ⇒ String
Render the user prompt The following instance variables are accessible to render the prompt: -
@role-@objective-@constraints.
Instance Method Details
#artifact_ref(artifact_name) ⇒ String
Get the artifact reference name communicated to the assistant
83 84 85 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 83 def artifact_ref(artifact_name) artifact_name.to_s end |
#missing_output_user_instructions(missing_output_artifacts) ⇒ Object
Get user instructions for missing output artifacts
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 94 def missing_output_user_instructions(missing_output_artifacts) <<~EO_PROMPT Some artifacts are missing: #{ ( missing_output_artifacts.map do |artifact_name, missing_info| "- You must create an artifact named `#{artifact_name}`: #{missing_info[:description]}" end ).join("\n") } EO_PROMPT end |
#render_instruction_ordered_list(instruction) ⇒ String
Render an instruction of type ordered_list
20 21 22 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 20 def render_instruction_ordered_list(instruction) instruction.map.with_index { |step, step_idx| "# #{step_idx + 1}. #{step}" }.join("\n\n") end |
#render_instruction_text(instruction) ⇒ String
Render an instruction of type text
12 13 14 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 12 def render_instruction_text(instruction) instruction end |
#render_instructions_list(instructions) ⇒ String
Render a list of rendered instructions
28 29 30 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 28 def render_instructions_list(instructions) instructions.map { |instruction| Utils::Markdown.align_markdown_headers(instruction, level: 1).strip }.join("\n\n") end |
#render_system_prompt(rendered_instructions) ⇒ String
Render the system prompt. The following instance variables are accessible to render the prompt:
@input_artifacts@role@objective@constraints
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 41 def render_system_prompt(rendered_instructions) sections = [] sections << <<~EO_SECTION if @role && !@role.empty? # Role #{Utils::Markdown.align_markdown_headers(@role, level: 2).strip} EO_SECTION sections << <<~EO_SECTION if @objective && !@objective.empty? # Objective #{Utils::Markdown.align_markdown_headers(@objective, level: 2).strip} EO_SECTION sections << <<~EO_SECTION if rendered_instructions && !rendered_instructions.empty? # Instructions #{Utils::Markdown.align_markdown_headers(rendered_instructions, level: 2).strip} EO_SECTION sections << <<~EO_SECTION if @constraints && !@constraints.empty? # Constraints #{Utils::Markdown.align_markdown_headers(@constraints, level: 2).strip} EO_SECTION sections.map(&:strip).join("\n\n") end |
#render_user_prompt(rendered_instructions, input_artifacts:) ⇒ String
Render the user prompt The following instance variables are accessible to render the prompt:
@role@objective@constraints
75 76 77 |
# File 'lib/composable_agents/prompt_rendering_strategy/markdown.rb', line 75 def render_user_prompt(rendered_instructions, input_artifacts:) rendered_instructions || '' end |