Class: Mistri::ToolContext

Inherits:
Data
  • Object
show all
Defined in:
lib/mistri/tool_context.rb

Overview

What a tool handler may know about the run it executes inside: the caller's session, the abort signal, the event stream, and the host's own context object. Handlers take it as an optional second argument — a proc ignores it invisibly, a lambda opts in by accepting two parameters. Sub-agents are built on it; any tool that spawns work, links records to the session, or streams progress can use it the same way.

app carries whatever the host passes as Agent.new(context:) — the acting user, a tenant, a request — untouched. The gem provides the slot, never the vocabulary:

agent = Mistri.agent("claude-opus-4-8", tools: tools,
                   context: { traveler: current_traveler })
Mistri::Tool.define("book_hotel", "Books the chosen hotel.") do |args, context|
Bookings.create(args, traveler: context.app[:traveler])
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session: nil, signal: nil, emit: nil, app: nil) ⇒ ToolContext

Returns a new instance of ToolContext.



22
23
24
# File 'lib/mistri/tool_context.rb', line 22

def initialize(session: nil, signal: nil, emit: nil, app: nil)
  super
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



21
22
23
# File 'lib/mistri/tool_context.rb', line 21

def app
  @app
end

#emitObject (readonly)

Returns the value of attribute emit

Returns:

  • (Object)

    the current value of emit



21
22
23
# File 'lib/mistri/tool_context.rb', line 21

def emit
  @emit
end

#sessionObject (readonly)

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



21
22
23
# File 'lib/mistri/tool_context.rb', line 21

def session
  @session
end

#signalObject (readonly)

Returns the value of attribute signal

Returns:

  • (Object)

    the current value of signal



21
22
23
# File 'lib/mistri/tool_context.rb', line 21

def signal
  @signal
end