Class: TurnKit::Agent
- Inherits:
-
Object
- Object
- TurnKit::Agent
- Defined in:
- lib/turnkit/agent.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#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.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#skills ⇒ Object
readonly
Returns the value of attribute skills.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#sub_agents ⇒ Object
readonly
Returns the value of attribute sub_agents.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #build_budget(root_started_at: Clock.now) ⇒ Object
- #conversation(model: nil, subject: nil, metadata: {}) ⇒ Object
- #effective_client ⇒ Object
- #effective_model ⇒ Object
- #effective_store ⇒ Object
- #effective_tools ⇒ Object
-
#initialize(name:, description: "", model: nil, instructions: "", tools: [], skills: [], sub_agents: [], client: nil, store: nil, max_iterations: nil, timeout: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil) ⇒ Agent
constructor
A new instance of Agent.
- #instructions_with_skills ⇒ Object
Constructor Details
#initialize(name:, description: "", model: nil, instructions: "", tools: [], skills: [], sub_agents: [], client: nil, store: nil, max_iterations: nil, timeout: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil) ⇒ Agent
Returns a new instance of Agent.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/turnkit/agent.rb', line 8 def initialize(name:, description: "", model: nil, instructions: "", tools: [], skills: [], sub_agents: [], client: nil, store: nil, max_iterations: nil, timeout: nil, cost_limit: nil, max_depth: nil, max_tool_executions: nil) @name = name.to_s @description = description.to_s @model = model @instructions = instructions.to_s @tools = Array(tools) @skills = Array(skills) @sub_agents = Array(sub_agents) @client = client @store = store @max_iterations = max_iterations @timeout = timeout @cost_limit = cost_limit @max_depth = max_depth @max_tool_executions = max_tool_executions raise ArgumentError, "name is required" if @name.empty? end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def client @client end |
#cost_limit ⇒ Object (readonly)
Returns the value of attribute cost_limit.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def cost_limit @cost_limit end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def description @description end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def instructions @instructions end |
#max_depth ⇒ Object (readonly)
Returns the value of attribute max_depth.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def max_depth @max_depth end |
#max_iterations ⇒ Object (readonly)
Returns the value of attribute max_iterations.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def max_iterations @max_iterations end |
#max_tool_executions ⇒ Object (readonly)
Returns the value of attribute max_tool_executions.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def max_tool_executions @max_tool_executions end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def name @name end |
#skills ⇒ Object (readonly)
Returns the value of attribute skills.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def skills @skills end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def store @store end |
#sub_agents ⇒ Object (readonly)
Returns the value of attribute sub_agents.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def sub_agents @sub_agents end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/turnkit/agent.rb', line 6 def timeout @timeout end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
5 6 7 |
# File 'lib/turnkit/agent.rb', line 5 def tools @tools end |
Instance Method Details
#build_budget(root_started_at: Clock.now) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/turnkit/agent.rb', line 54 def build_budget(root_started_at: Clock.now) Budget.new( max_iterations: max_iterations || TurnKit.max_iterations, timeout: timeout || TurnKit.timeout, max_depth: max_depth || TurnKit.max_depth, max_tool_executions: max_tool_executions || TurnKit.max_tool_executions, cost_limit: cost_limit || TurnKit.cost_limit, root_started_at: root_started_at ) end |
#conversation(model: nil, subject: nil, metadata: {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/turnkit/agent.rb', line 27 def conversation(model: nil, subject: nil, metadata: {}) store = effective_store record = store.create_conversation( "agent_name" => name, "model" => model || effective_model, "subject" => subject, "metadata" => ) Conversation.new(agent: self, record: record, store: store, model: model || effective_model, subject: subject, metadata: ) end |
#effective_client ⇒ Object
42 43 44 |
# File 'lib/turnkit/agent.rb', line 42 def effective_client client || TurnKit.client end |
#effective_model ⇒ Object
38 39 40 |
# File 'lib/turnkit/agent.rb', line 38 def effective_model model || TurnKit.default_model end |
#effective_store ⇒ Object
46 47 48 |
# File 'lib/turnkit/agent.rb', line 46 def effective_store store || TurnKit.store end |
#effective_tools ⇒ Object
50 51 52 |
# File 'lib/turnkit/agent.rb', line 50 def effective_tools tools + sub_agents.map { |agent| SubAgentTool.for(agent) } end |
#instructions_with_skills ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/turnkit/agent.rb', line 65 def instructions_with_skills parts = [ instructions ] skills.each do |skill| parts << "## Skill: #{skill.name}\n\n#{skill.content}" end parts.reject(&:empty?).join("\n\n") end |