Class: Agentd::Client

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

Overview

Low-level HTTP client for the Power Relay platform API and MCP endpoint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, endpoint: Agentd.endpoint) ⇒ Client

Returns a new instance of Client.



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

def initialize(api_key:, endpoint: Agentd.endpoint)
  @api_key  = api_key
  @endpoint = endpoint.chomp("/")
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

Instance Method Details

#provision(handle:, name: nil, description: nil, model: nil, capabilities: [], initial_context: {}, metadata: {}) ⇒ Object

Provision a new agent. Returns agent attributes including api_key.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/agentd/client.rb', line 15

def provision(handle:, name: nil, description: nil, model: nil,
              capabilities: [], initial_context: {}, metadata: {})
  resp = connection.post("/agents") do |req|
    req.body = JSON.generate(agent: {
      handle:,
      name:,
      description:,
      model:,
      capabilities:,
      initial_context:,
      metadata:
    }.compact)
  end
  handle_response(resp)
end

#tool(name, **args) ⇒ Object

Call an MCP tool on behalf of the authenticated agent.

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/agentd/client.rb', line 32

def tool(name, **args)
  resp = connection.post("/mcp") do |req|
    req.body = JSON.generate(
      jsonrpc: "2.0",
      id:      SecureRandom.hex(4),
      method:  "tools/call",
      params:  { name:, arguments: args }
    )
  end
  result = handle_response(resp)
  raise McpError, result.dig("error", "message") if result["error"]
  JSON.parse(result.dig("result", "content", 0, "text"))
end