💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add coding agent toolkit, closes #1054
davidmezzetti2d50a4c20266
diff --git a/docs/agent/configuration.md b/docs/agent/configuration.mdindex 18f9e10e..d53f5118 100644--- a/docs/agent/configuration.md+++ b/docs/agent/configuration.md@@ -85,11 +85,19 @@ The following shortcut strings load tools directly. Passing a Tool instance is a| Tool | Description ||:------------|:----------------------------------------------------------|+| bash | Runs a shell command through subprocess |+| defaults | Loads all of these tools as the default toolkit |+| edit | Edits a file in place and returns a diff |+| glob | Finds matching file patterns in a directory |+| grep | Finds matching file content in a directory || http.* | HTTP Path to a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro) server || python | Runs a Python action |-| *.md | Loads a [`skill.md`](https://agentskills.io/specification) file+| read | Reads file or url content, supports text extraction |+| todowrite | Generates a task list to organize complex tasks || websearch | Runs a websearch using the built-in websearch tool |-| webview | Extracts content from a web page |+| webview | Extracts content from a web page. Alias for `read` tool |+| write | Writes content to file |+| *.md | Loads a [`skill.md`](https://agentskills.io/specification) file |## instructionsdiff --git a/src/python/txtai/agent/tool/__init__.py b/src/python/txtai/agent/tool/__init__.pyindex cec23e0a..c45c38e6 100644--- a/src/python/txtai/agent/tool/__init__.py+++ b/src/python/txtai/agent/tool/__init__.py@@ -5,3 +5,10 @@ Tool importsfrom .embeddings import EmbeddingsToolfrom .factory import ToolFactoryfrom .function import FunctionTool+from .bash import BashTool+from .edit import EditTool+from .glob import GlobTool+from .grep import GrepTool+from .read import ReadTool+from .skill import SkillTool+from .todo import TodoWriteTooldiff --git a/src/python/txtai/agent/tool/factory.py b/src/python/txtai/agent/tool/factory.pyindex 12fdc8f3..06aa81ea 100644--- a/src/python/txtai/agent/tool/factory.py+++ b/src/python/txtai/agent/tool/factory.py@@ -9,13 +9,20 @@ from types import FunctionType, MethodTypeimport mcpadapt.corefrom mcpadapt.smolagents_adapter import SmolAgentsAdapter-from smolagents import PythonInterpreterTool, Tool, tool as CreateTool, VisitWebpageTool, WebSearchTool+from smolagents import PythonInterpreterTool, Tool, tool as CreateTool, UserInputTool, WebSearchToolfrom transformers.utils import chat_template_utils, TypeHintParsingExceptionfrom ...embeddings import Embeddings+from .bash import BashTool+from .edit import EditToolfrom .embeddings import EmbeddingsToolfrom .function import FunctionTool+from .glob import GlobTool+from .grep import GrepTool+from .read import ReadToolfrom .skill import SkillTool+from .todo import TodoWriteTool+from .write import WriteToolclass ToolFactory:@@ -24,7 +31,21 @@ class ToolFactory:"""# Default toolkit- DEFAULTS = {"python": PythonInterpreterTool(), "websearch": WebSearchTool(), "webview": VisitWebpageTool()}+ DEFAULTS = {+ "bash": BashTool(),+ "edit": EditTool(),+ "glob": GlobTool(),+ "grep": GrepTool(),+ "python": PythonInterpreterTool(),+ "question": UserInputTool(),+ "read": ReadTool(),+ "todowrite": TodoWriteTool(),+ "websearch": WebSearchTool(),+ "write": WriteTool(),+ }++ # Backwards compatible mappings+ DEFAULTS["webview"] = DEFAULTS["read"]@staticmethoddef create(config):@@ -62,6 +83,11 @@ class ToolFactory:elif isinstance(tool, str) and tool in ToolFactory.DEFAULTS:tool = ToolFactory.DEFAULTS[tool]+ # Get ALL default tools, if applicable+ elif isinstance(tool, str) and tool == "defaults":+ tools.extend(set(ToolFactory.DEFAULTS.values()))+ tool = None+# Support importing MCP tool collectionselif isinstance(tool, str) and tool.startswith("http"):tools.extend(mcpadapt.core.MCPAdapt({"url": tool}, SmolAgentsAdapter()).tools())diff --git a/src/python/txtai/agent/tool/function.py b/src/python/txtai/agent/tool/function.pyindex 5083e4bf..7fd80dd2 100644--- a/src/python/txtai/agent/tool/function.py+++ b/src/python/txtai/agent/tool/function.py@@ -7,8 +7,7 @@ from smolagents import Toolclass FunctionTool(Tool):"""- Creates a FunctionTool. A FunctionTool takes descriptive configuration and injects it along with a target function- into an LLM prompt.+ A FunctionTool takes descriptive configuration and injects it along with a target function into an LLM prompt."""# pylint: disable=W0231diff --git a/src/python/txtai/agent/tool/skill.py b/src/python/txtai/agent/tool/skill.pyindex 2290a8cf..13b616bb 100644--- a/src/python/txtai/agent/tool/skill.py+++ b/src/python/txtai/agent/tool/skill.py@@ -9,7 +9,7 @@ from smolagents import Toolclass SkillTool(Tool):"""- Creates a SkillTool. A SkillTool loads a skill.md file.+ A SkillTool loads a skill.md file."""# pylint: disable=W0231diff --git a/test/python/testagent.py b/test/python/testagent.pyindex cdf5d0b8..1b6bdcf2 100644--- a/test/python/testagent.py+++ b/test/python/testagent.py@@ -160,6 +160,29 @@ class TestAgent(unittest.TestCase):self.assertIsInstance(agent.tools["today"](True), str)self.assertIsInstance(agent.tools["current"](True), str)+ def testToolsDefaults(self):+ """+ Test default toolkit tools+ """++ agent = Agent(tools=["defaults"], llm="hf-internal-testing/tiny-random-LlamaForCausalLM", max_steps=1)++ # Working directory+ work = tempfile.gettempdir()++ # Test file+ path = os.path.join(work, "agent_tools.txt")+ agent.tools["write"](path, "hello world")++ # Test default tools+ self.assertIsNotNone(agent.tools["bash"](["ls", work]))+ self.assertGreater(len(agent.tools["glob"](work)), 0)+ self.assertGreater(len(agent.tools["grep"]("world", "*")), 0)+ self.assertEqual(agent.tools["todowrite"]("plan"), "plan")++ agent.tools["edit"](path, "hello", "goodbye")+ self.assertEqual(agent.tools["read"](path), "goodbye world".strip())+def testToolsEmbeddings(self):"""Test adding Embeddings as a tool