robosystems-client 0.2.11__py3-none-any.whl → 0.2.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of robosystems-client might be problematic. Click here for more details.
- robosystems_client/api/agent/auto_select_agent.py +81 -9
- robosystems_client/api/agent/execute_specific_agent.py +73 -5
- robosystems_client/api/agent/get_agent_metadata.py +1 -1
- robosystems_client/api/agent/list_agents.py +1 -1
- robosystems_client/api/auth/register_user.py +36 -8
- robosystems_client/api/billing/{cancel_subscription.py → cancel_org_subscription.py} +34 -9
- robosystems_client/api/billing/create_checkout_session.py +28 -20
- robosystems_client/api/billing/get_org_billing_customer.py +189 -0
- robosystems_client/api/billing/{get_subscription.py → get_org_subscription.py} +30 -5
- robosystems_client/api/billing/{get_upcoming_invoice.py → get_org_upcoming_invoice.py} +68 -22
- robosystems_client/api/billing/{list_invoices.py → list_org_invoices.py} +38 -9
- robosystems_client/api/billing/{list_subscriptions.py → list_org_subscriptions.py} +64 -22
- robosystems_client/api/billing/{update_payment_method.py → update_org_payment_method.py} +34 -9
- robosystems_client/api/credits_/list_credit_transactions.py +4 -4
- robosystems_client/api/org/__init__.py +1 -0
- robosystems_client/api/org/create_org.py +174 -0
- robosystems_client/api/{billing/get_billing_customer.py → org/get_org.py} +50 -28
- robosystems_client/api/org/list_org_graphs.py +170 -0
- robosystems_client/api/{user/get_user_limits.py → org/list_user_orgs.py} +21 -25
- robosystems_client/api/org/update_org.py +187 -0
- robosystems_client/api/org_members/__init__.py +1 -0
- robosystems_client/api/org_members/invite_org_member.py +207 -0
- robosystems_client/api/org_members/list_org_members.py +165 -0
- robosystems_client/api/org_members/remove_org_member.py +176 -0
- robosystems_client/api/org_members/update_org_member_role.py +200 -0
- robosystems_client/api/org_usage/__init__.py +1 -0
- robosystems_client/api/org_usage/get_org_limits.py +165 -0
- robosystems_client/api/org_usage/get_org_usage.py +186 -0
- robosystems_client/api/service_offerings/get_service_offerings.py +32 -8
- robosystems_client/api/usage/get_graph_usage_analytics.py +4 -4
- robosystems_client/extensions/__init__.py +25 -0
- robosystems_client/extensions/agent_client.py +526 -0
- robosystems_client/extensions/extensions.py +3 -0
- robosystems_client/models/__init__.py +44 -6
- robosystems_client/models/auth_response.py +35 -0
- robosystems_client/models/{user_usage_response_graphs.py → auth_response_org_type_0.py} +6 -6
- robosystems_client/models/billing_customer.py +8 -8
- robosystems_client/models/checkout_response.py +65 -22
- robosystems_client/models/checkout_status_response.py +2 -1
- robosystems_client/models/create_checkout_request.py +2 -1
- robosystems_client/models/create_checkout_request_resource_config.py +4 -1
- robosystems_client/models/create_org_request.py +79 -0
- robosystems_client/models/graph_subscription_tier.py +40 -48
- robosystems_client/models/graph_subscriptions.py +17 -5
- robosystems_client/models/invite_member_request.py +93 -0
- robosystems_client/models/list_org_graphs_response_200_item.py +44 -0
- robosystems_client/models/org_detail_response.py +174 -0
- robosystems_client/models/org_detail_response_graphs_item.py +44 -0
- robosystems_client/models/org_detail_response_limits_type_0.py +44 -0
- robosystems_client/models/org_detail_response_members_item.py +44 -0
- robosystems_client/models/org_limits_response.py +98 -0
- robosystems_client/models/org_limits_response_current_usage.py +44 -0
- robosystems_client/models/org_list_response.py +82 -0
- robosystems_client/models/org_member_list_response.py +90 -0
- robosystems_client/models/org_member_response.py +104 -0
- robosystems_client/models/org_response.py +121 -0
- robosystems_client/models/org_role.py +10 -0
- robosystems_client/models/org_type.py +10 -0
- robosystems_client/models/org_usage_response.py +146 -0
- robosystems_client/models/org_usage_response_daily_trend_item.py +44 -0
- robosystems_client/models/org_usage_response_graph_details_item.py +44 -0
- robosystems_client/models/org_usage_summary.py +158 -0
- robosystems_client/models/repository_subscriptions.py +15 -4
- robosystems_client/models/service_offerings_response.py +15 -0
- robosystems_client/models/update_member_role_request.py +62 -0
- robosystems_client/models/update_org_request.py +103 -0
- {robosystems_client-0.2.11.dist-info → robosystems_client-0.2.13.dist-info}/METADATA +1 -1
- {robosystems_client-0.2.11.dist-info → robosystems_client-0.2.13.dist-info}/RECORD +70 -37
- robosystems_client/models/user_limits_response.py +0 -95
- robosystems_client/models/user_usage_response.py +0 -90
- {robosystems_client-0.2.11.dist-info → robosystems_client-0.2.13.dist-info}/WHEEL +0 -0
- {robosystems_client-0.2.11.dist-info → robosystems_client-0.2.13.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
"""Enhanced Agent Client with SSE support
|
|
2
|
+
|
|
3
|
+
Provides intelligent agent execution with automatic strategy selection.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Dict, Any, Optional, Callable
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
|
|
10
|
+
from ..api.agent.auto_select_agent import sync_detailed as auto_select_agent
|
|
11
|
+
from ..api.agent.execute_specific_agent import sync_detailed as execute_specific_agent
|
|
12
|
+
from ..models.agent_request import AgentRequest
|
|
13
|
+
from ..models.agent_message import AgentMessage
|
|
14
|
+
from .sse_client import SSEClient, SSEConfig, EventType
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class AgentQueryRequest:
|
|
19
|
+
"""Request object for agent queries"""
|
|
20
|
+
|
|
21
|
+
message: str
|
|
22
|
+
history: Optional[list] = None
|
|
23
|
+
context: Optional[Dict[str, Any]] = None
|
|
24
|
+
mode: Optional[str] = None # 'quick', 'standard', 'extended', 'streaming'
|
|
25
|
+
enable_rag: Optional[bool] = None
|
|
26
|
+
force_extended_analysis: Optional[bool] = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class AgentOptions:
|
|
31
|
+
"""Options for agent execution"""
|
|
32
|
+
|
|
33
|
+
mode: Optional[str] = "auto" # 'auto', 'sync', 'async'
|
|
34
|
+
max_wait: Optional[int] = None
|
|
35
|
+
on_progress: Optional[Callable[[str, Optional[int]], None]] = None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class AgentResult:
|
|
40
|
+
"""Result from agent execution"""
|
|
41
|
+
|
|
42
|
+
content: str
|
|
43
|
+
agent_used: str
|
|
44
|
+
mode_used: str
|
|
45
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
46
|
+
tokens_used: Optional[Dict[str, int]] = None
|
|
47
|
+
confidence_score: Optional[float] = None
|
|
48
|
+
execution_time: Optional[float] = None
|
|
49
|
+
timestamp: Optional[str] = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class QueuedAgentResponse:
|
|
54
|
+
"""Response when agent execution is queued"""
|
|
55
|
+
|
|
56
|
+
status: str
|
|
57
|
+
operation_id: str
|
|
58
|
+
message: str
|
|
59
|
+
sse_endpoint: Optional[str] = None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class QueuedAgentError(Exception):
|
|
63
|
+
"""Exception thrown when agent execution is queued and maxWait is 0"""
|
|
64
|
+
|
|
65
|
+
def __init__(self, queue_info: QueuedAgentResponse):
|
|
66
|
+
super().__init__("Agent execution was queued")
|
|
67
|
+
self.queue_info = queue_info
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class AgentClient:
|
|
71
|
+
"""Enhanced agent client with SSE streaming support"""
|
|
72
|
+
|
|
73
|
+
def __init__(self, config: Dict[str, Any]):
|
|
74
|
+
self.config = config
|
|
75
|
+
self.base_url = config["base_url"]
|
|
76
|
+
self.headers = config.get("headers", {})
|
|
77
|
+
self.token = config.get("token")
|
|
78
|
+
self.sse_client: Optional[SSEClient] = None
|
|
79
|
+
|
|
80
|
+
def execute_query(
|
|
81
|
+
self,
|
|
82
|
+
graph_id: str,
|
|
83
|
+
request: AgentQueryRequest,
|
|
84
|
+
options: AgentOptions = None,
|
|
85
|
+
) -> AgentResult:
|
|
86
|
+
"""Execute agent query with automatic agent selection"""
|
|
87
|
+
if options is None:
|
|
88
|
+
options = AgentOptions()
|
|
89
|
+
|
|
90
|
+
# Build request data
|
|
91
|
+
agent_request = AgentRequest(
|
|
92
|
+
message=request.message,
|
|
93
|
+
history=[
|
|
94
|
+
AgentMessage(role=msg["role"], content=msg["content"])
|
|
95
|
+
for msg in (request.history or [])
|
|
96
|
+
],
|
|
97
|
+
context=request.context,
|
|
98
|
+
mode=request.mode,
|
|
99
|
+
enable_rag=request.enable_rag,
|
|
100
|
+
force_extended_analysis=request.force_extended_analysis,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Execute through the generated client
|
|
104
|
+
from ..client import AuthenticatedClient
|
|
105
|
+
|
|
106
|
+
if not self.token:
|
|
107
|
+
raise Exception("No API key provided. Set X-API-Key in headers.")
|
|
108
|
+
|
|
109
|
+
client = AuthenticatedClient(
|
|
110
|
+
base_url=self.base_url,
|
|
111
|
+
token=self.token,
|
|
112
|
+
prefix="",
|
|
113
|
+
auth_header_name="X-API-Key",
|
|
114
|
+
headers=self.headers,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
try:
|
|
118
|
+
response = auto_select_agent(
|
|
119
|
+
graph_id=graph_id,
|
|
120
|
+
client=client,
|
|
121
|
+
body=agent_request,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Check response type and handle accordingly
|
|
125
|
+
if hasattr(response, "parsed") and response.parsed:
|
|
126
|
+
response_data = response.parsed
|
|
127
|
+
|
|
128
|
+
# Handle both dict and attrs object responses
|
|
129
|
+
if isinstance(response_data, dict):
|
|
130
|
+
data = response_data
|
|
131
|
+
else:
|
|
132
|
+
# Response is an attrs object
|
|
133
|
+
data = response_data
|
|
134
|
+
|
|
135
|
+
# Check if this is an immediate response (sync or SSE execution)
|
|
136
|
+
has_content = False
|
|
137
|
+
if isinstance(data, dict):
|
|
138
|
+
has_content = "content" in data and "agent_used" in data
|
|
139
|
+
else:
|
|
140
|
+
has_content = hasattr(data, "content") and hasattr(data, "agent_used")
|
|
141
|
+
|
|
142
|
+
if has_content:
|
|
143
|
+
# Extract data from either dict or attrs object
|
|
144
|
+
if isinstance(data, dict):
|
|
145
|
+
return AgentResult(
|
|
146
|
+
content=data["content"],
|
|
147
|
+
agent_used=data["agent_used"],
|
|
148
|
+
mode_used=data["mode_used"],
|
|
149
|
+
metadata=data.get("metadata"),
|
|
150
|
+
tokens_used=data.get("tokens_used"),
|
|
151
|
+
confidence_score=data.get("confidence_score"),
|
|
152
|
+
execution_time=data.get("execution_time"),
|
|
153
|
+
timestamp=data.get("timestamp", datetime.now().isoformat()),
|
|
154
|
+
)
|
|
155
|
+
else:
|
|
156
|
+
# attrs object - access attributes directly
|
|
157
|
+
from ..types import UNSET
|
|
158
|
+
|
|
159
|
+
return AgentResult(
|
|
160
|
+
content=data.content if data.content is not UNSET else "",
|
|
161
|
+
agent_used=data.agent_used if data.agent_used is not UNSET else "unknown",
|
|
162
|
+
mode_used=data.mode_used.value
|
|
163
|
+
if hasattr(data.mode_used, "value")
|
|
164
|
+
else data.mode_used
|
|
165
|
+
if data.mode_used is not UNSET
|
|
166
|
+
else "standard",
|
|
167
|
+
metadata=data.metadata if data.metadata is not UNSET else None,
|
|
168
|
+
tokens_used=data.tokens_used if data.tokens_used is not UNSET else None,
|
|
169
|
+
confidence_score=data.confidence_score
|
|
170
|
+
if data.confidence_score is not UNSET
|
|
171
|
+
else None,
|
|
172
|
+
execution_time=data.execution_time
|
|
173
|
+
if data.execution_time is not UNSET
|
|
174
|
+
else None,
|
|
175
|
+
timestamp=data.timestamp
|
|
176
|
+
if hasattr(data, "timestamp") and data.timestamp is not UNSET
|
|
177
|
+
else datetime.now().isoformat(),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Check if this is a queued response (async Celery execution)
|
|
181
|
+
is_queued = False
|
|
182
|
+
queued_response = None
|
|
183
|
+
|
|
184
|
+
if isinstance(data, dict):
|
|
185
|
+
is_queued = "operation_id" in data
|
|
186
|
+
if is_queued:
|
|
187
|
+
queued_response = QueuedAgentResponse(
|
|
188
|
+
status=data.get("status", "queued"),
|
|
189
|
+
operation_id=data["operation_id"],
|
|
190
|
+
message=data.get("message", "Agent execution queued"),
|
|
191
|
+
sse_endpoint=data.get("sse_endpoint"),
|
|
192
|
+
)
|
|
193
|
+
else:
|
|
194
|
+
is_queued = hasattr(data, "operation_id")
|
|
195
|
+
if is_queued:
|
|
196
|
+
from ..types import UNSET
|
|
197
|
+
|
|
198
|
+
queued_response = QueuedAgentResponse(
|
|
199
|
+
status=data.status if hasattr(data, "status") else "queued",
|
|
200
|
+
operation_id=data.operation_id,
|
|
201
|
+
message=data.message
|
|
202
|
+
if hasattr(data, "message") and data.message is not UNSET
|
|
203
|
+
else "Agent execution queued",
|
|
204
|
+
sse_endpoint=data.sse_endpoint
|
|
205
|
+
if hasattr(data, "sse_endpoint") and data.sse_endpoint is not UNSET
|
|
206
|
+
else None,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
if is_queued and queued_response:
|
|
210
|
+
# If user doesn't want to wait, raise with queue info
|
|
211
|
+
if options.max_wait == 0:
|
|
212
|
+
raise QueuedAgentError(queued_response)
|
|
213
|
+
|
|
214
|
+
# Use SSE to monitor the operation
|
|
215
|
+
return self._wait_for_agent_completion(queued_response.operation_id, options)
|
|
216
|
+
|
|
217
|
+
except Exception as e:
|
|
218
|
+
if isinstance(e, QueuedAgentError):
|
|
219
|
+
raise
|
|
220
|
+
|
|
221
|
+
error_msg = str(e)
|
|
222
|
+
# Check for authentication errors
|
|
223
|
+
if (
|
|
224
|
+
"401" in error_msg or "403" in error_msg or "unauthorized" in error_msg.lower()
|
|
225
|
+
):
|
|
226
|
+
raise Exception(f"Authentication failed during agent execution: {error_msg}")
|
|
227
|
+
else:
|
|
228
|
+
raise Exception(f"Agent execution failed: {error_msg}")
|
|
229
|
+
|
|
230
|
+
# Unexpected response format
|
|
231
|
+
raise Exception("Unexpected response format from agent endpoint")
|
|
232
|
+
|
|
233
|
+
def execute_agent(
|
|
234
|
+
self,
|
|
235
|
+
graph_id: str,
|
|
236
|
+
agent_type: str,
|
|
237
|
+
request: AgentQueryRequest,
|
|
238
|
+
options: AgentOptions = None,
|
|
239
|
+
) -> AgentResult:
|
|
240
|
+
"""Execute specific agent type"""
|
|
241
|
+
if options is None:
|
|
242
|
+
options = AgentOptions()
|
|
243
|
+
|
|
244
|
+
# Build request data
|
|
245
|
+
agent_request = AgentRequest(
|
|
246
|
+
message=request.message,
|
|
247
|
+
history=[
|
|
248
|
+
AgentMessage(role=msg["role"], content=msg["content"])
|
|
249
|
+
for msg in (request.history or [])
|
|
250
|
+
],
|
|
251
|
+
context=request.context,
|
|
252
|
+
mode=request.mode,
|
|
253
|
+
enable_rag=request.enable_rag,
|
|
254
|
+
force_extended_analysis=request.force_extended_analysis,
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
# Execute through the generated client
|
|
258
|
+
from ..client import AuthenticatedClient
|
|
259
|
+
|
|
260
|
+
if not self.token:
|
|
261
|
+
raise Exception("No API key provided. Set X-API-Key in headers.")
|
|
262
|
+
|
|
263
|
+
client = AuthenticatedClient(
|
|
264
|
+
base_url=self.base_url,
|
|
265
|
+
token=self.token,
|
|
266
|
+
prefix="",
|
|
267
|
+
auth_header_name="X-API-Key",
|
|
268
|
+
headers=self.headers,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
response = execute_specific_agent(
|
|
273
|
+
graph_id=graph_id,
|
|
274
|
+
agent_type=agent_type,
|
|
275
|
+
client=client,
|
|
276
|
+
body=agent_request,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
# Check response type and handle accordingly
|
|
280
|
+
if hasattr(response, "parsed") and response.parsed:
|
|
281
|
+
response_data = response.parsed
|
|
282
|
+
|
|
283
|
+
# Handle both dict and attrs object responses
|
|
284
|
+
if isinstance(response_data, dict):
|
|
285
|
+
data = response_data
|
|
286
|
+
else:
|
|
287
|
+
data = response_data
|
|
288
|
+
|
|
289
|
+
# Check if this is an immediate response
|
|
290
|
+
has_content = False
|
|
291
|
+
if isinstance(data, dict):
|
|
292
|
+
has_content = "content" in data and "agent_used" in data
|
|
293
|
+
else:
|
|
294
|
+
has_content = hasattr(data, "content") and hasattr(data, "agent_used")
|
|
295
|
+
|
|
296
|
+
if has_content:
|
|
297
|
+
# Extract data from either dict or attrs object
|
|
298
|
+
if isinstance(data, dict):
|
|
299
|
+
return AgentResult(
|
|
300
|
+
content=data["content"],
|
|
301
|
+
agent_used=data["agent_used"],
|
|
302
|
+
mode_used=data["mode_used"],
|
|
303
|
+
metadata=data.get("metadata"),
|
|
304
|
+
tokens_used=data.get("tokens_used"),
|
|
305
|
+
confidence_score=data.get("confidence_score"),
|
|
306
|
+
execution_time=data.get("execution_time"),
|
|
307
|
+
timestamp=data.get("timestamp", datetime.now().isoformat()),
|
|
308
|
+
)
|
|
309
|
+
else:
|
|
310
|
+
# attrs object
|
|
311
|
+
from ..types import UNSET
|
|
312
|
+
|
|
313
|
+
return AgentResult(
|
|
314
|
+
content=data.content if data.content is not UNSET else "",
|
|
315
|
+
agent_used=data.agent_used if data.agent_used is not UNSET else "unknown",
|
|
316
|
+
mode_used=data.mode_used.value
|
|
317
|
+
if hasattr(data.mode_used, "value")
|
|
318
|
+
else data.mode_used
|
|
319
|
+
if data.mode_used is not UNSET
|
|
320
|
+
else "standard",
|
|
321
|
+
metadata=data.metadata if data.metadata is not UNSET else None,
|
|
322
|
+
tokens_used=data.tokens_used if data.tokens_used is not UNSET else None,
|
|
323
|
+
confidence_score=data.confidence_score
|
|
324
|
+
if data.confidence_score is not UNSET
|
|
325
|
+
else None,
|
|
326
|
+
execution_time=data.execution_time
|
|
327
|
+
if data.execution_time is not UNSET
|
|
328
|
+
else None,
|
|
329
|
+
timestamp=data.timestamp
|
|
330
|
+
if hasattr(data, "timestamp") and data.timestamp is not UNSET
|
|
331
|
+
else datetime.now().isoformat(),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
# Check if this is a queued response
|
|
335
|
+
is_queued = False
|
|
336
|
+
queued_response = None
|
|
337
|
+
|
|
338
|
+
if isinstance(data, dict):
|
|
339
|
+
is_queued = "operation_id" in data
|
|
340
|
+
if is_queued:
|
|
341
|
+
queued_response = QueuedAgentResponse(
|
|
342
|
+
status=data.get("status", "queued"),
|
|
343
|
+
operation_id=data["operation_id"],
|
|
344
|
+
message=data.get("message", "Agent execution queued"),
|
|
345
|
+
sse_endpoint=data.get("sse_endpoint"),
|
|
346
|
+
)
|
|
347
|
+
else:
|
|
348
|
+
is_queued = hasattr(data, "operation_id")
|
|
349
|
+
if is_queued:
|
|
350
|
+
from ..types import UNSET
|
|
351
|
+
|
|
352
|
+
queued_response = QueuedAgentResponse(
|
|
353
|
+
status=data.status if hasattr(data, "status") else "queued",
|
|
354
|
+
operation_id=data.operation_id,
|
|
355
|
+
message=data.message
|
|
356
|
+
if hasattr(data, "message") and data.message is not UNSET
|
|
357
|
+
else "Agent execution queued",
|
|
358
|
+
sse_endpoint=data.sse_endpoint
|
|
359
|
+
if hasattr(data, "sse_endpoint") and data.sse_endpoint is not UNSET
|
|
360
|
+
else None,
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
if is_queued and queued_response:
|
|
364
|
+
# If user doesn't want to wait, raise with queue info
|
|
365
|
+
if options.max_wait == 0:
|
|
366
|
+
raise QueuedAgentError(queued_response)
|
|
367
|
+
|
|
368
|
+
# Use SSE to monitor the operation
|
|
369
|
+
return self._wait_for_agent_completion(queued_response.operation_id, options)
|
|
370
|
+
|
|
371
|
+
except Exception as e:
|
|
372
|
+
if isinstance(e, QueuedAgentError):
|
|
373
|
+
raise
|
|
374
|
+
|
|
375
|
+
error_msg = str(e)
|
|
376
|
+
if (
|
|
377
|
+
"401" in error_msg or "403" in error_msg or "unauthorized" in error_msg.lower()
|
|
378
|
+
):
|
|
379
|
+
raise Exception(f"Authentication failed during agent execution: {error_msg}")
|
|
380
|
+
else:
|
|
381
|
+
raise Exception(f"Agent execution failed: {error_msg}")
|
|
382
|
+
|
|
383
|
+
# Unexpected response format
|
|
384
|
+
raise Exception("Unexpected response format from agent endpoint")
|
|
385
|
+
|
|
386
|
+
def _wait_for_agent_completion(
|
|
387
|
+
self, operation_id: str, options: AgentOptions
|
|
388
|
+
) -> AgentResult:
|
|
389
|
+
"""Wait for agent completion and return final result"""
|
|
390
|
+
result = None
|
|
391
|
+
error = None
|
|
392
|
+
completed = False
|
|
393
|
+
|
|
394
|
+
# Set up SSE connection
|
|
395
|
+
sse_config = SSEConfig(base_url=self.base_url, headers=self.headers)
|
|
396
|
+
sse_client = SSEClient(sse_config)
|
|
397
|
+
|
|
398
|
+
def on_progress(data):
|
|
399
|
+
if options.on_progress:
|
|
400
|
+
options.on_progress(
|
|
401
|
+
data.get("message", "Processing..."), data.get("percentage")
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
def on_agent_started(data):
|
|
405
|
+
if options.on_progress:
|
|
406
|
+
options.on_progress(f"Agent {data.get('agent_type')} started", 0)
|
|
407
|
+
|
|
408
|
+
def on_agent_initialized(data):
|
|
409
|
+
if options.on_progress:
|
|
410
|
+
options.on_progress(f"{data.get('agent_name')} initialized", 10)
|
|
411
|
+
|
|
412
|
+
def on_agent_completed(data):
|
|
413
|
+
nonlocal result, completed
|
|
414
|
+
result = AgentResult(
|
|
415
|
+
content=data.get("content", ""),
|
|
416
|
+
agent_used=data.get("agent_used", "unknown"),
|
|
417
|
+
mode_used=data.get("mode_used", "standard"),
|
|
418
|
+
metadata=data.get("metadata"),
|
|
419
|
+
tokens_used=data.get("tokens_used"),
|
|
420
|
+
confidence_score=data.get("confidence_score"),
|
|
421
|
+
execution_time=data.get("execution_time"),
|
|
422
|
+
timestamp=data.get("timestamp", datetime.now().isoformat()),
|
|
423
|
+
)
|
|
424
|
+
completed = True
|
|
425
|
+
|
|
426
|
+
def on_completed(data):
|
|
427
|
+
nonlocal result, completed
|
|
428
|
+
if not result:
|
|
429
|
+
# Fallback to generic completion event
|
|
430
|
+
agent_result = data.get("result", data)
|
|
431
|
+
result = AgentResult(
|
|
432
|
+
content=agent_result.get("content", ""),
|
|
433
|
+
agent_used=agent_result.get("agent_used", "unknown"),
|
|
434
|
+
mode_used=agent_result.get("mode_used", "standard"),
|
|
435
|
+
metadata=agent_result.get("metadata"),
|
|
436
|
+
tokens_used=agent_result.get("tokens_used"),
|
|
437
|
+
confidence_score=agent_result.get("confidence_score"),
|
|
438
|
+
execution_time=agent_result.get("execution_time"),
|
|
439
|
+
timestamp=agent_result.get("timestamp", datetime.now().isoformat()),
|
|
440
|
+
)
|
|
441
|
+
completed = True
|
|
442
|
+
|
|
443
|
+
def on_error(err):
|
|
444
|
+
nonlocal error, completed
|
|
445
|
+
error = Exception(err.get("message", err.get("error", "Unknown error")))
|
|
446
|
+
completed = True
|
|
447
|
+
|
|
448
|
+
def on_cancelled():
|
|
449
|
+
nonlocal error, completed
|
|
450
|
+
error = Exception("Agent execution cancelled")
|
|
451
|
+
completed = True
|
|
452
|
+
|
|
453
|
+
# Register event handlers
|
|
454
|
+
sse_client.on(EventType.OPERATION_PROGRESS.value, on_progress)
|
|
455
|
+
sse_client.on("agent_started", on_agent_started)
|
|
456
|
+
sse_client.on("agent_initialized", on_agent_initialized)
|
|
457
|
+
sse_client.on("progress", on_progress)
|
|
458
|
+
sse_client.on("agent_completed", on_agent_completed)
|
|
459
|
+
sse_client.on(EventType.OPERATION_COMPLETED.value, on_completed)
|
|
460
|
+
sse_client.on(EventType.OPERATION_ERROR.value, on_error)
|
|
461
|
+
sse_client.on("error", on_error)
|
|
462
|
+
sse_client.on(EventType.OPERATION_CANCELLED.value, on_cancelled)
|
|
463
|
+
|
|
464
|
+
# Connect and wait
|
|
465
|
+
sse_client.connect(operation_id)
|
|
466
|
+
|
|
467
|
+
# Wait for completion
|
|
468
|
+
import time
|
|
469
|
+
|
|
470
|
+
while not completed:
|
|
471
|
+
if error:
|
|
472
|
+
sse_client.close()
|
|
473
|
+
raise error
|
|
474
|
+
time.sleep(0.1)
|
|
475
|
+
|
|
476
|
+
sse_client.close()
|
|
477
|
+
return result
|
|
478
|
+
|
|
479
|
+
def query(
|
|
480
|
+
self, graph_id: str, message: str, context: Dict[str, Any] = None
|
|
481
|
+
) -> AgentResult:
|
|
482
|
+
"""Convenience method for simple agent queries with auto-selection"""
|
|
483
|
+
request = AgentQueryRequest(message=message, context=context)
|
|
484
|
+
return self.execute_query(graph_id, request, AgentOptions(mode="auto"))
|
|
485
|
+
|
|
486
|
+
def analyze_financials(
|
|
487
|
+
self,
|
|
488
|
+
graph_id: str,
|
|
489
|
+
message: str,
|
|
490
|
+
on_progress: Optional[Callable[[str, Optional[int]], None]] = None,
|
|
491
|
+
) -> AgentResult:
|
|
492
|
+
"""Execute financial agent for financial analysis"""
|
|
493
|
+
request = AgentQueryRequest(message=message)
|
|
494
|
+
return self.execute_agent(
|
|
495
|
+
graph_id, "financial", request, AgentOptions(on_progress=on_progress)
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
def research(
|
|
499
|
+
self,
|
|
500
|
+
graph_id: str,
|
|
501
|
+
message: str,
|
|
502
|
+
on_progress: Optional[Callable[[str, Optional[int]], None]] = None,
|
|
503
|
+
) -> AgentResult:
|
|
504
|
+
"""Execute research agent for deep research"""
|
|
505
|
+
request = AgentQueryRequest(message=message)
|
|
506
|
+
return self.execute_agent(
|
|
507
|
+
graph_id, "research", request, AgentOptions(on_progress=on_progress)
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
def rag(
|
|
511
|
+
self,
|
|
512
|
+
graph_id: str,
|
|
513
|
+
message: str,
|
|
514
|
+
on_progress: Optional[Callable[[str, Optional[int]], None]] = None,
|
|
515
|
+
) -> AgentResult:
|
|
516
|
+
"""Execute RAG agent for fast retrieval"""
|
|
517
|
+
request = AgentQueryRequest(message=message)
|
|
518
|
+
return self.execute_agent(
|
|
519
|
+
graph_id, "rag", request, AgentOptions(on_progress=on_progress)
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
def close(self):
|
|
523
|
+
"""Cancel any active SSE connections"""
|
|
524
|
+
if self.sse_client:
|
|
525
|
+
self.sse_client.close()
|
|
526
|
+
self.sse_client = None
|
|
@@ -7,6 +7,7 @@ from dataclasses import dataclass
|
|
|
7
7
|
from typing import Dict, Any, Optional, Callable
|
|
8
8
|
|
|
9
9
|
from .query_client import QueryClient
|
|
10
|
+
from .agent_client import AgentClient
|
|
10
11
|
from .operation_client import OperationClient
|
|
11
12
|
from .table_ingest_client import TableIngestClient
|
|
12
13
|
from .graph_client import GraphClient
|
|
@@ -58,6 +59,7 @@ class RoboSystemsExtensions:
|
|
|
58
59
|
|
|
59
60
|
# Initialize clients
|
|
60
61
|
self.query = QueryClient(self.config)
|
|
62
|
+
self.agent = AgentClient(self.config)
|
|
61
63
|
self.operations = OperationClient(self.config)
|
|
62
64
|
self.tables = TableIngestClient(self.config)
|
|
63
65
|
self.graphs = GraphClient(self.config)
|
|
@@ -88,6 +90,7 @@ class RoboSystemsExtensions:
|
|
|
88
90
|
def close(self):
|
|
89
91
|
"""Clean up all active connections"""
|
|
90
92
|
self.query.close()
|
|
93
|
+
self.agent.close()
|
|
91
94
|
self.operations.close_all()
|
|
92
95
|
self.tables.close()
|
|
93
96
|
self.graphs.close()
|
|
@@ -24,6 +24,7 @@ from .agent_response_tokens_used_type_0 import AgentResponseTokensUsedType0
|
|
|
24
24
|
from .api_key_info import APIKeyInfo
|
|
25
25
|
from .api_keys_response import APIKeysResponse
|
|
26
26
|
from .auth_response import AuthResponse
|
|
27
|
+
from .auth_response_org_type_0 import AuthResponseOrgType0
|
|
27
28
|
from .auth_response_user import AuthResponseUser
|
|
28
29
|
from .available_extension import AvailableExtension
|
|
29
30
|
from .available_extensions_response import AvailableExtensionsResponse
|
|
@@ -65,6 +66,7 @@ from .create_checkout_request_resource_config import CreateCheckoutRequestResour
|
|
|
65
66
|
from .create_connection_request import CreateConnectionRequest
|
|
66
67
|
from .create_connection_request_provider import CreateConnectionRequestProvider
|
|
67
68
|
from .create_graph_request import CreateGraphRequest
|
|
69
|
+
from .create_org_request import CreateOrgRequest
|
|
68
70
|
from .create_repository_subscription_request import CreateRepositorySubscriptionRequest
|
|
69
71
|
from .create_subgraph_request import CreateSubgraphRequest
|
|
70
72
|
from .create_subgraph_request_metadata_type_0 import CreateSubgraphRequestMetadataType0
|
|
@@ -144,6 +146,7 @@ from .health_status import HealthStatus
|
|
|
144
146
|
from .health_status_details_type_0 import HealthStatusDetailsType0
|
|
145
147
|
from .http_validation_error import HTTPValidationError
|
|
146
148
|
from .initial_entity_data import InitialEntityData
|
|
149
|
+
from .invite_member_request import InviteMemberRequest
|
|
147
150
|
from .invoice import Invoice
|
|
148
151
|
from .invoice_line_item import InvoiceLineItem
|
|
149
152
|
from .invoices_response import InvoicesResponse
|
|
@@ -151,6 +154,7 @@ from .link_token_request import LinkTokenRequest
|
|
|
151
154
|
from .link_token_request_options_type_0 import LinkTokenRequestOptionsType0
|
|
152
155
|
from .link_token_request_provider_type_0 import LinkTokenRequestProviderType0
|
|
153
156
|
from .list_connections_provider_type_0 import ListConnectionsProviderType0
|
|
157
|
+
from .list_org_graphs_response_200_item import ListOrgGraphsResponse200Item
|
|
154
158
|
from .list_subgraphs_response import ListSubgraphsResponse
|
|
155
159
|
from .list_table_files_response import ListTableFilesResponse
|
|
156
160
|
from .login_request import LoginRequest
|
|
@@ -172,6 +176,22 @@ from .offering_repository_plan_rate_limits_type_0 import (
|
|
|
172
176
|
from .operation_costs import OperationCosts
|
|
173
177
|
from .operation_costs_ai_operations import OperationCostsAiOperations
|
|
174
178
|
from .operation_costs_token_pricing import OperationCostsTokenPricing
|
|
179
|
+
from .org_detail_response import OrgDetailResponse
|
|
180
|
+
from .org_detail_response_graphs_item import OrgDetailResponseGraphsItem
|
|
181
|
+
from .org_detail_response_limits_type_0 import OrgDetailResponseLimitsType0
|
|
182
|
+
from .org_detail_response_members_item import OrgDetailResponseMembersItem
|
|
183
|
+
from .org_limits_response import OrgLimitsResponse
|
|
184
|
+
from .org_limits_response_current_usage import OrgLimitsResponseCurrentUsage
|
|
185
|
+
from .org_list_response import OrgListResponse
|
|
186
|
+
from .org_member_list_response import OrgMemberListResponse
|
|
187
|
+
from .org_member_response import OrgMemberResponse
|
|
188
|
+
from .org_response import OrgResponse
|
|
189
|
+
from .org_role import OrgRole
|
|
190
|
+
from .org_type import OrgType
|
|
191
|
+
from .org_usage_response import OrgUsageResponse
|
|
192
|
+
from .org_usage_response_daily_trend_item import OrgUsageResponseDailyTrendItem
|
|
193
|
+
from .org_usage_response_graph_details_item import OrgUsageResponseGraphDetailsItem
|
|
194
|
+
from .org_usage_summary import OrgUsageSummary
|
|
175
195
|
from .password_check_request import PasswordCheckRequest
|
|
176
196
|
from .password_check_response import PasswordCheckResponse
|
|
177
197
|
from .password_check_response_character_types import PasswordCheckResponseCharacterTypes
|
|
@@ -256,16 +276,15 @@ from .update_api_key_request import UpdateAPIKeyRequest
|
|
|
256
276
|
from .update_file_status_response_updatefilestatus import (
|
|
257
277
|
UpdateFileStatusResponseUpdatefilestatus,
|
|
258
278
|
)
|
|
279
|
+
from .update_member_role_request import UpdateMemberRoleRequest
|
|
280
|
+
from .update_org_request import UpdateOrgRequest
|
|
259
281
|
from .update_password_request import UpdatePasswordRequest
|
|
260
282
|
from .update_payment_method_request import UpdatePaymentMethodRequest
|
|
261
283
|
from .update_payment_method_response import UpdatePaymentMethodResponse
|
|
262
284
|
from .update_user_request import UpdateUserRequest
|
|
263
285
|
from .upgrade_subscription_request import UpgradeSubscriptionRequest
|
|
264
286
|
from .user_graphs_response import UserGraphsResponse
|
|
265
|
-
from .user_limits_response import UserLimitsResponse
|
|
266
287
|
from .user_response import UserResponse
|
|
267
|
-
from .user_usage_response import UserUsageResponse
|
|
268
|
-
from .user_usage_response_graphs import UserUsageResponseGraphs
|
|
269
288
|
from .validation_error import ValidationError
|
|
270
289
|
|
|
271
290
|
__all__ = (
|
|
@@ -289,6 +308,7 @@ __all__ = (
|
|
|
289
308
|
"APIKeyInfo",
|
|
290
309
|
"APIKeysResponse",
|
|
291
310
|
"AuthResponse",
|
|
311
|
+
"AuthResponseOrgType0",
|
|
292
312
|
"AuthResponseUser",
|
|
293
313
|
"AvailableExtension",
|
|
294
314
|
"AvailableExtensionsResponse",
|
|
@@ -326,6 +346,7 @@ __all__ = (
|
|
|
326
346
|
"CreateConnectionRequest",
|
|
327
347
|
"CreateConnectionRequestProvider",
|
|
328
348
|
"CreateGraphRequest",
|
|
349
|
+
"CreateOrgRequest",
|
|
329
350
|
"CreateRepositorySubscriptionRequest",
|
|
330
351
|
"CreateSubgraphRequest",
|
|
331
352
|
"CreateSubgraphRequestMetadataType0",
|
|
@@ -387,6 +408,7 @@ __all__ = (
|
|
|
387
408
|
"HealthStatusDetailsType0",
|
|
388
409
|
"HTTPValidationError",
|
|
389
410
|
"InitialEntityData",
|
|
411
|
+
"InviteMemberRequest",
|
|
390
412
|
"Invoice",
|
|
391
413
|
"InvoiceLineItem",
|
|
392
414
|
"InvoicesResponse",
|
|
@@ -394,6 +416,7 @@ __all__ = (
|
|
|
394
416
|
"LinkTokenRequestOptionsType0",
|
|
395
417
|
"LinkTokenRequestProviderType0",
|
|
396
418
|
"ListConnectionsProviderType0",
|
|
419
|
+
"ListOrgGraphsResponse200Item",
|
|
397
420
|
"ListSubgraphsResponse",
|
|
398
421
|
"ListTableFilesResponse",
|
|
399
422
|
"LoginRequest",
|
|
@@ -411,6 +434,22 @@ __all__ = (
|
|
|
411
434
|
"OperationCosts",
|
|
412
435
|
"OperationCostsAiOperations",
|
|
413
436
|
"OperationCostsTokenPricing",
|
|
437
|
+
"OrgDetailResponse",
|
|
438
|
+
"OrgDetailResponseGraphsItem",
|
|
439
|
+
"OrgDetailResponseLimitsType0",
|
|
440
|
+
"OrgDetailResponseMembersItem",
|
|
441
|
+
"OrgLimitsResponse",
|
|
442
|
+
"OrgLimitsResponseCurrentUsage",
|
|
443
|
+
"OrgListResponse",
|
|
444
|
+
"OrgMemberListResponse",
|
|
445
|
+
"OrgMemberResponse",
|
|
446
|
+
"OrgResponse",
|
|
447
|
+
"OrgRole",
|
|
448
|
+
"OrgType",
|
|
449
|
+
"OrgUsageResponse",
|
|
450
|
+
"OrgUsageResponseDailyTrendItem",
|
|
451
|
+
"OrgUsageResponseGraphDetailsItem",
|
|
452
|
+
"OrgUsageSummary",
|
|
414
453
|
"PasswordCheckRequest",
|
|
415
454
|
"PasswordCheckResponse",
|
|
416
455
|
"PasswordCheckResponseCharacterTypes",
|
|
@@ -477,15 +516,14 @@ __all__ = (
|
|
|
477
516
|
"UpcomingInvoice",
|
|
478
517
|
"UpdateAPIKeyRequest",
|
|
479
518
|
"UpdateFileStatusResponseUpdatefilestatus",
|
|
519
|
+
"UpdateMemberRoleRequest",
|
|
520
|
+
"UpdateOrgRequest",
|
|
480
521
|
"UpdatePasswordRequest",
|
|
481
522
|
"UpdatePaymentMethodRequest",
|
|
482
523
|
"UpdatePaymentMethodResponse",
|
|
483
524
|
"UpdateUserRequest",
|
|
484
525
|
"UpgradeSubscriptionRequest",
|
|
485
526
|
"UserGraphsResponse",
|
|
486
|
-
"UserLimitsResponse",
|
|
487
527
|
"UserResponse",
|
|
488
|
-
"UserUsageResponse",
|
|
489
|
-
"UserUsageResponseGraphs",
|
|
490
528
|
"ValidationError",
|
|
491
529
|
)
|