class RubyLLM::Workflow
Adds workflow and step context to RubyLLM instrumentation while leaving orchestration in ordinary Ruby code.
Create workflows through RubyLLM.workflow rather than constructing this class directly:
RubyLLM.workflow("Write article", id: "article-42") do |workflow| notes = workflow.step("Research") { ResearchAgent.new.ask(topic).content } workflow.step("Draft") { WriterAgent.new.ask(notes).content } end
Attributes
Returns the workflow identifier shared by its instrumentation events.
Returns the workflow name.
Public Instance Methods
Source
# File lib/ruby_llm/workflow.rb, line 42 def step(name, id: nil, &block) raise ArgumentError, 'a workflow step block is required' unless block step_context = workflow_context.merge( workflow_step_id: normalize(id || SecureRandom.uuid, 'step id'), workflow_step_name: normalize(name, 'step name') ) parent_id = current_step_id step_context[:workflow_step_parent_id] = parent_id if parent_id Support::Instrumentation.with_workflow(step_context.freeze) do RubyLLM.instrument('workflow_step.ruby_llm', config: @config) { block.call } end end
Runs a named section of Ruby code and adds its identity to every RubyLLM event emitted by the block. An ID is generated when one is not supplied. Steps can contain regular Ruby control flow and may be nested. Returns the block’s result.