Просмотр исходного кода

#5406 AI Agents revamp: content get tool

Aleksandr Trofimov 6 месяцев назад
Родитель
Сommit
fc9eef6f40

+ 50 - 0
inc/classes/BxDolAIToolContentGet.php

@@ -0,0 +1,50 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+use NeuronAI\Tools\PropertyType;
+use NeuronAI\Tools\Tool;
+use NeuronAI\Tools\ToolProperty;
+
+class BxDolAIToolContentGet extends Tool
+{
+    public function __construct()
+    {
+        parent::__construct(
+            'get_content_info',
+            'Retrieve content info for a given module and content id.',
+        );
+    }
+    
+    protected function properties(): array
+    {
+        return [
+            new ToolProperty(
+                name: 'module',
+                type: PropertyType::STRING,
+                description: 'The module name to retrieve content info from. Use "system" for site accounts. ',
+                required: true
+            ),
+            new ToolProperty(
+                name: 'content_id',
+                type: PropertyType::INTEGER,
+                description: 'The ID of the content item to retrieve info for.',
+                required: true
+            )
+        ];
+    }
+
+    public function __invoke(string $module, int $content_id): string
+    {
+        $a = bx_srv('system', 'get_info', [$module, $content_id], 'TemplServiceContent');
+        if (!$a)
+            return "Error: content item was not found";
+
+        return json_encode($a);
+    }
+}

+ 0 - 2
inc/classes/BxDolAIToolContentStructure.php

@@ -44,8 +44,6 @@ class BxDolAIToolContentStructure extends Tool
         else
             $s .= "\n" . $this->formatStructureOutputForLLM($aStructure);
 
-        echoDbgLog($module . 's content structure: ' . $s);
-
         return $s;
     }
 

+ 3 - 0
inc/classes/BxDolAIToolFactory.php

@@ -44,6 +44,9 @@ class BxDolAIToolFactory extends BxDolFactory
             case 'content_structure':
                 $o = BxDolAIToolContentStructure::make();
                 break;
+            case 'content_get':
+                $o = BxDolAIToolContentGet::make();
+                break;
             default:
                 bx_log('sys_agents', "Tool type {$a['type']} is not supported", BX_LOG_ERR);
                 throw new Exception("Tool type {$a['type']} is not supported");

+ 2 - 1
install/sql/system.sql

@@ -7279,7 +7279,8 @@ INSERT INTO `sys_agents_tools` (`type`, `title`, `docs`, `params`, `params_user`
 ('mysql_schema', 'MySQL Schema', 'This tool allows agents to understand the structure of the database, enabling them to construct intelligent queries without requiring you to hardcode table structures or relationships into the prompts. This tool essentially gives your agent the equivalent of a database administrator’s understanding of your schema, allowing it to craft queries that respect your data model and take advantage of existing indexes.  \r\nIt reads all tables by default, but it\'s possible to limit it to a certain number of tables by providing the list in the `tables` parameter. By limiting the schema scope, you can create specialized agents that focus on specific areas of the site.', '{\"tables\":[]}', NULL, 0, 0, 1),
 ('mysql_select', 'MySQL Select', 'Use this tool to make your agent able to run SELECT query against the database. It\'s like read-only access without ability to change anything in the DB. It works the best in par of MySQL Schema tool.  \r\nNo parameters are needed for this tool.', '{}', NULL, 0, 0, 1),
 ('mysql_write', 'MySQL Write', 'Use this tool to make your agent able to performs write operations against the database (INSERT, UPDATE, DELETE). It works the best in par of MySQL Schema tool.   \r\nNo parameters are needed for this tool.  \r\n**USE WITH CAUTION**', '{}', NULL, 0, 0, 0),
-('content_structure', 'Site content modules fields structure', 'This tool allows agents to understand the structure of content modules fields,  allowing them to call content adding and editing with correct data. It provide knowledge of what content modules are available and what the fields in them, event if fields are changed in fields builder.', '{}', NULL, 0, 0, 1);
+('content_structure', 'Site content modules fields structure', 'This tool allows agents to understand the structure of content modules fields,  allowing them to call content adding and editing with correct data. It provide knowledge of what content modules are available and what the fields in them, event if fields are changed in fields builder.', '{}', NULL, 0, 0, 1),
+('content_get', 'Site content modules get content', 'This tool allows agents to get info about specific content by module name and content id.', '{}', NULL, 0, 0, 1);
 
 CREATE TABLE IF NOT EXISTS `sys_agents_chat_history` (
   `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,

+ 1 - 1
template/scripts/BxBaseServiceContent.php

@@ -268,7 +268,7 @@ class BxBaseServiceContent extends BxDol
      */
     public function serviceGetInfo ($sContentObject, $iContentId, $bRawInfo = false)
     {
-        if ('sys_account' == $sContentObject) {
+        if ('sys_account' == $sContentObject || 'system' == $sContentObject) {
             $o = BxDolAccount::getInstance($iContentId);
             if (!$o)
                 return false;