Class: TurnKit::Workflow
- Inherits:
-
Object
- Object
- TurnKit::Workflow
- Defined in:
- lib/turnkit/workflow.rb
Constant Summary collapse
- DEFAULT_INSTRUCTIONS =
<<~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
Instance Attribute Summary collapse
-
#available_skills ⇒ Object
readonly
Returns the value of attribute available_skills.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#compaction ⇒ Object
readonly
Returns the value of attribute compaction.
-
#cost_limit ⇒ Object
readonly
Returns the value of attribute cost_limit.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#max_depth ⇒ Object
readonly
Returns the value of attribute max_depth.
-
#max_iterations ⇒ Object
readonly
Returns the value of attribute max_iterations.
-
#max_tool_executions ⇒ Object
readonly
Returns the value of attribute max_tool_executions.
-
#max_tool_executions_by_name ⇒ Object
readonly
Returns the value of attribute max_tool_executions_by_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_event ⇒ Object
readonly
Returns the value of attribute on_event.
-
#output_audit ⇒ Object
readonly
Returns the value of attribute output_audit.
-
#output_audit_mode ⇒ Object
readonly
Returns the value of attribute output_audit_mode.
-
#output_policy ⇒ Object
readonly
Returns the value of attribute output_policy.
-
#output_policy_mode ⇒ Object
readonly
Returns the value of attribute output_policy_mode.
-
#output_policy_model ⇒ Object
readonly
Returns the value of attribute output_policy_model.
-
#output_policy_thinking ⇒ Object
readonly
Returns the value of attribute output_policy_thinking.
-
#output_schema ⇒ Object
readonly
Returns the value of attribute output_schema.
-
#prompt_mode ⇒ Object
readonly
Returns the value of attribute prompt_mode.
-
#skills ⇒ Object
readonly
Returns the value of attribute skills.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #agent(**options) ⇒ Object
-
#initialize(name: "workflow", description: "", instructions: nil, tools: [], skills: [], available_skills: [], model: nil, client: nil, store: nil, prompt_mode: :task, thinking: nil, compaction: nil, on_event: nil, output_schema: nil, max_iterations: nil, timeout: nil, max_spend: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil, max_tool_executions_by_name: nil, output_audit: nil, output_audit_mode: nil, output_policy: nil, output_policy_mode: nil, output_policy_model: nil, output_policy_thinking: nil) ⇒ Workflow
constructor
A new instance of Workflow.
- #max_spend ⇒ Object
- #run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {}, max_spend: nil, cost_limit: nil, **options) ⇒ Object
Constructor Details
#initialize(name: "workflow", description: "", instructions: nil, tools: [], skills: [], available_skills: [], model: nil, client: nil, store: nil, prompt_mode: :task, thinking: nil, compaction: nil, on_event: nil, output_schema: nil, max_iterations: nil, timeout: nil, max_spend: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil, max_tool_executions_by_name: nil, output_audit: nil, output_audit_mode: nil, output_policy: nil, output_policy_mode: nil, output_policy_model: nil, output_policy_thinking: nil) ⇒ Workflow
Returns a new instance of Workflow.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/turnkit/workflow.rb', line 32 def initialize(name: "workflow", description: "", instructions: nil, tools: [], skills: [], available_skills: [], model: nil, client: nil, store: nil, prompt_mode: :task, thinking: nil, compaction: nil, on_event: nil, output_schema: nil, max_iterations: nil, timeout: nil, max_spend: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil, max_tool_executions_by_name: nil, output_audit: nil, output_audit_mode: nil, output_policy: nil, output_policy_mode: nil, output_policy_model: nil, output_policy_thinking: nil) @name = name.to_s @description = description.to_s @instructions = instructions || DEFAULT_INSTRUCTIONS @tools = Array(tools) @skills = Array(skills) @available_skills = Array(available_skills) @model = model @client = client @store = store @prompt_mode = prompt_mode @thinking = thinking @compaction = compaction @on_event = on_event @output_schema = output_schema @max_iterations = max_iterations @timeout = timeout @cost_limit = cost_limit || max_spend @max_depth = max_depth @max_tool_executions = max_tool_executions @max_tool_executions_by_name = max_tool_executions_by_name @output_audit = output_audit @output_audit_mode = output_audit_mode @output_policy = output_policy @output_policy_mode = output_policy_mode @output_policy_model = output_policy_model @output_policy_thinking = output_policy_thinking raise ArgumentError, "name is required" if @name.empty? @agent = build_agent end |
Instance Attribute Details
#available_skills ⇒ Object (readonly)
Returns the value of attribute available_skills.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def available_skills @available_skills end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def client @client end |
#compaction ⇒ Object (readonly)
Returns the value of attribute compaction.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def compaction @compaction end |
#cost_limit ⇒ Object (readonly)
Returns the value of attribute cost_limit.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def cost_limit @cost_limit end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def description @description end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def instructions @instructions end |
#max_depth ⇒ Object (readonly)
Returns the value of attribute max_depth.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def max_depth @max_depth end |
#max_iterations ⇒ Object (readonly)
Returns the value of attribute max_iterations.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def max_iterations @max_iterations end |
#max_tool_executions ⇒ Object (readonly)
Returns the value of attribute max_tool_executions.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def max_tool_executions @max_tool_executions end |
#max_tool_executions_by_name ⇒ Object (readonly)
Returns the value of attribute max_tool_executions_by_name.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def max_tool_executions_by_name @max_tool_executions_by_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def name @name end |
#on_event ⇒ Object (readonly)
Returns the value of attribute on_event.
9 10 11 |
# File 'lib/turnkit/workflow.rb', line 9 def on_event @on_event end |
#output_audit ⇒ Object (readonly)
Returns the value of attribute output_audit.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_audit @output_audit end |
#output_audit_mode ⇒ Object (readonly)
Returns the value of attribute output_audit_mode.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_audit_mode @output_audit_mode end |
#output_policy ⇒ Object (readonly)
Returns the value of attribute output_policy.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_policy @output_policy end |
#output_policy_mode ⇒ Object (readonly)
Returns the value of attribute output_policy_mode.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_policy_mode @output_policy_mode end |
#output_policy_model ⇒ Object (readonly)
Returns the value of attribute output_policy_model.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_policy_model @output_policy_model end |
#output_policy_thinking ⇒ Object (readonly)
Returns the value of attribute output_policy_thinking.
11 12 13 |
# File 'lib/turnkit/workflow.rb', line 11 def output_policy_thinking @output_policy_thinking end |
#output_schema ⇒ Object (readonly)
Returns the value of attribute output_schema.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def output_schema @output_schema end |
#prompt_mode ⇒ Object (readonly)
Returns the value of attribute prompt_mode.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def prompt_mode @prompt_mode end |
#skills ⇒ Object (readonly)
Returns the value of attribute skills.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def skills @skills end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def store @store end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking.
8 9 10 |
# File 'lib/turnkit/workflow.rb', line 8 def thinking @thinking end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/turnkit/workflow.rb', line 10 def timeout @timeout end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
7 8 9 |
# File 'lib/turnkit/workflow.rb', line 7 def tools @tools end |
Instance Method Details
#agent(**options) ⇒ Object
90 91 92 |
# File 'lib/turnkit/workflow.rb', line 90 def agent(**) .empty? ? @agent : build_agent(**) end |
#max_spend ⇒ Object
94 95 96 |
# File 'lib/turnkit/workflow.rb', line 94 def max_spend cost_limit end |
#run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {}, max_spend: nil, cost_limit: nil, **options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/turnkit/workflow.rb', line 69 def run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {}, max_spend: nil, cost_limit: nil, **) task = task || prompt raise ArgumentError, "task is required" if task.to_s.empty? runtime_agent = if .empty? && cost_limit.nil? && max_spend.nil? @agent else build_agent(cost_limit: cost_limit || max_spend, **) end runtime_agent.run( task, input: input, async: async, subject: subject, metadata: ) end |