ztcl::agent describe
Gives the spec of a command as a tool.
ztcl::agent describe NAME
Description
Gives the list NAME TEXT SCHEMA PARAMS of the host command NAME. SCHEMA is the JSON schema of its input, from info args and info default of the proc and from doc: an argument with a default is optional, and args is an array. A command that is not a proc has one argument, the array args of its words. The text with no doc is The command NAME.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| NAME | command name | required | A command of the host. |
Returns
A list of four items.
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 describe greet
greet {The command greet.} {{"type":"object","properties":{"name":{"type":"string"},"times":{"type":"string"}},"required":["name"]}} {{name required} {times optional}}
% lindex [ztcl::agent describe set] 2
{"type":"object","properties":{"args":{"type":"array","items":{"type":"string"}}},"required":[]}
Errors
% ztcl::agent describe nosuch
no command "nosuch" for a tool
-errorcode ZTCL AGENT USAGE
% proc g {a} {}
> ztcl::agent doc g x a bogus
> ztcl::agent describe g
bad type "bogus"
-errorcode ZTCL AGENT SCHEMA
% ztcl::agent describe
wrong # args: should be "ztcl::agent describe name"
-errorcode TCL WRONGARGS
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