Module: Phronomy::Runnable
- Included in:
- Agent::Base, OutputParser::Base, PromptTemplate, Workflow, WorkflowRunner
- 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.
When +trace_pii+ is disabled, both the input and the output (LLM response, tool result) are replaced with the literal string "[REDACTED]" before being forwarded to the tracing backend. The actual result is still returned to the caller — only the copy sent to the tracer is redacted.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/phronomy/runnable.rb', line 36 def trace(name, input: nil, **, &block) traced_input = Phronomy.configuration.trace_pii ? input : "[REDACTED]" if Phronomy.configuration.trace_pii # PII recording is allowed: pass through unchanged. Phronomy.configuration.tracer.trace(name, input: traced_input, **, &block) else # Redact both input (above) and output before forwarding to the tracer. # Capture the real result so callers receive the unredacted value. real_result = nil Phronomy.configuration.tracer.trace(name, input: traced_input, **) do |span| real_result, usage = block.call(span) ["[REDACTED]", usage] end real_result end end |