2025-04-02 13:52:33 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
"""
|
2025-07-16 23:09:32 +01:00
|
|
|
Displays the current agent tool configurations
|
|
|
|
|
|
|
|
|
|
Shows all configured tools including their types:
|
|
|
|
|
- knowledge-query: Tools that query knowledge bases
|
|
|
|
|
- text-completion: Tools for text generation
|
|
|
|
|
- mcp-tool: References to MCP (Model Context Protocol) tools
|
|
|
|
|
- prompt: Tools that execute prompt templates
|
2025-04-02 13:52:33 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
import os
|
|
|
|
|
from trustgraph.api import Api, ConfigKey
|
|
|
|
|
import json
|
|
|
|
|
import tabulate
|
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
|
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
|
|
|
|
|
|
|
|
def show_config(url):
|
|
|
|
|
|
2025-05-05 11:09:18 +01:00
|
|
|
api = Api(url).config()
|
2025-04-02 13:52:33 +01:00
|
|
|
|
2025-07-16 23:09:32 +01:00
|
|
|
values = api.get_values(type="tool")
|
2025-04-02 13:52:33 +01:00
|
|
|
|
2025-07-16 23:09:32 +01:00
|
|
|
for item in values:
|
2025-04-02 13:52:33 +01:00
|
|
|
|
2025-07-16 23:09:32 +01:00
|
|
|
id = item.key
|
|
|
|
|
data = json.loads(item.value)
|
2025-04-02 13:52:33 +01:00
|
|
|
|
2025-07-16 23:09:32 +01:00
|
|
|
tp = data["type"]
|
2025-04-02 13:52:33 +01:00
|
|
|
|
|
|
|
|
table = []
|
|
|
|
|
|
2025-07-16 23:09:32 +01:00
|
|
|
table.append(("id", id))
|
2025-04-02 13:52:33 +01:00
|
|
|
table.append(("name", data["name"]))
|
|
|
|
|
table.append(("description", data["description"]))
|
2025-07-16 23:09:32 +01:00
|
|
|
table.append(("type", tp))
|
|
|
|
|
|
|
|
|
|
if tp == "mcp-tool":
|
|
|
|
|
table.append(("mcp-tool", data["mcp-tool"]))
|
|
|
|
|
|
|
|
|
|
if tp == "knowledge-query":
|
|
|
|
|
table.append(("collection", data["collection"]))
|
|
|
|
|
|
|
|
|
|
if tp == "prompt":
|
|
|
|
|
table.append(("template", data["template"]))
|
|
|
|
|
for n, arg in enumerate(data["arguments"]):
|
|
|
|
|
table.append((
|
|
|
|
|
f"arg {n}",
|
|
|
|
|
f"{arg['name']}: {arg['type']}\n{arg['description']}"
|
|
|
|
|
))
|
2025-04-02 13:52:33 +01:00
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
print(tabulate.tabulate(
|
|
|
|
|
table,
|
|
|
|
|
tablefmt="pretty",
|
|
|
|
|
maxcolwidths=[None, 70],
|
|
|
|
|
stralign="left"
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2025-05-06 13:43:17 +01:00
|
|
|
prog='tg-show-tools',
|
2025-04-02 13:52:33 +01:00
|
|
|
description=__doc__,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'-u', '--api-url',
|
|
|
|
|
default=default_url,
|
|
|
|
|
help=f'API URL (default: {default_url})',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
show_config(
|
|
|
|
|
url=args.api_url,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
|
|
print("Exception:", e, flush=True)
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|