Class: Antigravity::Agent

Inherits:
Base
  • Object
show all
Defined in:
lib/antigravity/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited

Methods included from Emojifiable

#emoji, included

Constructor Details

#initialize(model: nil, auto_logger: true) {|_self| ... } ⇒ Agent

Returns a new instance of Agent.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/antigravity/agent.rb', line 9

def initialize(model: nil, auto_logger: true, &block)
  @model = model || Antigravity.config.default_model
  @api_key = Antigravity.config.api_key
  @system_instruction = nil
  @tools = []
  @skills = []
  @sidecars = []
  @hooks = Hooks.new
  @client = Client.new
  @logger_guard = nil

  # Automagic Logger attachment unless disabled via ENV["ANTIGRAVITY_LOGGER"]=false or auto_logger: false
  if auto_logger && logger_enabled?
    attach_logger
  end

  yield(self) if block_given?
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/antigravity/agent.rb', line 6

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def client
  @client
end

#hooksObject (readonly)

Returns the value of attribute hooks.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def hooks
  @hooks
end

#logger_guardObject (readonly)

Returns the value of attribute logger_guard.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def logger_guard
  @logger_guard
end

#modelObject

Returns the value of attribute model.



6
7
8
# File 'lib/antigravity/agent.rb', line 6

def model
  @model
end

#sidecarsObject (readonly)

Returns the value of attribute sidecars.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def sidecars
  @sidecars
end

#skillsObject (readonly)

Returns the value of attribute skills.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def skills
  @skills
end

#system_instructionObject

Returns the value of attribute system_instruction.



6
7
8
# File 'lib/antigravity/agent.rb', line 6

def system_instruction
  @system_instruction
end

#toolsObject (readonly)

Returns the value of attribute tools.



7
8
9
# File 'lib/antigravity/agent.rb', line 7

def tools
  @tools
end

Instance Method Details

#after_response(&block) ⇒ Object



61
62
63
# File 'lib/antigravity/agent.rb', line 61

def after_response(&block)
  hooks.after_response(&block)
end

#after_tool_call(&block) ⇒ Object Also known as: on_tool_call



69
70
71
# File 'lib/antigravity/agent.rb', line 69

def after_tool_call(&block)
  hooks.after_tool_call(&block)
end

#attach_logger(log_target = nil, level: ::Logger::INFO, silent_notice: false) ⇒ Object



45
46
47
48
49
# File 'lib/antigravity/agent.rb', line 45

def attach_logger(log_target = nil, level: ::Logger::INFO, silent_notice: false)
  @logger_guard = Guards::AgentLogger.new(log_target, level: level, silent_notice: silent_notice)
  @logger_guard.attach_to(self)
  @logger_guard
end

#attach_sidecar(sidecar) ⇒ Object



40
41
42
43
# File 'lib/antigravity/agent.rb', line 40

def attach_sidecar(sidecar)
  @sidecars << sidecar
  sidecar
end

#before_prompt(&block) ⇒ Object



57
58
59
# File 'lib/antigravity/agent.rb', line 57

def before_prompt(&block)
  hooks.before_prompt(&block)
end

#before_tool_call(&block) ⇒ Object



65
66
67
# File 'lib/antigravity/agent.rb', line 65

def before_tool_call(&block)
  hooks.before_tool_call(&block)
end

#emit_sidecar_event(event_type, payload = {}) ⇒ Object



74
75
76
# File 'lib/antigravity/agent.rb', line 74

def emit_sidecar_event(event_type, payload = {})
  @sidecars.each { |sidecar| sidecar.emit(event_type, payload) }
end

#load_skill(skill_path) ⇒ Object



51
52
53
54
55
# File 'lib/antigravity/agent.rb', line 51

def load_skill(skill_path)
  skill = Skill.load(skill_path)
  @skills << skill
  skill
end

#prompt(message, &block) ⇒ Object Also known as: ask



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/antigravity/agent.rb', line 78

def prompt(message, &block)
  emit_sidecar_event(:prompt_started, prompt: message)
  hooks.run_pre_prompt(message)

  response = client.send_turn(self, message, &block)

  hooks.run_post_response(response)
  emit_sidecar_event(:turn_completed, response: response.content, model: model)

  response
end

#register_tool(tool_or_name = nil, description: "", &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/antigravity/agent.rb', line 28

def register_tool(tool_or_name = nil, description: "", &block)
  if block_given? && tool_or_name
    tool = Tool::Dynamic.new(tool_or_name, description: description, &block)
  elsif tool_or_name.respond_to?(:to_json_schema)
    tool = tool_or_name
  else
    raise ArgumentError, "Invalid tool definition"
  end
  @tools << tool
  tool
end