Class: RubyLLM::Team

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/team.rb,
lib/ruby_llm/team/run.rb,
lib/ruby_llm/team/version.rb,
lib/ruby_llm/team/artifact.rb

Overview

Groups named coworkers and creates tools for delegating work.

team = RubyLLM::Team.new
team.add(:researcher, ResearcherAgent)

session = team.session(max_calls: 8)     # bound what the model may spend
chat.with_tools(*session.tools)

The session keeps the artifacts, budget, and trace reachable after the model is done.

Registered classes are instantiated per call; registered instances are reused.

Defined Under Namespace

Classes: Artifact, BudgetExceededError, CollaborationError, Run, Session

Constant Summary collapse

DEFAULT_MAX_CALLS =

Every call costs money, so a run is bounded unless you say otherwise. This is a smoke alarm rather than a budget: it stops a runaway, and a workflow that legitimately needs more says so in one keyword — examples/blog/workflow.rb passes 40. Pass max_calls: nil for an unbounded run.

25
VERSION =
'0.1.2'

Instance Method Summary collapse

Constructor Details

#initializeTeam

Returns a new instance of Team.



34
35
36
# File 'lib/ruby_llm/team.rb', line 34

def initialize
  @agents = {}
end

Instance Method Details

#add(role, agent) ⇒ Object

Registers agent under role and returns self.

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
# File 'lib/ruby_llm/team.rb', line 39

def add(role, agent)
  role = role.to_s
  raise ArgumentError, 'provide a role' if role.empty?
  raise ArgumentError, 'provide an agent' unless agent

  @agents[role] = agent
  self
end

#run(max_calls: DEFAULT_MAX_CALLS, share_context: true, context: nil) {|execution| ... } ⇒ Object

Executes an ordinary Ruby workflow over one isolated session.

Yields:

  • (execution)


54
55
56
57
58
# File 'lib/ruby_llm/team.rb', line 54

def run(max_calls: DEFAULT_MAX_CALLS, share_context: true, context: nil)
  execution = Run.new(session(max_calls: max_calls, share_context: share_context, context: context))
  yield execution if block_given?
  execution
end

#session(max_calls: DEFAULT_MAX_CALLS, share_context: true, context: nil) ⇒ Object

Creates isolated collaboration state for one lead-agent run.



49
50
51
# File 'lib/ruby_llm/team.rb', line 49

def session(max_calls: DEFAULT_MAX_CALLS, share_context: true, context: nil)
  Session.new(@agents.dup.freeze, max_calls: max_calls, share_context: share_context, context: context)
end