Module: ActiveAgent::Delegation
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_agent/concerns/delegation.rb,
lib/active_agent/delegation/budget.rb,
lib/active_agent/delegation/ledger.rb,
lib/active_agent/delegation/runner.rb,
lib/active_agent/delegation/schema.rb,
lib/active_agent/delegation/backend.rb,
lib/active_agent/delegation/pricing.rb,
lib/active_agent/delegation/contract.rb,
lib/active_agent/delegation/definition.rb
Overview
Agent-as-tool delegation: hand part of a job to another agent.
A tool is a Ruby method the model can call. A delegation is another agent the model can call — same mechanism, but the callee has its own instructions, its own templates, its own model, and its own budget. That separation is what makes the pattern worth having as a primitive: a specialist agent stays specialist, and the generalist orchestrating it never inherits its prompt.
Delegation has three moving parts, each declared where it belongs:
- The contract lives on the sub-agent, next to the action it describes. Callers say which agent they want; they never restate its parameters.
- The budget lives at the call site, because only the caller knows what the work is worth. Exceeding it returns a structured result the model can reason about, not an exception that ends the conversation.
- The backend lives at the call site too, so the same sub-agent can run on a cheap local model in one parent and a frontier model in another without either agent's code changing.
Defined Under Namespace
Modules: Pricing Classes: Backend, Budget, BudgetExceededError, Contract, Definition, InvalidResultError, Ledger, Runner, Schema, TimeoutError
Instance Method Summary collapse
-
#delegation_ledger ⇒ Delegation::Ledger
Ledger covering every delegation made during this generation.
-
#delegation_ledger_for(tool_name) ⇒ Delegation::Ledger
Ledger for a single delegation during this generation.
-
#delegation_ledgers ⇒ Hash{Symbol => Delegation::Ledger}
Per-delegation ledgers.
-
#perform_delegation(tool_name, **arguments) ⇒ Object
Runs a delegated call.
Instance Method Details
#delegation_ledger ⇒ Delegation::Ledger
Ledger covering every delegation made during this generation.
333 334 335 |
# File 'lib/active_agent/concerns/delegation.rb', line 333 def delegation_ledger @_delegation_ledger ||= Delegation::Ledger.new end |
#delegation_ledger_for(tool_name) ⇒ Delegation::Ledger
Ledger for a single delegation during this generation.
341 342 343 |
# File 'lib/active_agent/concerns/delegation.rb', line 341 def delegation_ledger_for(tool_name) delegation_ledgers[tool_name.to_sym] ||= Delegation::Ledger.new end |
#delegation_ledgers ⇒ Hash{Symbol => Delegation::Ledger}
Returns per-delegation ledgers.
346 347 348 |
# File 'lib/active_agent/concerns/delegation.rb', line 346 def delegation_ledgers @_delegation_ledgers ||= {} end |
#perform_delegation(tool_name, **arguments) ⇒ Object
Runs a delegated call. Providers reach this through the tool method ClassMethods#delegate_to defines.
356 357 358 359 360 361 |
# File 'lib/active_agent/concerns/delegation.rb', line 356 def perform_delegation(tool_name, **arguments) definition = self.class.delegations[tool_name.to_sym] raise ArgumentError, "#{self.class} has no delegation named #{tool_name}" unless definition Delegation::Runner.new(definition, owner: self).call(**arguments) end |