Liking cljdoc? Tell your friends :D
Clojure only.

copilot.define-tool

Idiomatic helpers for defining Copilot tools.

Provides define-tool (function) and deftool (macro) for concise tool definitions with automatic result normalisation.

Idiomatic helpers for defining Copilot tools.

Provides `define-tool` (function) and `deftool` (macro) for concise
tool definitions with automatic result normalisation.
raw docstring

define-toolclj

(define-tool name description handler-fn)
(define-tool name description parameters handler-fn)
(define-tool name description parameters handler-fn opts)

Define a tool with automatic result normalisation.

The handler function receives (args invocation) where:

  • args is the parsed arguments map from the LLM
  • invocation is a map with :session-id :tool-call-id :tool-name :arguments

The handler may return:

  • A string (wrapped as success)
  • A ToolResultObject map (passed through)
  • Any other value (JSON-serialised as success)
  • nil (empty success)

Exceptions in the handler are caught and returned as failure results with the error detail hidden from the LLM.

Parameters: name - tool name string description - description shown to the LLM parameters - JSON Schema map for the tool's parameters (or nil) handler-fn - (fn [args invocation]) -> any opts - optional map; {:idempotent true} marks the tool as safe to retry (sent as idempotent in the tool definition)

Returns a tool map suitable for copilot.client/create-session! :tools.

Define a tool with automatic result normalisation.

The handler function receives `(args invocation)` where:
  - `args`       is the parsed arguments map from the LLM
  - `invocation` is a map with :session-id :tool-call-id :tool-name :arguments

The handler may return:
  - A string (wrapped as success)
  - A ToolResultObject map (passed through)
  - Any other value (JSON-serialised as success)
  - nil (empty success)

Exceptions in the handler are caught and returned as failure results with
the error detail hidden from the LLM.

Parameters:
  `name`        - tool name string
  `description` - description shown to the LLM
  `parameters`  - JSON Schema map for the tool's parameters (or nil)
  `handler-fn`  - (fn [args invocation]) -> any
  `opts`        - optional map; {:idempotent true} marks the tool as safe to
                  retry (sent as `idempotent` in the tool definition)

Returns a tool map suitable for `copilot.client/create-session!` :tools.
sourceraw docstring

deftoolcljmacro

(deftool name docstring [args-binding invocation-binding] & body)
(deftool name docstring schema [args-binding invocation-binding] & body)

Define a tool and bind it to a var.

Usage:

(deftool lookup-fact "Returns a fun fact about a given topic." {:type "object" :properties {:topic {:type "string" :description "Topic to look up"}} :required ["topic"]} [args invocation] (get facts (get args :topic) "No fact found."))

Expands to a def binding to the result of define-tool.

The body has access to the bindings specified in the parameter vector. The first binding receives the arguments map, the second (optional) receives the invocation context map.

Define a tool and bind it to a var.

Usage:

  (deftool lookup-fact
    "Returns a fun fact about a given topic."
    {:type       "object"
     :properties {:topic {:type "string"
                          :description "Topic to look up"}}
     :required   ["topic"]}
    [args invocation]
    (get facts (get args :topic) "No fact found."))

Expands to a `def` binding to the result of `define-tool`.

The body has access to the bindings specified in the parameter vector.
The first binding receives the arguments map, the second (optional)
receives the invocation context map.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close