ztcl::agent schema
Gives the JSON schema of a result schema.
ztcl::agent schema SCHEMA
Description
Gives the JSON schema of the result schema SCHEMA, as the model sees it in the input schema of the tool result. Each key is required, and an object has no other key.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| SCHEMA | result schema | required | A list of keys and types. |
Returns
A JSON text.
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} }
.
% ztcl::agent schema {n int}
{"type":"object","properties":{"n":{"type":"integer"}},"required":["n"],"additionalProperties":false}
% ztcl::agent schema {k {enum a b} l {list number}}
{"type":"object","properties":{"k":{"type":"string","enum":["a","b"]},"l":{"type":"array","items":{"type":"number"}}},"required":["k","l"],"additionalProperties":false}
Errors
% ztcl::agent schema {n bogus}
bad type "bogus"
-errorcode ZTCL AGENT SCHEMA
% ztcl::agent schema
wrong # args: should be "ztcl::agent schema spec"
-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