Class: Antigravity::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(harness: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/antigravity/client.rb', line 9

def initialize(harness: nil)
  @harness = harness || Harness.new
end

Instance Attribute Details

#harnessObject (readonly)

Returns the value of attribute harness.



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

def harness
  @harness
end

Instance Method Details

#execute_tool(agent, tool_name, params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/antigravity/client.rb', line 25

def execute_tool(agent, tool_name, params)
  # 1. Pre-tool Safety Policy Check
  policy_check = agent.hooks.run_pre_tool(tool_name, params)
  unless policy_check[:allowed]
    reason = policy_check[:reason]
    agent.emit_sidecar_event(:tool_blocked, tool: tool_name, params: params, reason: reason)
    return "❌ TOOL BLOCKED: #{reason}"
  end

  # 2. Execute target tool (safely match parameter signatures)
  tool = agent.tools.find { |t| t.tool_name == tool_name }
  raw_result = if tool && tool.respond_to?(:call)
                 method = tool.method(:call)
                 param_types = method.parameters

                 if param_types.empty?
                   tool.call
                 elsif param_types.any? { |type, _| type == :keyreq || type == :key }
                   valid_keys = param_types.map { |_, name| name }.compact
                   kw_args = params.transform_keys(&:to_sym).select { |k, _| valid_keys.include?(k) }
                   kw_args[:location] = "Milan" if valid_keys.include?(:location) && kw_args[:location].nil?
                   kw_args[:city] = "Milan" if valid_keys.include?(:city) && kw_args[:city].nil?
                   tool.call(**kw_args)
                 else
                   tool.call(params)
                 end
               else
                 "Tool #{tool_name} not found"
               end

  # 3. Post-tool Result Masking / Filtering
  filtered_result = agent.hooks.run_post_tool(tool_name, params, raw_result)
  agent.emit_sidecar_event(:tool_executed, tool_name: tool_name, params: params, result: filtered_result)

  filtered_result
end

#send_turn(agent, user_message, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/antigravity/client.rb', line 13

def send_turn(agent, user_message, &block)
  final_message = Message.new(role: :assistant, model_id: agent.model)

  if harness.running?
    dispatch_harness_turn(agent, user_message, final_message, &block)
  else
    mock_streaming_turn(agent, user_message, final_message, &block)
  end

  final_message
end