Module: Brute::Env

Defined in:
lib/brute/env.rb

Overview

What the turn came back with, asked of the env itself.

env = agent.start("hello")
env.extend(Brute::Env)
env.reply.content if env.has_reply?

A turn ends with whatever the last middleware left in env, and that is not always an answer: a turn that only ran tools, or that the provider failed, ends on something else. So the reply is the last message AND only when the assistant is the one who wrote it.

Instance Method Summary collapse

Instance Method Details

#has_reply?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/brute/env.rb', line 18

def has_reply?
  !reply.nil?
end

#replyObject



22
23
24
25
26
27
28
# File 'lib/brute/env.rb', line 22

def reply
  messages = self[:messages]

  if messages.respond_to?(:last) && messages.last&.role == :assistant
    messages.last
  end
end