Class: Agentd::Client
- Inherits:
-
Object
- Object
- Agentd::Client
- Defined in:
- lib/agentd/client.rb
Overview
Low-level HTTP client for the Power Relay platform API and MCP endpoint.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#initialize(api_key:, endpoint: Agentd.endpoint) ⇒ Client
constructor
A new instance of Client.
-
#provision(handle:, name: nil, description: nil, model: nil, capabilities: [], initial_context: {}, metadata: {}) ⇒ Object
Provision a new agent.
-
#tool(name, **args) ⇒ Object
Call an MCP tool on behalf of the authenticated agent.
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/agentd/client.rb', line 7 def api_key @api_key end |
#endpoint ⇒ Object (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.
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 |