eca icon indicating copy to clipboard operation
eca copied to clipboard

Support user custom tools

Open ChetanKoneru opened this issue 1 year ago • 11 comments

When using GPTEL, I prefer using emacs native tools instead of MCP exposed tools.

In this instance I use this emacs tool to fetch content from URL rather than using mcp-fetch.


  (gptel-make-tool
   :function (lambda (url)
               (with-current-buffer (url-retrieve-synchronously url)
                 (goto-char (point-min))
                 (forward-paragraph)
                 (let ((dom (libxml-parse-html-region (point) (point-max))))
                   (run-at-time 0 nil #'kill-buffer (current-buffer))
                   (with-temp-buffer
                     (shr-insert-document dom)
                     (buffer-substring-no-properties (point-min) (point-max))))))
   :name "read_url"
   :description "Fetch and read the contents of a URL"
   :args (list '(:name "url"
                 :type string
                 :description "The URL to read"))
   :category "web")

Now LLM uses read_url tool when I provide a URL.

ChetanKoneru avatar Aug 27 '25 19:08 ChetanKoneru

Interesting use case, I believe supporting user specify tools by themselves would be nice, but not sure it should be something done in client, but on server, and with that you wouldn't be able to do via elisp I guess.

For this case especifically we will implement https://github.com/editor-code-assistant/eca/issues/70.

ericdallo avatar Aug 27 '25 20:08 ericdallo

Any guess @editor-code-assistant/maintainers on how to approach this feature support?

ericdallo avatar Aug 27 '25 20:08 ericdallo

I've thought about this. While I like that feature of GPTEL, it doesn't really fit into the overall design of ECA in my opinion. It would be limited to Emacs. If a user needs custom tools, they can write them in Clojure and recompile ECA, or they can write a Bash script and call it using the Bash tool.

zikajk avatar Aug 28 '25 08:08 zikajk

Yeah, agree, or even have MCPs for that but I agree is not a sconvenient than write a simple elisp.

Maybe we could have a way to specify custom tools scripts, that would reduce the work for users plug custom script as tools?

{
"extraTools": {
   "websearch": {"bash": "/path/to/my-script"}
}
}

ericdallo avatar Aug 28 '25 12:08 ericdallo

Makes sense, build tool in the server and use it in any client.

Lets say I want to create a tool to fetch url content in markdown with Trafilatura, how would I achieve that.

bash script? still wouldn't we want to pass url as a parameter?

Some example scenarios in the documentation would be nice.

This how I do it in emacs, I plug this function in to gptel-make-tool

(defun my-gptel--trafilatura-fetch-url (url)
    "Fetch content from URL using trafilatura and return it as a string."
    (with-temp-message (format "Fetching content from: %s" url)
      (with-temp-buffer
        (call-process "trafilatura" nil t nil "--output-format=markdown" "--with-metadata" "-u" url)
        (buffer-string))))

ChetanKoneru avatar Aug 28 '25 12:08 ChetanKoneru

Ah yeah, myu config was missing that we should define the args so LLM knows what to call:

{
   "extraTools":{
      "websearch":{
         "bash":"emacs --batch -l your-script.el",
         "schema":{
            "args":{
               "url":{
                  "type":"string",
                  "description":"...."
               }
            }
         }
      }
   }
}

This is pretty close to how ECA native tools work and would give a lot power to ECA without the need to write MCPs

So LLM would call the bash script with something like emacs --batch -l your-script.el --url "fooo"

And we may want to have in the future more options besides bash, like clojure so people code in Clojure and we use it via builtin sci

ericdallo avatar Aug 28 '25 12:08 ericdallo

Cool, I just gave my elisp function as an example, I would just use the bash for this.

Does this look right? url should be passed with -u, or should I have -u $1?

{
   "extraTools":{
      "websearch":{
         "bash":"trafilatura --output-format=markdown --with-metadata -u ",
         "schema":{
            "args":{
               "url":{
                  "type":"string",
                  "description":"provide url to fetch content in markdown format"
               }
            }
         }
      }
   }
}

ChetanKoneru avatar Aug 28 '25 12:08 ChetanKoneru

Yeah, putting extra thoughts to avoid problems with those I'd say a config like that would work:

{
   "userTools":{
      "websearch":{
         "bash":"trafilatura --output-format=markdown --with-metadata -u {{url}}",
         "schema":{
            "required": ["url"],
            "args":{
               "url":{
                  "type":"string",
                  "description":"provide url to fetch content in markdown format"
               }
            }
         }
      }
   }
}

I mean, you can already have a ECA rule teaching how LLM how to request url via bash command, but that would be more precise probably if we pass as tools to LLM.

ericdallo avatar Aug 28 '25 12:08 ericdallo

Awesome. feel free to close this issue.

Again thank you for the support. I will try to contribute documentation as I use ECA.

Love to contribute code but never really coded in Clojure, well first time for everything I guess.

ChetanKoneru avatar Aug 28 '25 12:08 ChetanKoneru

Moved this to eca server

ericdallo avatar Aug 28 '25 13:08 ericdallo

@CsBigDataHub did that in #105, thanks !

ericdallo avatar Sep 03 '25 03:09 ericdallo