Module: PWN::AI::Agent::PromptBuilder

Defined in:
lib/pwn/ai/agent/prompt_builder.rb

Overview

Assembles the system prompt for every Loop.run invocation from durable on-disk state: PWN::Env persona, host environment probe, PWN::Memory facts, and PWN::Skills index.

Re-injection IS the persistence mechanism: this is rebuilt fresh on every user turn, so a memory_remember / skill_create from the prior turn shows up here with no extra wiring.

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <support@0dayinc.com>



85
86
87
# File 'lib/pwn/ai/agent/prompt_builder.rb', line 85

public_class_method def self.authors
  "AUTHOR(S):\n  0day Inc. <support@0dayinc.com>\n"
end

.build(opts = {}) ⇒ Object

Supported Method Parameters

system_prompt = PWN::AI::Agent::PromptBuilder.build(

session_id: 'optional - PWN::Sessions id to embed in the ENV block'

)



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pwn/ai/agent/prompt_builder.rb', line 19

public_class_method def self.build(opts = {})
  session_id = opts[:session_id]
  engine = active_engine
  base   = (PWN::Env.dig(:ai, engine, :system_role_content) if defined?(PWN::Env)) ||
           'You are an offensive-security AI named Sonny operating inside the pwn REPL.'

  <<~SYS.rstrip
    #{base}

    ENVIRONMENT
      host       : #{host_line}
      cwd        : #{Dir.pwd}
      ruby       : #{RUBY_VERSION}
      pwn        : #{pwn_version}
      session_id : #{session_id || '(none)'}

    #{memory_block}#{skills_block}TOOL USE
      Use the provided function tools to act on the host. A reply with
      no tool_calls is treated as your FINAL answer to the user.
      Prefer `pwn_eval` for anything in the PWN:: namespace and `shell`
      for OS commands. Save durable facts with `memory_remember`.
  SYS
end

.helpObject

Display Usage for this Module



91
92
93
94
95
96
97
98
# File 'lib/pwn/ai/agent/prompt_builder.rb', line 91

public_class_method def self.help
  puts <<~USAGE
    USAGE:
      system_prompt = PWN::AI::Agent::PromptBuilder.build(session_id: 'abc')

      #{self}.authors
  USAGE
end