Repository navigation
feat(lk): write evals and session labels under --user-auth - #1153
Conversation
Picks up the Public API's project-level observability reads: ListProjectLogs, ListLogPatterns and GetAgentInsights. Nothing calls them yet. Also picks up what the spec gained since the last regeneration: the eval and session label RPCs, GetSessionEvals, ListEvalSessions, GetEvalResults, GetSessionLabelResults, and Agent Builder, whose service is now AgentBuilderService in place of BuilderAgentService. Nothing in lk calls them. Generated from livekit/public-api-server@16e4400
Reads the Public API's ListProjectLogs: the log records that the logs page on the dashboard lists, from the project's agents, client SDKs and LiveKit, newest first, one line per record with its time, level, source, session, logger and message. --json prints the records as the API sends them. --since, or --start and --end (a UTC date or an RFC 3339 time), set the range; without them the server reads the last 24 hours. --log-level, --source, --session-id and --query filter, --sort-order orders, and --limit and the hidden --cursor page, as for lk analytics session logs. The read is for project admins. A refusal says so, a query the server can't parse gets a hint about the search syntax (an attribute needs its @), and with user data recording off the error names the settings page, as the session reads do.
Reads the Public API's ListLogPatterns: the patterns that the logs page on the dashboard groups a project's log records into, ranked, one row each with its number of records, level, source, first and last record, and template. A note on stderr says how many records the range holds and, on a project with many records, that the counts are estimates. --json prints the API's response, with each pattern's counts over time and its variants. It takes the same range flags as lk analytics logs, plus --min-level (the server's default is WARN), --source agent|client, --agent-name, --agent-id, --session-id, --query, --rank events|first-seen|last-seen and --limit. The list is one page, so there is no --cursor. The read is for project admins, and its errors say so as the logs' do.
Reads the Public API's GetAgentInsights: the data that the agent dashboards of LiveKit Cloud show, as four tables. The totals; the latencies that have measurements (end-to-end, LLM and realtime time to first token, TTS time to first byte, transcription and end-of-utterance delay, tool calls) with p50, p95, p99, mean and max; one row for each agent and deployment, busiest first; and one row for each model, with its tokens, characters or seconds of audio. --json prints the API's response. It takes the same range flags as lk analytics logs, reading the last 7 days by default, and --agent-id and --agent-name, repeatable, to select agents. Every project member can read it, so a refusal says the caller has no access to the project rather than that it needs an admin.
- A project read's refusal now goes through readAPIError, which sessionAPIError also calls, so the two no longer repeat the same permission-denied wording. - The help says that a lone --end moves the range too: each read covers its default length before --end. It also says that times print in local time. - The hint for a query the server can't parse no longer says that a missing @ is the only cause. - logs' usage line lists --sort-order and --limit, and --source's help gives a participant joining as its platform example, the proto's own example. - log-patterns prints "1 pattern shown", not "1 patterns". - insights prints a dash for an STT's requests, which the API always counts as 0.
Adds client calls for the Public API's eval reads: ListEvals, GetEval, ListEvalHistory, DiffEvalRevisions, GetEvalDefaults, ListSessionLabels, GetSessionLabelSettings, GetEvalResults, GetSessionLabelResults, ListEvalSessions and GetSessionEvals, with their renderers. GetEval and GetEvalDefaults keep the definition as the API sent it: the generated type drops unknown properties and stores pass_threshold as a float32. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk agent eval list|get|history|diff|defaults and lk agent eval label list|settings read a project's evals and session labels. lk analytics evals|eval-sessions|labels and lk analytics session evals read their results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds client calls for the Public API's eval writes: ValidateEval, CreateEval, UpdateEval, SaveEvalDraft, DiscardEvalDraft, PublishEvalDraft, RollbackEval, DeleteEval, UndeleteEval, UpdateEvalDefaults, the session label writes and UpdateSessionLabelSettings. Definitions go to the API verbatim. APIError now keeps the error envelope's gRPC code, so a caller can tell a stale draft etag (Aborted) from a stale base revision (FailedPrecondition), and FieldViolations reads a BadRequest detail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds lk agent eval validate|create|update|save|discard|publish|rollback| delete|undelete, lk agent eval defaults set, lk agent eval label create|update|delete|undelete and lk agent eval label settings set. Publish, rollback, undelete and label create/undelete start LLM judging or labeling, so they ask first, as the MCP tools do; discard asks too. --yes skips the question, and a run that can't ask refuses. A refused request lists the fields the API named. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Six agent dev tests left devSession.run running after they returned. It prints through the shared out, so it raced with the next test that replaced out; the new agent_eval_test.go sorts right after them and tripped -race. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Print the reason on its own lines wrapped at 80 columns and the transcript excerpt quoted with "> " as written, not Go-quoted. Leave "on -" out of an eval heading when the session has no agent name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The eval sessions response carries only the label IDs, so read the project's labels (deleted ones included) once and show each label by name. A failed label read falls back to the IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lk analytics eval-sessions reads the project's evals once and shows each eval by name, cut to 30 characters, falling back to the ID. lk analytics session evals prints a blank line between one eval's failures and the next eval. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A flag given with a blank ID used to read every session, as if it were left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An explicit empty --etag now reaches the API, which refuses the save when a draft exists, instead of the CLI adopting the current draft's etag. A definition file holding null is refused like any other non-object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Topherhindman
left a comment
There was a problem hiding this comment.
took a pass at f846300. the etag default is the main thing (inline). small: FieldViolations is the same code as #1136, and #1136's cloudOnlyAPIError covers what the three IsPermissionDenied branches here hand-roll, so worth lining those up when one of them lands. on the body: the bare #212/#213 want livekit/public-api-server#N, and the "Draft etags" paragraph describes the auto-read as a feature, which would change with the etag comment
| return evalWriteError(err, projectID, evalID) | ||
| } | ||
| if draft != nil { | ||
| etag = util.Deref(draft.DraftEtag) |
There was a problem hiding this comment.
without --etag this reads the current etag and sends it, so save always wins and quietly replaces whatever draft a teammate saved. agent-evals refuses an empty etag when a draft exists on purpose. could save just send what --etag gave, and let the Aborted hint point at get --draft --json?
There was a problem hiding this comment.
Done in 6c1a5df: save sends only what --etag gives, and prints the new draftEtag. The Aborted hint points at get --draft --json.
| evalID, util.Accented("lk agent eval save "+evalID+" --file FILE")) | ||
| } | ||
| if p.Etag == "" { | ||
| p.Etag = util.Deref(draft.DraftEtag) |
There was a problem hiding this comment.
same here and in discard: the prompt is the only guard, and --yes skips it. should --yes require --etag, or at least the prompt say who saved the draft and when?
There was a problem hiding this comment.
Both, in 6c1a5df: --yes needs --etag, and the prompt shows when the draft last changed and by whom.
| } | ||
| got, err := client.PublishEvalDraft(ctx, projectID, evalID, p.EvalPublishOptions) | ||
| if err != nil { | ||
| if public.IsFailedPrecondition(err) && len(public.FieldViolations(err)) == 0 { |
There was a problem hiding this comment.
publishing a deleted eval's draft lands here too ("the eval is deleted" is a FailedPrecondition with no violations), and then points at diff + --allow-stale-base. you already have draft.BaseRevision and e.PublishedRevision, could the hint only show when they differ?
There was a problem hiding this comment.
Done in 6c1a5df: the hint shows only when the base isn't live.
| // judging or labeling, or loses work: title is the question, and description | ||
| // says what follows. yes (--yes) confirms without asking; a run that can't | ||
| // ask fails with refusal and a hint to pass --yes. | ||
| func confirmEvalChange(ctx context.Context, yes bool, title, description, refusal string) error { |
There was a problem hiding this comment.
this is confirmKeyDeletion from member_removal.go with the strings passed in. could it move to utils.go and member_removal use it, instead of a second copy?
There was a problem hiding this comment.
Done in 6c1a5df: confirmAction in utils.go, used by member removal too.
| // flags. | ||
| func labelSettingsFlags() []cli.Flag { | ||
| return []cli.Flag{ | ||
| &cli.FloatFlag{Name: "confidence-threshold", Usage: "Lowest confidence `N`, above 0 and at most 1, at which the LLM keeps a label (default 0.7)"}, |
There was a problem hiding this comment.
help prints (default 0.7) (default: 0) here and (default 1) (default: 0) on --min-user-turns. HideDefault: true like --revision?
| func createEval(ctx context.Context, client *public.Client, projectID string, c evalCreate, asJSON bool) error { | ||
| got, err := client.CreateEval(ctx, projectID, c.name, c.description, c.definition) | ||
| if err != nil { | ||
| return evalWriteError(err, projectID, "") |
There was a problem hiding this comment.
a NotFound on create is the project, so this prints "(eval in project p_…)". same on label create. projectReadError instead?
There was a problem hiding this comment.
Fixed in 6c1a5df: NotFound on create now goes through projectReadError.
|
|
||
| // decodeOK decodes a 200 response's body into out, and returns the API's | ||
| // error for any other status. | ||
| func decodeOK(status int, body []byte, out any) error { |
There was a problem hiding this comment.
nit: GetEval and GetEvalDefaults in evals.go inline this same block, could they use it?
…eads # Conflicts: # cmd/lk/analytics.go # cmd/lk/analytics_project.go # cmd/lk/analytics_project_test.go # cmd/lk/script_test.go # pkg/public/project_logs.go # pkg/public/project_logs_test.go
- sessionRead and evalAction share one actionWithID, which takes the ID's name. - eval-sessions and the eval results reads share the agent, intent and outcome filter flags. - Drop the client's copy of the criterion rules; the API refuses a criterion without its eval or with a verdict. - The eval-sessions usage shows --verdict works without --eval-id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # cmd/lk/agent_eval.go
- save sends only the draftEtag that --etag gives, so it never replaces a draft the caller didn't read; it prints the new draftEtag for the next change. - publish and discard: --yes needs --etag, and the question says when the draft last changed and who changed it. - publish points at --allow-stale-base only when the draft's base isn't live. - create and label create report a NotFound as the project's, not an empty eval's. - One confirmAction in utils.go for the eval commands and member removal. - GetEval and GetEvalDefaults decode through decodeOK. - label settings set prints each default once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Topherhindman
left a comment
There was a problem hiding this comment.
thanks, checked the etag change on the wire: save sends nothing it wasn't given and --yes needs --etag. one optional thing: the recipe in the help ends with a publish that a script can't run without --yes --etag, could add save --json's draftEtag there. approving
…rites # Conflicts: # cmd/lk/agent_eval.go # cmd/lk/script_test.go # pkg/public/evals.go # pkg/public/render/evals.go
Stacked on #1152 (eval reads). Merge order: #1152 → this.
What
Lets a person or coding agent signed in with
--user-authwrite and ship evals fromlk: check a definition, create an eval, save a draft, publish it, roll it back. It also manages session labels (the intents and outcomes an LLM assigns to each session).lk agent eval validate | create | update | save | discard | publish | rollback | delete | undeletelk agent eval defaults set --file FILE(the project's judge defaults)lk agent eval label create | update | delete | undelete,lk agent eval label settings set--file FILE(or-for stdin), a JSON object, the same oneget --jsonprintsWhy
The Public API's EvalService writes are in production (livekit/public-api-server#212, livekit/public-api-server#213), but
lkcould only read evals (#1152). Authoring from a file makes evals scriptable, and a coding agent can edit them.How
confirm: true. Discard asks too, since the draft is lost.--yesskips the question; a run that can't prompt refuses and sends nothing. The question helper moved toutils.go, and member removal uses it too.savesends only the--etagit is given, so it never replaces a draft the caller didn't read; without one, the API accepts the save only when the eval has no draft.publishanddiscardshow who last changed the draft and when in their question, and--yesneeds--etag. A stale etag (Aborted) says how to re-read; a stale base revision (FailedPrecondition) prints thediffto run and--allow-stale-base. To tell the two apart,APIErrornow keeps the envelope's gRPCcode.FieldViolationsand thecloudAPIErrorchange are copied from feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136; whichever merges second takes one copy, and lines its permission errors up with feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136'scloudOnlyAPIError.label settings setreads the settings, changes only the flags given, and sends them all, because the API resets any field left out.get --jsonresponse is refused, with thejqthat extracts the definition.Testing
go build ./...,go vet ./...,go test ./...andgo test -race ./cmd/lk ./pkg/public/...pass.--yes, the violations listing, and the settings merge.eval-writes-with-user-auth.txtarruns the binary through validate, create, save, publish (refused without--yes, then with it), label create and settings set. The request log shows that a refused change sends nothing.🤖 Generated with Claude Code