Module: PWN::AI::Agent::Reflect

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

Overview

PWN::AI::Agent::Reflect is the inward-facing counterpart to PWN::AI::Agent::Extrospection. Where Extrospection looks OUTWARD at the world the agent operates in (host state, toolchain, network, threat-intel), Reflect looks INWARD - it lets pwn hand a request to the active AI engine and reflect on its own artifacts, transcripts, findings, code, or decisions.

This module is gated by PWN::Env[:ai][:module_reflection] so that potentially-sensitive local data is never shipped to a remote LLM unless the operator has explicitly opted in via pwn-vault / config.

It is the single choke-point every PWN::AI::Agent::* domain agent (Assembly, BurpSuite, GQRX, HackerOne, SAST, VulnGen, ...) routes through when it wants an LLM opinion on locally-produced data, and it is also what PWN::AI::Agent::Learning.reflect uses to distill session transcripts into durable PWN::Memory lessons.

TEACHER-STUDENT REFLECTION

When PWN::Env[:reflect_engine] (or opts) names a different provider than :active, Reflect.on temporarily flips :active for the duration of the introspection call. This lets a local Ollama model EXECUTE the task while a frontier model WRITES the durable lessons about it — the local model then reads back distilled reasoning it could never have produced itself.

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. support@0dayinc.com



98
99
100
101
102
# File 'lib/pwn/ai/agent/reflect.rb', line 98

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

.helpObject

Display Usage for this Module



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pwn/ai/agent/reflect.rb', line 106

public_class_method def self.help
  puts "USAGE:
    #{self}.on(
      request: 'required - String - What you want the AI to reflect on',
      system_role_content: 'optional - context to set up the model behavior for reflection',
      engine: 'optional - override engine (Symbol) for teacher-student reflection; defaults to PWN::Env[:ai][:reflect_engine]',
      spinner: 'optional - Boolean - Display spinner during operation (default: false)',
      suppress_pii_warning: 'optional - Boolean - Suppress PII Warnings (default: false)'
    )

    Teacher-student config:
      PWN::Env[:ai][:reflect_engine] = :anthropic   # execute on :active, critique on :anthropic

    #{self}.authors
  "
end

.on(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::AI::Agent::Reflect.on( request: 'required - String - What you want the AI to reflect on', system_role_content: 'optional - context to set up the model behavior for reflection', engine: 'optional - override engine for THIS reflection only (Symbol/String); defaults to PWN::Env[:reflect_engine] || :active', spinner: 'optional - Boolean - Display spinner during operation (default: false)', suppress_pii_warning: 'optional - Boolean - Suppress PII Warnings (default: false)' )



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pwn/ai/agent/reflect.rb', line 43

public_class_method def self.on(opts = {})
  request = opts[:request]
  raise 'ERROR: request must be provided' if request.nil?

  system_role_content = opts[:system_role_content]

  spinner = opts[:spinner] || false

  suppress_pii_warning = opts[:suppress_pii_warning] || false

  response = nil

  ai_module_reflection = PWN::Env[:ai][:module_reflection]

  if ai_module_reflection && request.length.positive?
    override = opts[:engine] || PWN::Env.dig(:ai, :reflect_engine)
    engine   = (override || PWN::Env[:ai][:active]).to_s.downcase.to_sym
    valid_ai_engines = PWN::AI.help.reject { |e| e.downcase == :agent }.map(&:downcase)
    raise "ERROR: Unsupported AI engine. Supported engines are: #{valid_ai_engines}" unless valid_ai_engines.include?(engine)

    warn "AI Reflection is enabled.  Ensure #{engine} has been authorized for use and/or requests are sanitized properly." unless suppress_pii_warning
    response = with_engine(engine: override) do
      PWN::AI::Agent::Loop.run(
        request: request.chomp,
        system_role_content: system_role_content,
        enabled_toolsets: [],
        spinner: spinner
      )
    end
  end

  response
rescue StandardError => e
  raise e
end