From 10b89f28aede9005d165852004f230d7b02add5e Mon Sep 17 00:00:00 2001 From: Slipstream Date: Wed, 11 Jun 2025 23:02:11 +0000 Subject: [PATCH] docs: sync tool guide and components --- docs/ai_agent_tool_syntax_v2_xml.md | 168 ++++++++++++++++++++++++---- docs/components.md | 8 +- 2 files changed, 150 insertions(+), 26 deletions(-) diff --git a/docs/ai_agent_tool_syntax_v2_xml.md b/docs/ai_agent_tool_syntax_v2_xml.md index 6c78d18..a4142c9 100644 --- a/docs/ai_agent_tool_syntax_v2_xml.md +++ b/docs/ai_agent_tool_syntax_v2_xml.md @@ -1,24 +1,25 @@ -# Project: Refactor AI Agent Tool Syntax to XML +# AI Agent XML Tool Syntax -**Date:** 2025-05-31 +**Updated:** 2025-06-11 -**Goal:** To refactor the AI agent's tool calling mechanism from a custom regex-parsed format to a standardized XML-based format. This aims to improve robustness, ease of AI generation, parsing simplicity, extensibility, and standardization. +The AI agent defined in `cogs/ai_code_agent_cog.py` uses an XML-based format for all tool calls. When the agent needs to perform an action it responds **only** with an XML block. The name of the root element corresponds to the tool to invoke and the child elements provide the parameters. -**1. Current State:** -The AI agent in `cogs/ai_code_agent_cog.py` uses a custom, line-based syntax for tool calls, defined in `AGENT_SYSTEM_PROMPT` and parsed using regular expressions in `_parse_and_execute_tool_call`. +The following sections document the currently supported tools and their parameters. -**2. Proposed Change: XML-Based Tool Calls** - -The AI will be instructed to output *only* an XML block when calling a tool. The root element of the XML block will be the tool's name. - -**2.1. New XML Tool Call Syntax Definitions:** +**Tool Call Syntax Examples:** * **ReadFile:** - ```xml - - path/to/file.ext - - ``` +```xml + + path/to/file.ext + + 10 + 20 + + 5 + 5 + +``` * **WriteFile:** ```xml @@ -56,12 +57,16 @@ The AI will be instructed to output *only* an XML block when calling a tool. The ``` * **ListFiles:** - ```xml - - path/to/search - true - - ``` +```xml + + path/to/search + true + + .py,.txt + test_.*\.py + true + +``` * **WebSearch:** ```xml @@ -77,6 +82,102 @@ The AI will be instructed to output *only* an XML block when calling a tool. The ``` +* **LintFile:** + ```xml + + path/to/python_file.py + pylint + + ``` + +* **GetCodeStructure:** + ```xml + + path/to/python_file.py + + ``` + +* **FindSymbolDefinition:** + ```xml + + my_function + ./cogs + *.py + + ``` + +* **ManageCog:** + ```xml + + reload + cogs.example_cog + + ``` + +* **RunTests:** + ```xml + + tests/test_module.py + pytest + + ``` + +* **PythonREPL:** + ```xml + + + optional_id + + ``` + +* **CreateNamedSnapshot:** + ```xml + + feature_snapshot + Optional description + + ``` + +* **CompareSnapshots:** + ```xml + + snapshot_a + snapshot_b + + ``` + +* **DryRunApplyDiff:** + ```xml + + path/to/file.ext + + + ``` + +* **DryRunWriteFile:** + ```xml + + path/to/file.ext + + ``` + +* **ReadWebPageRaw:** + ```xml + + https://example.com/raw.txt + + ``` + **3. Parsing Logic in `_parse_and_execute_tool_call` (Python):** * The method will attempt to parse the `ai_response_text` as XML using `xml.etree.ElementTree`. @@ -123,6 +224,17 @@ graph TD E -- ExecuteCommand --> I[Call _execute_tool_execute_command]; E -- ListFiles --> J[Call _execute_tool_list_files]; E -- WebSearch --> K[Call _execute_tool_web_search]; + E -- LintFile --> R[Call _execute_tool_lint_file]; + E -- GetCodeStructure --> S[Call _execute_tool_get_code_structure]; + E -- FindSymbolDefinition --> T[Call _execute_tool_find_symbol_definition]; + E -- ManageCog --> U[Call _execute_tool_manage_cog]; + E -- RunTests --> V[Call _execute_tool_run_tests]; + E -- PythonREPL --> W[Call _execute_tool_python_repl]; + E -- CreateNamedSnapshot --> X[Call _execute_tool_create_named_snapshot]; + E -- CompareSnapshots --> Y[Call _execute_tool_compare_snapshots]; + E -- DryRunApplyDiff --> Z[Call _execute_tool_dry_run_apply_diff]; + E -- DryRunWriteFile --> AA[Call _execute_tool_dry_run_write_file]; + E -- ReadWebPageRaw --> AB[Call _execute_tool_read_web_page_raw]; E -- TaskComplete --> L[Process TaskComplete]; E -- Unknown Tool --> M[Handle Unknown Tool / Error]; B -- Invalid XML / Not a Tool --> N[Return "NO_TOOL" status]; @@ -132,7 +244,19 @@ graph TD I --> O; J --> O; K --> O; + R --> O; + S --> O; + T --> O; + U --> O; + V --> O; + W --> O; + X --> O; + Y --> O; + Z --> O; + AA --> O; + AB --> O; L --> P[End Interaction]; M --> P; N --> P; - O --> Q[Add to History, Continue Loop]; \ No newline at end of file + O --> Q[Add to History, Continue Loop]; +``` diff --git a/docs/components.md b/docs/components.md index 1e32e46..db22433 100644 --- a/docs/components.md +++ b/docs/components.md @@ -299,7 +299,7 @@ class InfoView(discord.ui.LayoutView): ## See Also -More examples can be found in the -`examples `{.interpreted-text role="resource"} directory. -Refer to the `interactions/api`{.interpreted-text role="doc"} page for -an exhaustive API reference. +For additional usage examples, refer to the official `discord.py` +documentation. This repository does not include the example suite from +the library. See the `interactions/api` reference for an exhaustive API +overview.