Class: SwarmSDK::Agent::SystemPromptBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/agent/system_prompt_builder.rb

Overview

Builds system prompts for agents

This class encapsulates all system prompt construction logic, including:

  • Base system prompt rendering (for coding agents)
  • Non-coding base prompt rendering
  • Plugin prompt contribution collection
  • Combining base and custom prompts

Safety Note for SwarmMemory Integration

This is an INTERNAL helper that receives Definition attributes as input. Definition remains the single source of truth with all instance variables. SwarmMemory uses agent_definition.instance_eval { binding } for ERB templating, which requires all properties to be on Definition object. This helper is safe because it doesn't affect Definition's structure - it only extracts logic.

Constant Summary collapse

BASE_SYSTEM_PROMPT_PATH =
File.expand_path("../prompts/base_system_prompt.md.erb", __dir__)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_prompt:, coding_agent:, disable_default_tools:, directory:, definition:) ⇒ SystemPromptBuilder

Returns a new instance of SystemPromptBuilder.



43
44
45
46
47
48
49
# File 'lib/swarm_sdk/agent/system_prompt_builder.rb', line 43

def initialize(custom_prompt:, coding_agent:, disable_default_tools:, directory:, definition:)
  @custom_prompt = custom_prompt
  @coding_agent = coding_agent
  @disable_default_tools = disable_default_tools
  @directory = directory
  @definition = definition
end

Class Method Details

.build(custom_prompt:, coding_agent:, disable_default_tools:, directory:, definition:) ⇒ String

Build the complete system prompt for an agent

Parameters:

  • custom_prompt (String, nil)

    Custom system prompt from configuration

  • coding_agent (Boolean)

    Whether agent is configured for coding tasks

  • disable_default_tools (Boolean, Array, nil)

    Default tools disable configuration

  • directory (String)

    Agent's working directory

  • definition (Definition)

    Full definition for plugin contributions

Returns:

  • (String)

    Complete system prompt



32
33
34
35
36
37
38
39
40
# File 'lib/swarm_sdk/agent/system_prompt_builder.rb', line 32

def build(custom_prompt:, coding_agent:, disable_default_tools:, directory:, definition:)
  new(
    custom_prompt: custom_prompt,
    coding_agent: coding_agent,
    disable_default_tools: disable_default_tools,
    directory: directory,
    definition: definition,
  ).build
end

Instance Method Details

#buildObject



51
52
53
54
55
# File 'lib/swarm_sdk/agent/system_prompt_builder.rb', line 51

def build
  prompt = base_prompt_section
  prompt = append_plugin_contributions(prompt)
  prompt
end