Class: TurnKit::Fleet

Inherits:
Object
  • Object
show all
Defined in:
lib/turnkit/fleet.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.

  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

Instance Method Summary collapse

Constructor Details

#initialize(name: "orchestrator", description: "", instructions: nil, tools: [], skills: [], available_skills: [], model: nil, client: nil, store: nil, prompt_mode: :task, thinking: nil, compaction: nil, output_schema: nil, max_iterations: nil, timeout: nil, max_spend: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil) ⇒ Fleet

Returns a new instance of Fleet.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/turnkit/fleet.rb', line 24

def initialize(name: "orchestrator", description: "", instructions: nil,
  tools: [], skills: [], available_skills: [], model: nil, client: nil,
  store: nil, prompt_mode: :task, thinking: nil, compaction: nil,
  output_schema: nil, max_iterations: nil, timeout: nil, max_spend: nil,
  cost_limit: nil, max_depth: nil, max_tool_executions: 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
  @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
  raise ArgumentError, "name is required" if @name.empty?
  build_agent
end

Instance Attribute Details

#available_skillsObject (readonly)

Returns the value of attribute available_skills.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def available_skills
  @available_skills
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def client
  @client
end

#compactionObject (readonly)

Returns the value of attribute compaction.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def compaction
  @compaction
end

#cost_limitObject (readonly)

Returns the value of attribute cost_limit.



7
8
9
# File 'lib/turnkit/fleet.rb', line 7

def cost_limit
  @cost_limit
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def description
  @description
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def instructions
  @instructions
end

#max_depthObject (readonly)

Returns the value of attribute max_depth.



7
8
9
# File 'lib/turnkit/fleet.rb', line 7

def max_depth
  @max_depth
end

#max_iterationsObject (readonly)

Returns the value of attribute max_iterations.



7
8
9
# File 'lib/turnkit/fleet.rb', line 7

def max_iterations
  @max_iterations
end

#max_tool_executionsObject (readonly)

Returns the value of attribute max_tool_executions.



7
8
9
# File 'lib/turnkit/fleet.rb', line 7

def max_tool_executions
  @max_tool_executions
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def name
  @name
end

#output_schemaObject (readonly)

Returns the value of attribute output_schema.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def output_schema
  @output_schema
end

#prompt_modeObject (readonly)

Returns the value of attribute prompt_mode.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def prompt_mode
  @prompt_mode
end

#skillsObject (readonly)

Returns the value of attribute skills.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def skills
  @skills
end

#storeObject (readonly)

Returns the value of attribute store.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def store
  @store
end

#thinkingObject (readonly)

Returns the value of attribute thinking.



6
7
8
# File 'lib/turnkit/fleet.rb', line 6

def thinking
  @thinking
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/turnkit/fleet.rb', line 7

def timeout
  @timeout
end

#toolsObject (readonly)

Returns the value of attribute tools.



5
6
7
# File 'lib/turnkit/fleet.rb', line 5

def tools
  @tools
end

Instance Method Details

#agent(**options) ⇒ Object



70
71
72
# File 'lib/turnkit/fleet.rb', line 70

def agent(**options)
  build_agent(**options)
end

#max_spendObject



74
75
76
# File 'lib/turnkit/fleet.rb', line 74

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 Also known as: auto_run, autorun

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/turnkit/fleet.rb', line 52

def run(prompt = nil, task: nil, input: nil, async: false, subject: nil, metadata: {},
  max_spend: nil, cost_limit: nil, **options)

  task = task || prompt
  raise ArgumentError, "task is required" if task.to_s.empty?

  build_agent(cost_limit: cost_limit || max_spend, **options).run(
    task,
    input: input,
    async: async,
    subject: subject,
    metadata: 
  )
end