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

Instance Method Details

#artifact_ref(artifact_name) ⇒ String

Get the artifact reference name communicated to the assistant

Parameters:

  • artifact_name (Symbol)

    The artifact name

Returns:

  • (String)

    The artifact reference name used for 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

Parameters:

  • missing_output_artifacts (Hash{Symbol => Object})

    The missing output artifacts information, per artifact name Information can contain the following attributes:

    • description [String] The artifact's description.
    • error [String, nil] An error message related to this missing artifact.

Returns:

  • (Object)

    The user instructions (see Instructions#initialize)



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)
  "    Some artifacts are missing:\n    \#{\n      (\n        missing_output_artifacts.map do |artifact_name, missing_info|\n          \"- You must create an artifact named `\#{artifact_name}`: \#{missing_info[:description]}\"\n        end\n      ).join(\"\\n\")\n    }\n  EO_PROMPT\nend\n"

#render_instruction_ordered_list(instruction) ⇒ String

Render an instruction of type ordered_list

Parameters:

  • instruction (Array<String>)

    The instruction to render

Returns:

  • (String)

    The rendered instruction



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

Parameters:

  • instruction (String)

    The instruction to render

Returns:

  • (String)

    The rendered instruction



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

Parameters:

  • instructions (Array<String>)

    The instructions list to render

Returns:

  • (String)

    The rendered instructions list



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

Parameters:

  • rendered_instructions (String, nil)

    The rendered system instructions, or nil if none

Returns:

  • (String)

    The rendered system prompt



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 << "    # Role\n\n    \#{Utils::Markdown.align_markdown_headers(@role, level: 2).strip}\n  EO_SECTION\n  sections << <<~EO_SECTION if @objective && [email protected]?\n    # Objective\n\n    \#{Utils::Markdown.align_markdown_headers(@objective, level: 2).strip}\n  EO_SECTION\n  sections << <<~EO_SECTION if rendered_instructions && !rendered_instructions.empty?\n    # Instructions\n\n    \#{Utils::Markdown.align_markdown_headers(rendered_instructions, level: 2).strip}\n  EO_SECTION\n  sections << <<~EO_SECTION if @constraints && [email protected]?\n    # Constraints\n\n    \#{Utils::Markdown.align_markdown_headers(@constraints, level: 2).strip}\n  EO_SECTION\n  sections.map(&:strip).join(\"\\n\\n\")\nend\n" if @role && !@role.empty?

#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

Parameters:

  • rendered_instructions (String, nil)

    The rendered instructions, or nil if none

  • input_artifacts (Hash{Symbol => Object})

    The input artifacts content for which we render this prompt, per artifact name

Returns:

  • (String)

    The rendered user prompt



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