luv

Workshop wiki

transcript.lisp

application-agent/transcript.lisp

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

in-package#:luv.application-agent

Typed transcript records are the durable boundary shared by plain text, retained developer panels, and application-specific world presentation.

defclasstool-call
tool:initarg:tool:readertool-call-tool
command:initarg:command:initformnil:accessortool-call-command
arguments:initarg:arguments:readertool-call-arguments
status:initform:running:accessortool-call-status
started:initform
get-internal-real-time
:readertool-call-started
finished:initformnil:accessortool-call-finished
result:initformnil:accessortool-call-result
error:initformnil:accessortool-call-error
output:initform"":accessortool-call-output
defuntool-call-name
call
openai:tool-name
tool-call-toolcall
defuntool-call-elapsed-seconds
call
/
-
or
tool-call-finishedcall
get-internal-real-time
tool-call-startedcall
floatinternal-time-units-per-second1.0
defmethodprint-object
stream
print-unreadable-object
callstream:typet
formatstream"~A ~(~A~) ~,1Fs"
tool-call-statuscall
defclassturn
prompt:initarg:prompt:readerturn-prompt
thought:initform"":accessorturn-thought
text:initform"":accessorturn-text
%calls:initform'
:accessor%turn-calls
status:initform:queued:accessorturn-status
error:initformnil:accessorturn-error
response:initformnil:accessorturn-response
started:initformnil:accessorturn-started
finished:initformnil:accessorturn-finished
thread:initformnil:accessorturn-thread
lock:initform
sb-thread:make-mutex:name"application agent turn"
:readerturn-lock
completion:initform
sb-thread:make-waitqueue:name"application agent turn complete"
:readerturn-completion
defunfinish-turn

Publish turn's completion once and wake every waiter.

sb-thread:with-mutex
turn-lockturn
unless
turn-finishedturn
setf
turn-finishedturn
get-internal-real-time
sb-thread:condition-broadcast
turn-completionturn
turn
defunwait-for-turn
turn&keytimeout

Return turn when complete, or NIL when timeout seconds elapse.

let
deadline
andtimeout
+
get-internal-real-time
round
*timeoutinternal-time-units-per-second
sb-thread:with-mutex
turn-lockturn
loopuntil
turn-finishedturn
do
let
remaining
anddeadline
/
-deadline
get-internal-real-time
floatinternal-time-units-per-second1.0
when
andremaining
not
pluspremaining
return-fromwait-for-turnnil
unless
sb-thread:condition-wait
turn-completionturn
turn-lockturn
:timeoutremaining
return-fromwait-for-turnnil
turn
defunturn-calls

Return a stable newest-first snapshot of turn's tool calls.

sb-thread:with-mutex
turn-lockturn
copy-list
%turn-callsturn
defunpush-turn-call
turncall
sb-thread:with-mutex
turn-lockturn
pushcall
%turn-callsturn
call
defmethodprint-object
stream
print-unreadable-object
turnstream:typet
formatstream"~(~A~) ~D call~:P ~S"
turn-statusturn
let
prompt
turn-promptturn
if
>
lengthprompt
40
concatenate'string
subseqprompt040
"..."
prompt
defuntool-call-arguments-text
call
formatnil"~{~(~A~)=~A~^ ~}"
loopfor
key.value
in
tool-call-argumentscall
collectkeycollectvalue
defuntranscript-lines

Return turn as plain lines suitable for a REPL or log.

let
lines'
flet
line
control&restarguments
push
apply#'formatnilcontrolarguments
lines
line"> ~A"
turn-promptturn
unless
string=
turn-thoughtturn
""
line" (thinking) ~A"
turn-thoughtturn
dolist
line" [~A] ~A ~A ~,1Fs~@[ -- ~A~]"
case
tool-call-statuscall
:ok"ok"
:error"!!"
otherwise".."
and
tool-call-errorcall
princ-to-string
tool-call-errorcall
unless
string=
tool-call-outputcall
""
dolist
text-line
uiop:split-string
tool-call-outputcall
:separator'
#\Newline
line" ~A"text-line
unless
string=
turn-textturn
""
line"~A"
turn-textturn
when
turn-errorturn
line" failed: ~A"
turn-errorturn
nreverselines
defunprint-transcript
turn&optional
stream*standard-output*
dolist
write-linelinestream
turn