Class: Cadenya::Resources::Objectives

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenya/resources/objectives.rb

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ Objectives

Returns a new instance of Objectives.



8
9
10
# File 'lib/cadenya/resources/objectives.rb', line 8

def initialize(core)
  @core = core
end

Instance Method Details

#approve_tool_call(objective_id, tool_call_id, workspace_id: nil, request_options: nil) ⇒ Object

Approve a tool call



212
213
214
215
216
217
# File 'lib/cadenya/resources/objectives.rb', line 212

def approve_tool_call(objective_id, tool_call_id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tool_calls/#{Util.path_param('toolCallId', tool_call_id)}:approve"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::ObjectiveToolCall.from_json(_data)
end

#cancel(objective_id, workspace_id: nil, reason: nil, request_options: nil) ⇒ Object

Cancel an objective



258
259
260
261
262
263
264
265
266
# File 'lib/cadenya/resources/objectives.rb', line 258

def cancel(objective_id, workspace_id: nil, reason: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}:cancel"
  _body = {
    "reason" => reason,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::Objective.from_json(_data)
end

#compact(objective_id, workspace_id: nil, compaction_config: nil, request_options: nil) ⇒ Object

Compact an objective



269
270
271
272
273
274
275
276
277
# File 'lib/cadenya/resources/objectives.rb', line 269

def compact(objective_id, workspace_id: nil, compaction_config: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}:compact"
  _body = {
    "compactionConfig" => compaction_config.nil? ? nil : (->(_v) { Types.encode_AgentVariationSpec_CompactionConfig(_v) }).call(compaction_config),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::CompactObjectiveResponse.from_json(_data)
end

#continue(objective_id, message:, workspace_id: nil, enqueue: nil, request_options: nil) ⇒ Object

Continue an objective



280
281
282
283
284
285
286
287
288
289
# File 'lib/cadenya/resources/objectives.rb', line 280

def continue(objective_id, message:, workspace_id: nil, enqueue: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}:continue"
  _body = {
    "message" => message,
    "enqueue" => enqueue,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::ObjectiveEvent.from_json(_data)
end

#create(agent_id:, system_prompt_data:, workspace_id: nil, variation_id: nil, metadata: nil, first_user_message: nil, secrets: nil, memory_cascade: nil, first_user_message_data: nil, episodic_memory: nil, tenant: nil, subject: nil, pinned_parameters: nil, request_options: nil) ⇒ Object

Create a new objective



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cadenya/resources/objectives.rb', line 41

def create(agent_id:, system_prompt_data:, workspace_id: nil, variation_id: nil, metadata: nil, first_user_message: nil, secrets: nil, memory_cascade: nil, first_user_message_data: nil, episodic_memory: nil, tenant: nil, subject: nil, pinned_parameters: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives"
  _body = {
    "agentId" => agent_id,
    "variationId" => variation_id,
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "systemPromptData" => system_prompt_data,
    "firstUserMessage" => first_user_message,
    "secrets" => secrets.nil? ? nil : (->(_v) { _v.is_a?(Array) ? _v.map { |_i| (->(_v) { Types.encode_CreateObjectiveRequest_Secret(_v) }).call(_i) } : _v }).call(secrets),
    "memoryCascade" => memory_cascade.nil? ? nil : (->(_v) { _v.is_a?(Array) ? _v.map { |_i| (->(_v) { Types.encode_MemoryReference(_v) }).call(_i) } : _v }).call(memory_cascade),
    "firstUserMessageData" => first_user_message_data,
    "episodicMemory" => episodic_memory.nil? ? nil : (->(_v) { Types.encode_ObjectiveEpisodicConfig(_v) }).call(episodic_memory),
    "tenant" => tenant.nil? ? nil : (->(_v) { Types.encode_TenantAssertion(_v) }).call(tenant),
    "subject" => subject.nil? ? nil : (->(_v) { Types.encode_SubjectAssertion(_v) }).call(subject),
    "pinnedParameters" => pinned_parameters,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::Objective.from_json(_data)
end

#create_feedback(objective_id, metadata:, data:, workspace_id: nil, request_options: nil) ⇒ Object

Submit feedback for an objective



147
148
149
150
151
152
153
154
155
156
# File 'lib/cadenya/resources/objectives.rb', line 147

def create_feedback(objective_id, metadata:, data:, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/feedback"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "data" => data.nil? ? nil : (->(_v) { Types.encode_ObjectiveFeedbackData(_v) }).call(data),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::ObjectiveFeedback.from_json(_data)
end

#deny_tool_call(objective_id, tool_call_id, workspace_id: nil, memo: nil, request_options: nil) ⇒ Object

Deny a tool call



220
221
222
223
224
225
226
227
228
# File 'lib/cadenya/resources/objectives.rb', line 220

def deny_tool_call(objective_id, tool_call_id, workspace_id: nil, memo: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tool_calls/#{Util.path_param('toolCallId', tool_call_id)}:deny"
  _body = {
    "memo" => memo,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::ObjectiveToolCall.from_json(_data)
end

#list(workspace_id: nil, limit: nil, cursor: nil, agent_id: nil, parent_objective_id: nil, state: nil, profile_id: nil, sort_order: nil, include_info: nil, agent_schedule_id: nil, labels: nil, tenant_id: nil, subject_id: nil, widget_id: nil, widget_session_id: nil, request_options: nil) ⇒ Object

List objectives



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cadenya/resources/objectives.rb', line 13

def list(workspace_id: nil, limit: nil, cursor: nil, agent_id: nil, parent_objective_id: nil, state: nil, profile_id: nil, sort_order: nil, include_info: nil, agent_schedule_id: nil, labels: nil, tenant_id: nil, subject_id: nil, widget_id: nil, widget_session_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "agentId" => agent_id,
    "parentObjectiveId" => parent_objective_id,
    "state" => state,
    "profileId" => profile_id,
    "sortOrder" => sort_order,
    "includeInfo" => include_info,
    "agentScheduleId" => agent_schedule_id,
    "labels" => labels,
    "tenantId" => tenant_id,
    "subjectId" => subject_id,
    "widgetId" => widget_id,
    "widgetSessionId" => widget_session_id,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::Objective.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list(workspace_id: workspace_id, limit: limit, cursor: _c, agent_id: agent_id, parent_objective_id: parent_objective_id, state: state, profile_id: profile_id, sort_order: sort_order, include_info: include_info, agent_schedule_id: agent_schedule_id, labels: labels, tenant_id: tenant_id, subject_id: subject_id, widget_id: widget_id, widget_session_id: widget_session_id, request_options: request_options)
  end
end

#list_context_windows(objective_id, workspace_id: nil, limit: nil, cursor: nil, include_info: nil, labels: nil, request_options: nil) ⇒ Object

List objective context windows



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cadenya/resources/objectives.rb', line 71

def list_context_windows(objective_id, workspace_id: nil, limit: nil, cursor: nil, include_info: nil, labels: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/context_windows"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "includeInfo" => include_info,
    "labels" => labels,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveContextWindow.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_context_windows(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, include_info: include_info, labels: labels, request_options: request_options)
  end
end

#list_events(objective_id, workspace_id: nil, limit: nil, cursor: nil, sort_order: nil, include_info: nil, window_id: nil, since_event_id: nil, labels: nil, request_options: nil) ⇒ Object

List objective events



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cadenya/resources/objectives.rb', line 97

def list_events(objective_id, workspace_id: nil, limit: nil, cursor: nil, sort_order: nil, include_info: nil, window_id: nil, since_event_id: nil, labels: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/events"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "sortOrder" => sort_order,
    "includeInfo" => include_info,
    "windowId" => window_id,
    "sinceEventId" => since_event_id,
    "labels" => labels,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveEvent.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_events(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, sort_order: sort_order, include_info: include_info, window_id: window_id, since_event_id: since_event_id, labels: labels, request_options: request_options)
  end
end

#list_feedback(objective_id, workspace_id: nil, limit: nil, cursor: nil, labels: nil, request_options: nil) ⇒ Object

List feedback for an objective



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cadenya/resources/objectives.rb', line 130

def list_feedback(objective_id, workspace_id: nil, limit: nil, cursor: nil, labels: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/feedback"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "labels" => labels,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveFeedback.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_feedback(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, labels: labels, request_options: request_options)
  end
end

#list_tasks(objective_id, workspace_id: nil, limit: nil, cursor: nil, sort_order: nil, request_options: nil) ⇒ Object

List objective tasks



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/cadenya/resources/objectives.rb', line 159

def list_tasks(objective_id, workspace_id: nil, limit: nil, cursor: nil, sort_order: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tasks"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "sortOrder" => sort_order,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveTask.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_tasks(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, sort_order: sort_order, request_options: request_options)
  end
end

#list_tool_calls(objective_id, workspace_id: nil, limit: nil, cursor: nil, status: nil, include_info: nil, execution_status: nil, labels: nil, request_options: nil) ⇒ Object

List objective tool calls



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cadenya/resources/objectives.rb', line 184

def list_tool_calls(objective_id, workspace_id: nil, limit: nil, cursor: nil, status: nil, include_info: nil, execution_status: nil, labels: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tool_calls"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "status" => status,
    "includeInfo" => include_info,
    "executionStatus" => execution_status,
    "labels" => labels,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveToolCall.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_tool_calls(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, status: status, include_info: include_info, execution_status: execution_status, labels: labels, request_options: request_options)
  end
end

#list_tools(objective_id, workspace_id: nil, limit: nil, cursor: nil, request_options: nil) ⇒ Object

List objective tools



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/cadenya/resources/objectives.rb', line 242

def list_tools(objective_id, workspace_id: nil, limit: nil, cursor: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tools"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveTool.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_tools(objective_id, workspace_id: workspace_id, limit: limit, cursor: _c, request_options: request_options)
  end
end

#retrieve(id, workspace_id: nil, request_options: nil) ⇒ Object

Get an objective by ID



63
64
65
66
67
68
# File 'lib/cadenya/resources/objectives.rb', line 63

def retrieve(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('id', id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::Objective.from_json(_data)
end

#retrieve_diagnostics(objective_id, workspace_id: nil, request_options: nil) ⇒ Object

Get objective context usage



89
90
91
92
93
94
# File 'lib/cadenya/resources/objectives.rb', line 89

def retrieve_diagnostics(objective_id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/diagnostics"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::GetObjectiveDiagnosticsResponse.from_json(_data)
end

#retrieve_task(objective_id, id, workspace_id: nil, request_options: nil) ⇒ Object

Get an objective task by ID



176
177
178
179
180
181
# File 'lib/cadenya/resources/objectives.rb', line 176

def retrieve_task(objective_id, id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tasks/#{Util.path_param('id', id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::ObjectiveTask.from_json(_data)
end

#retrieve_tool_call(objective_id, tool_call_id, workspace_id: nil, request_options: nil) ⇒ Object

Get an objective tool call by ID



204
205
206
207
208
209
# File 'lib/cadenya/resources/objectives.rb', line 204

def retrieve_tool_call(objective_id, tool_call_id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tool_calls/#{Util.path_param('toolCallId', tool_call_id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::ObjectiveToolCallWithResult.from_json(_data)
end

#set_tool_call_content(objective_id, tool_call_id, content:, workspace_id: nil, request_options: nil) ⇒ Object

Set a bare tool call's content



231
232
233
234
235
236
237
238
239
# File 'lib/cadenya/resources/objectives.rb', line 231

def set_tool_call_content(objective_id, tool_call_id, content:, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/tool_calls/#{Util.path_param('toolCallId', tool_call_id)}:setContent"
  _body = {
    "content" => content.nil? ? nil : (->(_v) { _v.is_a?(Array) ? _v.map { |_i| (->(_v) { Types.encode_SetToolCallContentRequest_ContentBlock(_v) }).call(_i) } : _v }).call(content),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::ObjectiveToolCall.from_json(_data)
end

#stream_events(objective_id, workspace_id: nil, last_event_id: nil, request_options: nil) ⇒ Object

Stream objective events



118
119
120
121
122
123
124
125
126
127
# File 'lib/cadenya/resources/objectives.rb', line 118

def stream_events(objective_id, workspace_id: nil, last_event_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/objectives/#{Util.path_param('objectiveId', objective_id)}/events:stream"
  _headers = last_event_id ? { "Last-Event-ID" => last_event_id } : nil
  _decoder = ->(event) { Types::ObjectiveEvent.from_json(event) }
  _auto_reconnect = !(request_options && request_options[:reconnect] == false)
  Stream.new(_decoder, last_event_id: last_event_id, skip_events: ["ping", "open"], auto_reconnect: _auto_reconnect) do |_cancel, _resume, &on_chunk|
    @core.stream_request(:get, _path, headers: (_resume ? { "Last-Event-ID" => _resume } : nil), request_options: request_options, cancel: _cancel, &on_chunk)
  end
end