Module: RubyPi::Context::Transform
- Defined in:
- lib/ruby_pi/context/transform.rb
Overview
Factory methods for building transform_context callables. Each method returns a Proc that accepts an Agent::State and mutates it. Use ‘compose` to chain multiple transforms.
Class Method Summary collapse
-
.compose(*transforms) ⇒ Proc
Chains multiple transform callables into a single callable that executes them in order.
-
.inject_datetime ⇒ Proc
Returns a transform that appends the current date and time to the system prompt.
-
.inject_user_preferences {|state| ... } ⇒ Proc
Returns a transform that appends user preferences to the system prompt.
-
.inject_workspace_context {|state| ... } ⇒ Proc
Returns a transform that appends workspace context to the system prompt.
Class Method Details
.compose(*transforms) ⇒ Proc
Chains multiple transform callables into a single callable that executes them in order. Each transform receives the same State object and can mutate it freely.
38 39 40 41 42 |
# File 'lib/ruby_pi/context/transform.rb', line 38 def compose(*transforms) ->(state) do transforms.each { |t| t.call(state) } end end |
.inject_datetime ⇒ Proc
Returns a transform that appends the current date and time to the system prompt. Useful for giving the LLM temporal awareness.
52 53 54 55 56 57 |
# File 'lib/ruby_pi/context/transform.rb', line 52 def inject_datetime ->(state) do = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S UTC") state.system_prompt += "\n\nCurrent date and time: #{}" end end |
.inject_user_preferences {|state| ... } ⇒ Proc
Returns a transform that appends user preferences to the system prompt. The block is called with the state and should return a string or hash of preferences. If nil is returned, nothing is appended.
71 72 73 74 75 76 77 78 79 |
# File 'lib/ruby_pi/context/transform.rb', line 71 def inject_user_preferences(&block) ->(state) do preferences = block.call(state) return if preferences.nil? prefs_text = preferences.is_a?(Hash) ? format_hash(preferences) : preferences.to_s state.system_prompt += "\n\n[User Preferences]\n#{prefs_text}" end end |
.inject_workspace_context {|state| ... } ⇒ Proc
Returns a transform that appends workspace context to the system prompt. The block is called with the state and should return contextual information about the current workspace/project.
92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby_pi/context/transform.rb', line 92 def inject_workspace_context(&block) ->(state) do context = block.call(state) return if context.nil? ctx_text = context.is_a?(Hash) ? format_hash(context) : context.to_s state.system_prompt += "\n\n[Workspace Context]\n#{ctx_text}" end end |