luv

Workshop wiki

presentations.lisp

application-agent/presentations.lisp

system luv/application-agent · 33 definitions · on GitHub

in-package#:luv.application-agent

A tool result remains a semantic object. These views say how a model, trace, or retained developer surface reads it; no provider JSON leaks into the application command itself.

defclassmodel-view
textual-view
:documentation

The compact textual view a language model reads.

defclasstrace-view
textual-view
:documentation

A short view suitable for an old-turn trace.

defclasscassette-view
textual-view
:documentation

The rich retained view used by an agent transcript UI.

defparameter+model-view+
make-instance'model-view
defparameter+trace-view+
make-instance'trace-view
defparameter+cassette-view+
make-instance'cassette-view

Handles are per-agent capabilities. Releasing their table atomically revokes every capability and prevents an in-flight turn from retaining fresh application objects after its owner has stopped.

defparameter+handle-alphabet+

ABCDEFGHJKLMNPQRSTUVWXYZ23456789

define-conditionhandle-table-released
error
table:initarg:table:readerreleased-handle-table
:report
lambda
conditionstream
formatstream"The application-agent handle table ~S is released."
released-handle-tablecondition
defclasshandle-table
objects:initform
make-hash-table:test#'equal
:readerhandle-table-objects
ids:initform
make-hash-table:test#'eq
:readerhandle-table-ids
counter:initform0:accessorhandle-table-counter
released-p:initformnil:accessorhandle-table-released-p
lock:initform
sb-thread:make-mutex:name"application agent handles"
:readerhandle-table-lock
defvar*handles*nil"The HANDLE-TABLE dynamically current while an agent command is handled."
defunhandle-id-string
number
let
coerce
looprepeat4collect
char+handle-alphabet+
modnumberbase
do
setfnumber
floornumberbase
'string
defunintern-handle
object&optional

Return object's short id in table, minting one on first mention.

unlesstable
error"No application-agent handle table is current."
sb-thread:with-mutex
handle-table-locktable
when
handle-table-released-ptable
or
gethashobject
handle-table-idstable
let
id
handle-id-string

Begin beyond the one-character range so the first id already reads as an opaque capability rather than data.

+1024
incf
handle-table-countertable
setf
gethashid
handle-table-objectstable
object
gethashobject
handle-table-idstable
id
id
defunhandle-object
id&optional

Return the object id names in table and whether it was present.

A leading # is accepted. Released or absent tables resolve no capability.

whentable
let
id
string-upcase
string-left-trim"#"id
sb-thread:with-mutex
handle-table-locktable
unless
handle-table-released-ptable
gethashid
handle-table-objectstable
defunrelease-handle-table

Revoke every handle in table once, returning true for the releasing call.

sb-thread:with-mutex
handle-table-locktable
unless
handle-table-released-ptable
setf
handle-table-released-ptable
t
clrhash
handle-table-objectstable
clrhash
handle-table-idstable
t
eval-when
:compile-toplevel:load-toplevel:execute
define-presentation-typehandle
:description"a short #ABCD handle naming something the agent was shown"
define-presentation-methodaccept
typehandle
stream
viewtextual-view
&key
let
string
read-tokenstream
multiple-value-bind
objectpresent-p
if
and
plusp
lengthstring
present-p
object
simple-parse-error"~S is not a live handle I have shown you."string
define-presentation-methodpresent
object
typehandle
stream
viewtextual-view
&key
formatstream"#~A"

JSON Schema is an open protocol over CLIM presentation-type names. A new application domain contributes one EQL method; the command-tool code never needs a typecase or an application dependency.

defgenericpresentation-type-json-schema
name&restparameters
:documentation

Return name with parameters as a CL-JSON alist containing JSON Schema.

:method
namet
&restparameters
declare
ignoreparameters
'
"type"."string"
defmethodpresentation-type-json-schema
name
eql'integer
&restparameters
declare
ignoreparameters
'
"type"."integer"
defmethodpresentation-type-json-schema
name
eql'real
&restparameters
declare
ignoreparameters
'
"type"."number"
defmethodpresentation-type-json-schema
name
eql'number
&restparameters
declare
ignoreparameters
'
"type"."number"
defmethodpresentation-type-json-schema
name
eql'float
&restparameters
declare
ignoreparameters
'
"type"."number"
defmethodpresentation-type-json-schema
name
eql'boolean
&restparameters
declare
ignoreparameters
'
"type"."boolean"
defmethodpresentation-type-json-schema
name
eql'member
&restvalues
`
"type"."string"
"enum".,
mapcar
lambda
value
string-downcase
princ-to-stringvalue
values
defmethodpresentation-type-json-schema
name
eql'completion
&restparameters
destructuring-bind
sequence&key
value-key'identity
&allow-other-keys
parameters
`
"type"."string"
"enum".,
mapcar
lambda
value
string-downcase
princ-to-string
funcallvalue-keyvalue
sequence
defmethodpresentation-type-json-schema
name
eql'handle
&restparameters
declare
ignoreparameters
'
"type"."string"
"pattern"."^#?[A-Z2-9]{4}$"
"description"."a #ABCD handle from an earlier result"
defunpresentation-type-specifier-json-schema
specifier

Return a schema for a symbol or parameterized presentation specifier.

let
specifier
expand-presentation-type-abbreviationspecifier
if
conspspecifier
apply#'presentation-type-json-schema
firstspecifier
restspecifier

Text for the provider. Folding is a presentation policy, never a command implementation policy, and the full object remains reachable by handle.

defunfold-model-text
text
let*
lines
uiop:split-stringtext:separator'
#\Newline
count
lengthlines
iftext
let
formatnil"~{~A~%~}[~D of ~D lines omitted; #~A names the full text]~%~{~A~^~%~}"omittedcount
defunhandle-worthy-p
object
typepobject'
orstandard-objectstructure-object
defunmodel-text
object&key
type
presentation-type-ofobject

Present object under view, append a capability handle, and fold long text.

let
text
handler-case
present-to-stringobjecttype:viewview
error
condition
formatnil"~A [unpresentable as ~S: ~A]"
prin1-to-stringobject
typecondition
when
setftext
formatnil"~A #~A"text