Class: TurnKit::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/turnkit/workflow.rb

Constant Summary collapse

ORCHESTRATOR_PREAMBLE =
<<~TEXT.strip
  You are an autonomous task orchestrator. Navigate from the application
  request to a final output without asking the user follow-up questions.

  Use the available tools to gather context, inspect sources, take actions,
  persist outputs, and verify work. Use loaded skills as reusable workflow
  patterns. Iterate when work needs missing context, critique, revision, or
  verification.

  When multiple independent items need the same kind of fetch or read, and
  an available batch tool can handle them in one call, prefer the batch tool
  over repeated one-item tool calls.

  Stop when the task is complete, when the available context and tools are
  sufficient for the best possible answer, or when further iteration would
  not materially improve the result. Respect runtime, cost, and iteration
  limits.
TEXT
DEFAULT_INSTRUCTIONS =
ORCHESTRATOR_PREAMBLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "workflow", instructions: nil, preamble: true, **options) ⇒ Workflow

Returns a new instance of Workflow.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/turnkit/workflow.rb', line 30

def initialize(name: "workflow", instructions: nil, preamble: true, **options)
  @name = name.to_s
  raise ArgumentError, "name is required" if @name.empty?

  @options = options.merge(
    name: @name,
    prompt_mode: options.fetch(:prompt_mode, :task),
    instructions: compose_instructions(instructions, preamble: preamble)
  ).freeze
  @agent = Agent.new(**@options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/turnkit/workflow.rb', line 28

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/turnkit/workflow.rb', line 28

def options
  @options
end

Instance Method Details

#agent(**overrides) ⇒ Object



46
47
48
# File 'lib/turnkit/workflow.rb', line 46

def agent(**overrides)
  overrides.empty? ? @agent : Agent.new(**@options.merge(overrides.compact))
end

#run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {}, **overrides) ⇒ Object



42
43
44
# File 'lib/turnkit/workflow.rb', line 42

def run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {}, **overrides)
  agent(**overrides).run(task || prompt, input: input, async: async, subject: subject, metadata: )
end