meshagent-tools 0.20.5__py3-none-any.whl → 0.21.0__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.
- meshagent/tools/database.py +181 -1
- meshagent/tools/version.py +1 -1
- {meshagent_tools-0.20.5.dist-info → meshagent_tools-0.21.0.dist-info}/METADATA +2 -2
- {meshagent_tools-0.20.5.dist-info → meshagent_tools-0.21.0.dist-info}/RECORD +7 -7
- {meshagent_tools-0.20.5.dist-info → meshagent_tools-0.21.0.dist-info}/WHEEL +0 -0
- {meshagent_tools-0.20.5.dist-info → meshagent_tools-0.21.0.dist-info}/licenses/LICENSE +0 -0
- {meshagent_tools-0.20.5.dist-info → meshagent_tools-0.21.0.dist-info}/top_level.txt +0 -0
meshagent/tools/database.py
CHANGED
|
@@ -5,6 +5,10 @@ from .hosting import RemoteToolkit, Toolkit
|
|
|
5
5
|
from typing import Literal, Optional
|
|
6
6
|
from meshagent.api.room_server_client import DataType, RoomClient
|
|
7
7
|
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger("database_toolkit")
|
|
11
|
+
|
|
8
12
|
|
|
9
13
|
class ListTablesTool(Tool):
|
|
10
14
|
def __init__(self):
|
|
@@ -208,7 +212,6 @@ class SearchTool(Tool):
|
|
|
208
212
|
},
|
|
209
213
|
}
|
|
210
214
|
|
|
211
|
-
print(input_schema)
|
|
212
215
|
super().__init__(
|
|
213
216
|
name=f"search_{table}",
|
|
214
217
|
title=f"search {table}",
|
|
@@ -242,6 +245,183 @@ class SearchTool(Tool):
|
|
|
242
245
|
}
|
|
243
246
|
|
|
244
247
|
|
|
248
|
+
class LLMßSearchTool(Tool):
|
|
249
|
+
def __init__(
|
|
250
|
+
self,
|
|
251
|
+
*,
|
|
252
|
+
table: str,
|
|
253
|
+
schema: dict[str, DataType],
|
|
254
|
+
namespace: Optional[list[str]] = None,
|
|
255
|
+
):
|
|
256
|
+
self.table = table
|
|
257
|
+
self.namespace = namespace
|
|
258
|
+
|
|
259
|
+
query = {
|
|
260
|
+
"type": "object",
|
|
261
|
+
"required": [],
|
|
262
|
+
"additionalProperties": False,
|
|
263
|
+
"properties": {},
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for k, v in schema.items():
|
|
267
|
+
query["required"].append(k)
|
|
268
|
+
query["properties"][k] = v.to_json_schema()
|
|
269
|
+
|
|
270
|
+
input_schema = {
|
|
271
|
+
"type": "object",
|
|
272
|
+
"required": ["query", "limit", "offset", "select"],
|
|
273
|
+
"additionalProperties": False,
|
|
274
|
+
"properties": {
|
|
275
|
+
"query": query,
|
|
276
|
+
"select": {
|
|
277
|
+
"type": "array",
|
|
278
|
+
"description": f"the columns to return, available columns: {','.join(schema.keys())}",
|
|
279
|
+
"items": {
|
|
280
|
+
"type": "string",
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
"limit": {"type": "integer"},
|
|
284
|
+
"offset": {"type": "integer"},
|
|
285
|
+
},
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
super().__init__(
|
|
289
|
+
name=f"search_{table}",
|
|
290
|
+
title=f"search {table}",
|
|
291
|
+
description=f"search {table} table for rows with the specified values (specify null for a column to exclude it from the search)",
|
|
292
|
+
input_schema=input_schema,
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
async def execute(
|
|
296
|
+
self,
|
|
297
|
+
context: ToolContext,
|
|
298
|
+
query: object,
|
|
299
|
+
limit: int,
|
|
300
|
+
offset: int,
|
|
301
|
+
select: list[str],
|
|
302
|
+
):
|
|
303
|
+
search = {}
|
|
304
|
+
|
|
305
|
+
for k, v in query.items():
|
|
306
|
+
if v is not None:
|
|
307
|
+
search[k] = v
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
"rows": await context.room.database.search(
|
|
311
|
+
select=select,
|
|
312
|
+
table=self.table,
|
|
313
|
+
where=search if len(search) > 0 else None,
|
|
314
|
+
namespace=self.namespace,
|
|
315
|
+
offset=offset,
|
|
316
|
+
limit=limit,
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class SpawnTaskForEachRow(Tool):
|
|
322
|
+
def __init__(
|
|
323
|
+
self,
|
|
324
|
+
*,
|
|
325
|
+
table: str,
|
|
326
|
+
schema: dict[str, DataType],
|
|
327
|
+
prompt: str,
|
|
328
|
+
queue: str,
|
|
329
|
+
namespace: Optional[list[str]] = None,
|
|
330
|
+
name: Optional[str] = None,
|
|
331
|
+
title: Optional[str] = None,
|
|
332
|
+
description: Optional[str] = None,
|
|
333
|
+
supports_context: bool = True,
|
|
334
|
+
):
|
|
335
|
+
self.table = table
|
|
336
|
+
self.namespace = namespace
|
|
337
|
+
self.queue = queue
|
|
338
|
+
self.prompt = prompt
|
|
339
|
+
|
|
340
|
+
query = {
|
|
341
|
+
"type": "object",
|
|
342
|
+
"required": [],
|
|
343
|
+
"additionalProperties": False,
|
|
344
|
+
"properties": {},
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
for k, v in schema.items():
|
|
348
|
+
query["required"].append(k)
|
|
349
|
+
query["properties"][k] = v.to_json_schema()
|
|
350
|
+
|
|
351
|
+
input_schema = {
|
|
352
|
+
"type": "object",
|
|
353
|
+
"required": ["query", "limit", "offset", "select"],
|
|
354
|
+
"additionalProperties": False,
|
|
355
|
+
"properties": {
|
|
356
|
+
"query": query,
|
|
357
|
+
"select": {
|
|
358
|
+
"type": "array",
|
|
359
|
+
"description": f"the columns to return, available columns: {','.join(schema.keys())}",
|
|
360
|
+
"items": {
|
|
361
|
+
"type": "string",
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
"limit": {"type": "integer"},
|
|
365
|
+
"offset": {"type": "integer"},
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
print(input_schema)
|
|
370
|
+
super().__init__(
|
|
371
|
+
name=name or f"spawn_task_for_each_{table}_row",
|
|
372
|
+
title=title or f"Spawn task for each {table} row",
|
|
373
|
+
description=description
|
|
374
|
+
or f"for each result in {table} where rows match the specified values (specify null for a column to exclude it from the search), queue a worker task",
|
|
375
|
+
input_schema=input_schema,
|
|
376
|
+
supports_context=supports_context,
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
def make_message(self, *, context: ToolContext, row: dict):
|
|
380
|
+
msg = {
|
|
381
|
+
"prompt": self.prompt.format(**row),
|
|
382
|
+
"row": row,
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if self.supports_context:
|
|
386
|
+
msg["caller_context"] = context.caller_context
|
|
387
|
+
|
|
388
|
+
return msg
|
|
389
|
+
|
|
390
|
+
async def execute(
|
|
391
|
+
self,
|
|
392
|
+
context: ToolContext,
|
|
393
|
+
query: object,
|
|
394
|
+
limit: int,
|
|
395
|
+
offset: int,
|
|
396
|
+
select: list[str],
|
|
397
|
+
):
|
|
398
|
+
search = {}
|
|
399
|
+
|
|
400
|
+
for k, v in query.items():
|
|
401
|
+
if v is not None:
|
|
402
|
+
search[k] = v
|
|
403
|
+
|
|
404
|
+
rows = await context.room.database.search(
|
|
405
|
+
select=select,
|
|
406
|
+
table=self.table,
|
|
407
|
+
where=search if len(search) > 0 else None,
|
|
408
|
+
namespace=self.namespace,
|
|
409
|
+
offset=offset,
|
|
410
|
+
limit=limit,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
logger.info(
|
|
414
|
+
f"spawn_task_for_each_{self.table}_row matched {len(rows)}. adding items to the queue {self.queue}"
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
for row in rows:
|
|
418
|
+
await context.room.queues.send(
|
|
419
|
+
name=self.queue, message=self.make_message(context=context, row=row)
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
return {f"added {len(row)} items to the queue {self.queue}"}
|
|
423
|
+
|
|
424
|
+
|
|
245
425
|
class CountTool(Tool):
|
|
246
426
|
def __init__(
|
|
247
427
|
self,
|
meshagent/tools/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.21.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meshagent-tools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.21.0
|
|
4
4
|
Summary: Tools for Meshagent
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Documentation, https://docs.meshagent.com
|
|
@@ -12,7 +12,7 @@ License-File: LICENSE
|
|
|
12
12
|
Requires-Dist: pyjwt~=2.10
|
|
13
13
|
Requires-Dist: pytest~=8.4
|
|
14
14
|
Requires-Dist: pytest-asyncio~=0.26
|
|
15
|
-
Requires-Dist: meshagent-api~=0.
|
|
15
|
+
Requires-Dist: meshagent-api~=0.21.0
|
|
16
16
|
Requires-Dist: aiohttp~=3.10
|
|
17
17
|
Requires-Dist: opentelemetry-distro~=0.54b1
|
|
18
18
|
Dynamic: license-file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
meshagent/tools/__init__.py,sha256=1zgD5OvAJP10eERoE72VbDu9hFVfAqCWUXw3SiCYFTE,1285
|
|
2
2
|
meshagent/tools/blob.py,sha256=aDW_z8R4HrmrYzAWoWm13Ypqcxcl4rL1Dc0ESnQETLM,1473
|
|
3
3
|
meshagent/tools/config.py,sha256=zH2xGxg28K7Tg-aYor6LXdzf0LRxS9iE0679H1FuWhE,79
|
|
4
|
-
meshagent/tools/database.py,sha256=
|
|
4
|
+
meshagent/tools/database.py,sha256=YpCuLsLRcaDec1KAN9ax1-3dun-iSbVIUHVTM9B-3lg,18116
|
|
5
5
|
meshagent/tools/datetime.py,sha256=2pOUOWopYIsc5y4EoFo_1PdBaBcTSkeOOs_EqdqYTk0,17503
|
|
6
6
|
meshagent/tools/discovery.py,sha256=GZcC4XCgk0ftcYCBxuWlaIsLV5vU4-gXiu0HhlDUlwY,1861
|
|
7
7
|
meshagent/tools/document_tools.py,sha256=LMULXOSBjsvhKjqzxUxe8586t0Vol0v1Btu5v6ofm7A,11755
|
|
@@ -13,10 +13,10 @@ meshagent/tools/strict_schema.py,sha256=IytdAANa6lsfrsg5FsJuqYrxH9D_fayl-Lc9EwgL
|
|
|
13
13
|
meshagent/tools/tool.py,sha256=9OAlbfaHqfgJnCDBSW-8PS0Z1K1KjWGD3JBUyiHOxAk,3131
|
|
14
14
|
meshagent/tools/toolkit.py,sha256=rCCkpQBoSkmmhjnRGA4jx0QP-ds6WTJ0PkQVnf1Ls7s,3843
|
|
15
15
|
meshagent/tools/uuid.py,sha256=mzRwDmXy39U5lHhd9wqV4r-ZdS8jPfDTTs4UfW4KHJQ,1342
|
|
16
|
-
meshagent/tools/version.py,sha256
|
|
16
|
+
meshagent/tools/version.py,sha256=-reNiXr25nUU7em7_IKJzimCI10W4nA8ouxAiOr4FaQ,23
|
|
17
17
|
meshagent/tools/web_toolkit.py,sha256=IoOYjOBmcbQsqWT14xYg02jjWpWmGOkDSxt2U-LQoaA,1258
|
|
18
|
-
meshagent_tools-0.
|
|
19
|
-
meshagent_tools-0.
|
|
20
|
-
meshagent_tools-0.
|
|
21
|
-
meshagent_tools-0.
|
|
22
|
-
meshagent_tools-0.
|
|
18
|
+
meshagent_tools-0.21.0.dist-info/licenses/LICENSE,sha256=eTt0SPW-sVNdkZe9PS_S8WfCIyLjRXRl7sUBWdlteFg,10254
|
|
19
|
+
meshagent_tools-0.21.0.dist-info/METADATA,sha256=cYkX9lEH8RFBWv55ocTRJ20op7gNyiUdZTmd0whvZAw,2878
|
|
20
|
+
meshagent_tools-0.21.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
meshagent_tools-0.21.0.dist-info/top_level.txt,sha256=GlcXnHtRP6m7zlG3Df04M35OsHtNXy_DY09oFwWrH74,10
|
|
22
|
+
meshagent_tools-0.21.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|