Class: Phronomy::Agent::Context::Knowledge::StaticKnowledge

Inherits:
Base
  • Object
show all
Defined in:
lib/phronomy/agent/context/knowledge/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::Agent::Context::Knowledge::StaticKnowledge.new(
  "Our refund policy: ...",
  type: :policy
)
agent = MyAgent.new
agent.add_knowledge_source(ks)
agent.invoke("What is the refund policy?")

Instance Method Summary collapse

Methods inherited from Base

#fetch_async

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.



27
28
29
30
31
# File 'lib/phronomy/agent/context/knowledge/static_knowledge.rb', line 27

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

Instance Method Details

#fetch(query: nil, cancellation_token: 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

  • cancellation_token (Phronomy::Concurrency::CancellationToken, nil) (defaults to: nil)

    optional; raises CancellationError when cancelled

Returns:

  • (Array<Hash>)


39
40
41
42
43
44
45
46
# File 'lib/phronomy/agent/context/knowledge/static_knowledge.rb', line 39

def fetch(query: nil, cancellation_token: nil)
  cancellation_token&.raise_if_cancelled!
  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)


51
52
53
# File 'lib/phronomy/agent/context/knowledge/static_knowledge.rb', line 51

def static?
  true
end