Module: Phronomy::Runnable
- Included in:
- Agent::Base, Graph::CompiledGraph, OutputParser::Base, PromptTemplate
- Defined in:
- lib/phronomy/runnable.rb
Overview
Base interface for executable graph components. Provides invoke / stream / batch.
Instance Method Summary collapse
-
#batch(inputs, config: {}) ⇒ Object
Batch execution.
-
#invoke(input, config: {}) ⇒ Object
Synchronous execution.
-
#stream(input, config: {}) {|result| ... } ⇒ Object
Streaming execution.
-
#trace(name, input: nil, **meta, &block) ⇒ Object
Convenience wrapper that delegates to the global tracer.
Instance Method Details
#batch(inputs, config: {}) ⇒ Object
Batch execution. Default calls invoke sequentially.
20 21 22 |
# File 'lib/phronomy/runnable.rb', line 20 def batch(inputs, config: {}) inputs.map { |input| invoke(input, config: config) } end |
#invoke(input, config: {}) ⇒ Object
Synchronous execution. Must be overridden in subclasses.
8 9 10 |
# File 'lib/phronomy/runnable.rb', line 8 def invoke(input, config: {}) raise NotImplementedError, "#{self.class}#invoke is not implemented" end |
#stream(input, config: {}) {|result| ... } ⇒ Object
Streaming execution. Default yields the invoke result as a single chunk.
13 14 15 16 17 |
# File 'lib/phronomy/runnable.rb', line 13 def stream(input, config: {}, &block) result = invoke(input, config: config) yield result if block result end |
#trace(name, input: nil, **meta, &block) ⇒ Object
Convenience wrapper that delegates to the global tracer. Yields a span; the block must return [result, usage] where usage is a Phronomy::TokenUsage or nil. Returns only the result value.
30 31 32 33 34 35 |
# File 'lib/phronomy/runnable.rb', line 30 def trace(name, input: nil, **, &block) # Redact user input from spans when trace_pii is disabled to prevent # accidental PII transmission to external tracing backends. traced_input = Phronomy.configuration.trace_pii ? input : "[REDACTED]" Phronomy.configuration.tracer.trace(name, input: traced_input, **, &block) end |