beetlebug▾
/

ztcl::agent doc

Sets the text of a tool and the types of its arguments.

ztcl::agent doc NAME TEXT ?ARG TYPE ...?

Description

Sets the text of the tool NAME and the types of its arguments, for its schema, and gives NAME. An argument with no entry is a string. doc checks that NAME is a command, that each ARG is an argument of the proc (args for a command that is no proc), and that each TYPE is a type of a schema.

Arguments

ArgumentTypeDefaultDescription
NAMEcommand namerequiredThe name of the tool.
TEXTstringrequiredThe text of the tool for the model.

Returns

NAME.

Examples

Each example of this page runs after package require ztcl::agent # A fake model on 127.0.0.1, on a port of the system, in a thread: each # request gets the next reply of ::replies, and ::requests keeps them. set srv [thread::create { proc serve {c a p} { fconfigure $c -translation binary set len 0 set hs {} while {[gets $c line] >= 0 && [set line [string trim $line]] ne ""} { lappend hs $line regexp -nocase {^content-length: *(\d+)} $line -> len } lappend ::requests [list $hs [read $c $len]] set body [lindex $::replies 0] set ::replies [lrange $::replies 1 end] puts -nonewline $c "HTTP/1.1 $::status OK\r\nContent-Length: [string length $body]\r\nConnection: close\r\n\r\n$body" close $c } set ::status 200 set ::replies {} set ::requests {} set ::port [lindex [fconfigure [socket -server serve -myaddr 127.0.0.1 0] -sockname] 2] thread::wait }] set url http://127.0.0.1:[thread::send $srv {set ::port}]/v1/messages # Sets the replies of the fake model, and gives the requests that it got. proc replies {args} { thread::send $::srv [list set ::replies $args] } proc requests {} { thread::send $::srv {set ::requests} } # A reply of the Messages API with one call of a tool. proc call {name input} { return "{\"content\":\[{\"type\":\"tool_use\",\"id\":\"t[incr ::id]\",\"name\":\"$name\",\"input\":$input}\],\"usage\":{\"input_tokens\":5,\"output_tokens\":3}}" } proc add {a b} { expr {$a + $b} } .

% proc greet {name {times 1}} {}
> ztcl::agent doc greet "Greets a person." name string times int
greet

% proc greet {name {times 1}} {}
> ztcl::agent doc greet "Greets a person." times int
> lrange [ztcl::agent describe greet] 0 1
greet {Greets a person.}

Errors

% ztcl::agent doc greet
wrong # args: should be "ztcl::agent doc name text ?arg type ...?"
-errorcode TCL WRONGARGS

% ztcl::agent doc nosuch x
no command "nosuch" for a tool
-errorcode ZTCL AGENT USAGE

Facts

Capability
thread. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also