Class: Phronomy::KnowledgeSource::StaticKnowledge

Inherits:
Base
  • Object
show all
Defined in:
lib/phronomy/knowledge_source/static_knowledge.rb

Overview

A KnowledgeSource backed by fixed text provided at construction time.

Useful for injecting static documents, policy files, or configuration knowledge that does not change per request.

Examples:

ks = Phronomy::KnowledgeSource::StaticKnowledge.new(
  "Our refund policy: ...",
  type: :policy
)
agent.invoke("What is the refund policy?", config: { knowledge_sources: [ks] })

Instance Method Summary collapse

Constructor Details

#initialize(text, type: :static, source: nil) ⇒ StaticKnowledge

Returns a new instance of StaticKnowledge.

Parameters:

  • text (String)

    the static knowledge text to inject

  • type (Symbol) (defaults to: :static)

    semantic tag for the chunk (default :static)

  • source (String, nil) (defaults to: nil)

    label identifying where this knowledge came from (e.g. a filename). Included in the context XML tag and exposed to the LLM so that agents can produce grounded citations.



22
23
24
25
26
# File 'lib/phronomy/knowledge_source/static_knowledge.rb', line 22

def initialize(text, type: :static, source: nil)
  @text = text.to_s
  @type = type
  @source = source
end

Instance Method Details

#fetch(query: nil) ⇒ Array<Hash>

Returns the fixed text as a single chunk, regardless of query.

Parameters:

  • query (String, nil) (defaults to: nil)

    ignored for static knowledge

Returns:

  • (Array<Hash>)


32
33
34
35
36
37
38
# File 'lib/phronomy/knowledge_source/static_knowledge.rb', line 32

def fetch(query: nil)
  return [] if @text.empty?

  chunk = {content: @text, type: @type}
  chunk[:source] = @source if @source
  [chunk]
end

#static?true

Static knowledge content never changes between invocations.

Returns:

  • (true)


42
43
44
# File 'lib/phronomy/knowledge_source/static_knowledge.rb', line 42

def static?
  true
end