Class: Zavudev::Resources::Senders::Agent::Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/zavudev/resources/senders/agent/tools.rb,
lib/zavudev/resources/senders/agent/tools/webhook.rb,
sig/zavudev/resources/senders/agent/tools.rbs,
sig/zavudev/resources/senders/agent/tools/webhook.rbs

Defined Under Namespace

Classes: Webhook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Tools

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tools.

Parameters:



239
240
241
242
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 239

def initialize(client:)
  @client = client
  @webhook = Zavudev::Resources::Senders::Agent::Tools::Webhook.new(client: client)
end

Instance Attribute Details

#webhook ⇒ Zavudev::Resources::Senders::Agent::Tools::Webhook (readonly)



9
10
11
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 9

def webhook
  @webhook
end

Instance Method Details

#create(sender_id, description:, name:, parameters:, webhook_url:, enabled: nil, webhook_secret: nil, request_options: {}) ⇒ Zavudev::Models::Senders::Agent::ToolCreateResponse

Some parameter documentations has been truncated, see Models::Senders::Agent::ToolCreateParams for more details.

Create a new tool for an agent. Tools allow the agent to call external webhooks.

Parameters:

  • sender_id (String)
  • description (String)
  • name (String)
  • parameters (Zavudev::Models::Senders::Agent::ToolParameters)
  • webhook_url (String) —

    Must be HTTPS.

  • enabled (Boolean)
  • webhook_secret (String) —

    Signing secret for the webhook. Optional: Zavu generates one when omitted and re

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



37
38
39
40
41
42
43
44
45
46
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 37

def create(sender_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/senders/%1$s/agent/tools", sender_id],
    body: parsed,
    model: Zavudev::Models::Senders::Agent::ToolCreateResponse,
    options: options
  )
end

#delete(tool_id, sender_id:, request_options: {}) ⇒ nil

Delete a tool.

Parameters:

Returns:

  • (nil)

See Also:



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 150

def delete(tool_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolDeleteParams.dump_request(params)
  sender_id =
    parsed.delete(:sender_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["v1/senders/%1$s/agent/tools/%2$s", sender_id, tool_id],
    model: NilClass,
    options: options
  )
end

#list(sender_id, cursor: nil, enabled: nil, limit: nil, request_options: {}) ⇒ Zavudev::Internal::Cursor<Zavudev::Models::Senders::Agent::AgentTool>

List tools for an agent.

Parameters:

  • sender_id (String)
  • cursor (String)
  • enabled (Boolean)
  • limit (Integer)
  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 126

def list(sender_id, params = {})
  parsed, options = Zavudev::Senders::Agent::ToolListParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["v1/senders/%1$s/agent/tools", sender_id],
    query: query,
    page: Zavudev::Internal::Cursor,
    model: Zavudev::Senders::Agent::AgentTool,
    options: options
  )
end

#list_test_runs(tool_id, sender_id:, limit: nil, request_options: {}) ⇒ Zavudev::Models::Senders::Agent::ToolListTestRunsResponse

Recent runs of this tool triggered from the test endpoint, newest first. Covers manual tests only: a tool called by an agent during a real conversation is not recorded here.

Parameters:

  • tool_id (String) —

    Path param

  • sender_id (String) —

    Path param

  • limit (Integer) —

    Query param

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 181

def list_test_runs(tool_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolListTestRunsParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  sender_id =
    parsed.delete(:sender_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/senders/%1$s/agent/tools/%2$s/test-runs", sender_id, tool_id],
    query: query,
    model: Zavudev::Models::Senders::Agent::ToolListTestRunsResponse,
    options: options
  )
end

#retrieve(tool_id, sender_id:, request_options: {}) ⇒ Zavudev::Models::Senders::Agent::ToolRetrieveResponse

Get a specific tool.

Parameters:

Returns:

See Also:



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 59

def retrieve(tool_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolRetrieveParams.dump_request(params)
  sender_id =
    parsed.delete(:sender_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/senders/%1$s/agent/tools/%2$s", sender_id, tool_id],
    model: Zavudev::Models::Senders::Agent::ToolRetrieveResponse,
    options: options
  )
end

#test_(tool_id, sender_id:, test_params:, request_options: {}) ⇒ Zavudev::Models::Senders::Agent::ToolTestResponse

Run a tool with the parameters you supply and return what it answered.

The call is synchronous: the response carries the tool's status, body, and duration, so a green result is evidence the tool ran rather than evidence it was accepted. Each run is also recorded and readable afterwards via GET /v1/senders/{senderId}/agent/tools/{toolId}/test-runs.

A tool that answers with an error is reported as a run with success: false — the endpoint itself still returns 200. This fires the tool's real webhook, so a test has whatever side effects the tool has.

Parameters:

  • tool_id (String) —

    Path param

  • sender_id (String) —

    Path param

  • test_params (Hash{Symbol=>Object}) —

    Body param: Parameters to pass to the tool for testing.

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 221

def test_(tool_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolTestParams.dump_request(params)
  sender_id =
    parsed.delete(:sender_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/senders/%1$s/agent/tools/%2$s/test", sender_id, tool_id],
    body: parsed,
    model: Zavudev::Models::Senders::Agent::ToolTestResponse,
    options: options
  )
end

#update(tool_id, sender_id:, description: nil, enabled: nil, name: nil, parameters: nil, webhook_secret: nil, webhook_url: nil, request_options: {}) ⇒ Zavudev::Models::Senders::Agent::ToolUpdateResponse

Update a tool.

Parameters:

  • tool_id (String) —

    Path param

  • sender_id (String) —

    Path param

  • description (String) —

    Body param

  • enabled (Boolean) —

    Body param

  • name (String) —

    Body param

  • parameters (Zavudev::Models::Senders::Agent::ToolParameters) —

    Body param

  • webhook_secret (String, nil) —

    Body param

  • webhook_url (String) —

    Body param

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/zavudev/resources/senders/agent/tools.rb', line 98

def update(tool_id, params)
  parsed, options = Zavudev::Senders::Agent::ToolUpdateParams.dump_request(params)
  sender_id =
    parsed.delete(:sender_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :patch,
    path: ["v1/senders/%1$s/agent/tools/%2$s", sender_id, tool_id],
    body: parsed,
    model: Zavudev::Models::Senders::Agent::ToolUpdateResponse,
    options: options
  )
end