Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
183c95e
chore(public): regenerate the client from the Public API in production
Topherhindman Nov 24, 2026
d6a8749
feat(lk): lk analytics logs prints a project's logs under --user-auth
Topherhindman Nov 24, 2026
b6f184d
feat(lk): lk analytics log-patterns prints a project's log patterns
Topherhindman Nov 24, 2026
897f480
feat(lk): lk analytics insights prints a project's agent insights
Topherhindman Nov 24, 2026
1a05d61
fix(lk): review fixes for the analytics project reads
Topherhindman Nov 24, 2026
04a69ed
feat(public): read evals, session labels and eval results
jmcclanahan Dec 1, 2026
ab2de36
feat(lk): lk agent eval and lk analytics eval reads under --user-auth
jmcclanahan Dec 1, 2026
9563196
feat(public): change evals, judge defaults and session labels
jmcclanahan Dec 1, 2026
130735c
feat(lk): lk agent eval writes under --user-auth
jmcclanahan Dec 1, 2026
3ddd44d
test(lk): wait for each dev session test's session to stop
jmcclanahan Dec 1, 2026
272cbda
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
02764d2
fix(lk): wrap a session eval's failure reason under its criterion
jmcclanahan Dec 1, 2026
2baf096
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
6c42541
fix(lk): show intent and outcome names in lk analytics eval-sessions
jmcclanahan Dec 1, 2026
233c281
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
5a53e58
fix(lk): eval names in eval-sessions, spacing in session evals
jmcclanahan Dec 1, 2026
08c3dd6
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
e86b5a5
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
cbfb3f5
fix(lk): refuse a blank --eval-id or --criterion-id in eval-sessions
jmcclanahan Dec 1, 2026
f846300
fix(lk): honor an empty --etag on eval save, refuse a null definition
jmcclanahan Dec 1, 2026
1ff6397
Merge remote-tracking branch 'origin/main' into jakemcclanahan/eval-r…
jmcclanahan Dec 1, 2026
ee4ff4f
refactor(lk): review fixes for the eval reads
jmcclanahan Dec 1, 2026
cfab7f0
Merge branch 'jakemcclanahan/eval-reads' into jakemcclanahan/eval-writes
jmcclanahan Dec 1, 2026
6c1a5df
fix(lk): review fixes for the eval writes
jmcclanahan Dec 1, 2026
850c0cb
Merge remote-tracking branch 'origin/main' into jakemcclanahan/eval-w…
jmcclanahan Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions cmd/lk/agent_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
"github.com/livekit/livekit-cli/v2/pkg/util"
)

// init appends `lk agent eval` to `lk agent`. It reads a project's evals, its
// judge defaults and its session labels. Evals exist only on LiveKit Cloud,
// init appends `lk agent eval` to `lk agent`. It reads and changes a
// project's evals, its judge defaults and its session labels; the changes are
// in agent_eval_writes.go. Evals exist only on LiveKit Cloud,
// and only the Public API serves them, so every eval command requires
// --user-auth and calls pkg/public directly. Like the other Public-API-only
// groups, it is Hidden until a user signs in (see setUserAuthHidden). The
Expand All @@ -41,7 +42,7 @@ func init() {
var agentEvalCommand = &cli.Command{
Name: "eval",
Aliases: []string{"evals"},
Usage: "Read the evals that score your agents' sessions on LiveKit Cloud (requires --user-auth)",
Usage: "Manage the evals that score your agents' sessions on LiveKit Cloud (requires --user-auth)",
Hidden: true,
Metadata: userAuthOnly,
Description: `An eval is a set of criteria that LiveKit checks on each finished live session
Expand All @@ -58,8 +59,9 @@ only on the sessions with a label.
EVAL_ID is the EVAL_ ID that list prints. The results of the evals are under
lk analytics: evals, eval-sessions, labels and session evals.

Reading evals and labels requires the READ role on the project.`,
Commands: []*cli.Command{
Reading evals and labels, and validate, require the READ role on the project;
changing them requires the WRITE role.`,
Commands: append([]*cli.Command{
{
Name: "list",
Usage: "List the evals of a project",
Expand Down Expand Up @@ -125,13 +127,14 @@ Reading evals and labels requires the READ role on the project.`,
Usage: "Print the project's judge defaults and the judge models a definition can name",
Description: "Each eval uses the judge defaults for the judge settings that its definition doesn't set. " +
"A revision keeps the defaults it was published with. --json prints the API's response.",
Action: projectRead(noReadOptions, fetchEvalDefaults),
Flags: []cli.Flag{jsonFlag},
Action: projectRead(noReadOptions, fetchEvalDefaults),
Flags: []cli.Flag{jsonFlag},
Commands: []*cli.Command{evalDefaultsSetCommand},
},
{
Name: "label",
Usage: "Read the session labels of a project",
Commands: []*cli.Command{
Usage: "Manage the session labels of a project",
Commands: append([]*cli.Command{
{
Name: "list",
Usage: "List the session labels of a project",
Expand All @@ -158,18 +161,19 @@ Reading evals and labels requires the READ role on the project.`,
Description: "--json prints the settings as the API sends them.",
Action: projectRead(noReadOptions, fetchSessionLabelSettings),
Flags: []cli.Flag{jsonFlag},
Commands: []*cli.Command{labelSettingsSetCommand},
},
},
}, labelWriteCommands...),
},
},
}, evalWriteCommands...),
}

// noReadOptions is the options reader of a read that takes no flags of its
// own.
func noReadOptions(*cli.Command) (struct{}, error) { return struct{}{}, nil }

// evalAction builds the action of a command about one eval of a project,
// named by its EVAL_ID argument.
// evalAction builds the action of a command that reads or changes one eval
// of a project, named by its EVAL_ID argument.
func evalAction[O any](
readOptions func(*cli.Command) (O, error),
run func(ctx context.Context, client *public.Client, projectID, evalID string, opts O, asJSON bool) error,
Expand Down
989 changes: 989 additions & 0 deletions cmd/lk/agent_eval_writes.go

Large diffs are not rendered by default.

331 changes: 331 additions & 0 deletions cmd/lk/agent_eval_writes_test.go

Large diffs are not rendered by default.

31 changes: 4 additions & 27 deletions cmd/lk/member_removal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ package main

import (
"context"
"errors"
"fmt"
"strings"

"charm.land/huh/v2"
"github.com/urfave/cli/v3"

"github.com/livekit/livekit-cli/v2/pkg/public"
Expand Down Expand Up @@ -74,15 +72,9 @@ func removeMember(ctx context.Context, cmd *cli.Command, userID, scope string, r
// userID owns. --yes agrees; without it a non-interactive run fails, since the
// deletion can't be undone.
func confirmKeyDeletion(ctx context.Context, cmd *cli.Command, userID, scope string, numKeys uint32, changed bool) error {
if cmd.Bool("yes") {
return nil
}
if !isInteractive() {
msg := fmt.Sprintf("removing %s deletes the %d API key(s) they own, and anything using them stops working", userID, numKeys)
if scope != "" {
msg += "; " + strings.ToLower(scope[:1]) + strings.TrimSuffix(scope[1:], ".")
}
return errors.New(msg + "; re-run with --yes to go ahead")
refusal := fmt.Sprintf("removing %s deletes the %d API key(s) they own, and anything using them stops working", userID, numKeys)
if scope != "" {
refusal += "; " + strings.ToLower(scope[:1]) + strings.TrimSuffix(scope[1:], ".")
}
title := fmt.Sprintf("Remove %s and delete the %d API key(s) they own?", userID, numKeys)
if changed {
Expand All @@ -92,22 +84,7 @@ func confirmKeyDeletion(ctx context.Context, cmd *cli.Command, userID, scope str
if scope != "" {
description = scope + " " + description
}
confirmed := false
if err := huh.NewForm(huh.NewGroup(util.Confirm().
Title(title).
Description(description).
Value(&confirmed).
WithTheme(util.FormTheme()))).
RunWithContext(ctx); err != nil {
if errors.Is(err, huh.ErrUserAborted) {
return errors.New("aborted")
}
return err
}
if !confirmed {
return errors.New("aborted")
}
return nil
return confirmAction(ctx, cmd.Bool("yes"), title, description, refusal)
}

// lastKeyError says a removal is refused because it would leave projects
Expand Down
7 changes: 7 additions & 0 deletions cmd/lk/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ var publicAPIRoutes = []struct {
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/evals$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalsListResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/evals/[^/]+$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalsGetResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/evals/[^/]+/diff$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalRevisionsDiffResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/evals$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalsCreateResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/evals:validate$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalsValidateResponse) }},
{http.MethodPut, regexp.MustCompile(`^/v0/projects/[^/]+/evals/[^/]+/draft$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalDraftsSaveResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/evals/[^/]+/draft:publish$`), func() any { return new(oapi.LivekitPublicapiEvalsV1EvalDraftsPublishResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/session-labels$`), func() any { return new(oapi.LivekitPublicapiEvalsV1SessionLabelsCreateResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/session-label-settings$`), func() any { return new(oapi.LivekitPublicapiEvalsV1SessionLabelSettingsOpsGetResponse) }},
{http.MethodPut, regexp.MustCompile(`^/v0/projects/[^/]+/session-label-settings$`), func() any { return new(oapi.LivekitPublicapiEvalsV1SessionLabelSettingsOpsUpdateResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/session-labels$`), func() any { return new(oapi.LivekitPublicapiEvalsV1SessionLabelsListResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/eval-results$`), func() any { return new(oapi.LivekitPublicapiAnalyticsV1EvalResultsGetResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/eval-sessions$`), func() any { return new(oapi.LivekitPublicapiObservabilityV1EvalSessionsListResponse) }},
Expand Down
76 changes: 76 additions & 0 deletions cmd/lk/testdata/script/eval-writes-with-user-auth.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# lk agent eval changes a project's evals and session labels through the
# Public API as the signed-in user. The changes that make LiveKit judge or
# label sessions with an LLM ask first: a run that can't ask refuses without
# --yes and sends nothing.
respond POST http://publicapi.test/v0/projects/p_1/evals:validate 200 '{"definition":{"pass_threshold":0.75},"violations":[{"path":"criteria","message":"needs at least one criterion"}]}'
respond POST http://publicapi.test/v0/projects/p_1/evals 200 '{"eval":{"evalId":"EVAL_1","name":"resolved","hasDraft":true},"draft":{"draftEtag":"e1","definition":{"pass_threshold":0.75}}}'
respond GET http://publicapi.test/v0/projects/p_1/evals/EVAL_1?version.draft=true 200 '{"eval":{"evalId":"EVAL_1","name":"resolved","publishedRevision":0,"hasDraft":true},"draft":{"draftEtag":"e1","definition":{"pass_threshold":0.75}}}'
respond PUT http://publicapi.test/v0/projects/p_1/evals/EVAL_1/draft 200 '{"draft":{"draftEtag":"e2","definition":{"pass_threshold":0.75}}}'
respond POST http://publicapi.test/v0/projects/p_1/evals/EVAL_1/draft:publish 200 '{"eval":{"evalId":"EVAL_1","name":"resolved","publishedRevision":1},"revision":{"revision":1,"definition":{"pass_threshold":0.75}}}'
respond POST http://publicapi.test/v0/projects/p_1/session-labels 200 '{"label":{"labelId":"LBL_1","kind":"SESSION_LABEL_KIND_INTENT","name":"billing","active":true}}'
respond GET http://publicapi.test/v0/projects/p_1/session-label-settings 200 '{"settings":{"confidenceThreshold":0.7,"minUserTurns":1}}'
respond PUT http://publicapi.test/v0/projects/p_1/session-label-settings 200 '{"settings":{"confidenceThreshold":0.8,"minUserTurns":1}}'

! exec lk --user-auth agent eval validate --file eval.json
stdout '^criteria: needs at least one criterion$'
stderr 'the definition has 1 violation\(s\), so it can''t be published'

exec lk --user-auth agent eval create --name resolved --file eval.json
stderr 'Created eval EVAL_1 \(resolved\)\. Its draft scores nothing until you publish it: lk agent eval publish EVAL_1'

# Save sends the draftEtag it was given and reads nothing first.
exec lk --user-auth agent eval save EVAL_1 --file eval.json --etag e1
stderr 'Saved the draft of eval EVAL_1, draftEtag e2'

# The run can't ask, so publish refuses without --yes, after reading the
# draft to name it, and publishes nothing.
! exec lk --user-auth agent eval publish EVAL_1 -m first
stderr 'publishing EVAL_1 makes LiveKit score live sessions with it; re-run with --yes to go ahead'

# A script that skips the question must name the draft it read.
! exec lk --user-auth --yes agent eval publish EVAL_1 -m first
stderr '--yes needs --etag'

exec lk --user-auth --yes agent eval publish EVAL_1 -m first --etag e2
stderr 'Published eval EVAL_1 as revision 1'

! exec lk --user-auth agent eval label create --kind intent --name billing --description 'Billing questions'
stderr 're-run with --yes to go ahead'

exec lk --user-auth --yes agent eval label create --kind intent --name billing --description 'Billing questions'
stderr 'Created the intent label LBL_1 \(billing\)'

# A bad flag fails before any request.
! exec lk --user-auth agent eval label create --kind intent --name x --description y --rating good
stderr 'only an outcome has a rating'

exec lk --user-auth agent eval label settings set --confidence-threshold 0.8
stdout '^Confidence threshold: 0.8$'

requests
cmp stdout want-requests

-- eval.json --
{"pass_threshold": 0.75}
-- home/.livekit/cli-config.yaml --
default_user: u_1
users:
- id: u_1
email: dev@example.com
session_token: st_1
api_url: http://publicapi.test
default_project: p_1
projects:
- project_id: p_1
name: one
alias: one
-- want-requests --
POST http://publicapi.test/v0/projects/p_1/evals:validate bearer=st_1 project=p_1
POST http://publicapi.test/v0/projects/p_1/evals bearer=st_1 project=p_1
PUT http://publicapi.test/v0/projects/p_1/evals/EVAL_1/draft bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/evals/EVAL_1 bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/evals/EVAL_1 bearer=st_1 project=p_1
POST http://publicapi.test/v0/projects/p_1/evals/EVAL_1/draft:publish bearer=st_1 project=p_1
POST http://publicapi.test/v0/projects/p_1/session-labels bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/session-label-settings bearer=st_1 project=p_1
PUT http://publicapi.test/v0/projects/p_1/session-label-settings bearer=st_1 project=p_1
10 changes: 9 additions & 1 deletion cmd/lk/user_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,17 @@ func signInCommand() string {
// or missing session suggests re-auth; a permission denial explains that the
// signed-in account/session lacks access and points at the API-key escape hatch
// (rather than silently falling back to API-key "admin" access): re-running
// without --user-auth. Other errors
// without --user-auth. A refused request lists the fields that are wrong, one
// per line, when the API named them. Other errors
// pass through unchanged.
func cloudAPIError(err error) error {
if violations := public.FieldViolations(err); len(violations) > 0 {
var lines strings.Builder
for _, v := range violations {
fmt.Fprintf(&lines, "\n %s: %s", v.Field, v.Description)
}
return fmt.Errorf("%w%s", err, lines.String())
}
switch {
case public.IsUnauthenticated(err):
return fmt.Errorf("%w (run %s to sign in again)", err, signInCommand())
Expand Down
31 changes: 31 additions & 0 deletions cmd/lk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
package main

import (
"context"
"errors"
"fmt"
"maps"
"math"
"os"
"strings"

"charm.land/huh/v2"
"github.com/joho/godotenv"
"github.com/mattn/go-isatty"
"github.com/twitchtv/twirp"
Expand Down Expand Up @@ -599,3 +601,32 @@ func int32Flag(cmd *cli.Command, name string) (int32, error) {
}
return int32(v), nil
}

// confirmAction asks the user to agree to a change that is hard to undo,
// with title as the question and description under it. yes (--yes) agrees
// without asking. A run that can't ask fails with refusal, which says what
// the change does, and tells the user to pass --yes.
func confirmAction(ctx context.Context, yes bool, title, description, refusal string) error {
if yes {
return nil
}
if !isInteractive() {
return errors.New(refusal + "; re-run with --yes to go ahead")
}
confirmed := false
if err := huh.NewForm(huh.NewGroup(util.Confirm().
Title(title).
Description(description).
Value(&confirmed).
WithTheme(util.FormTheme()))).
RunWithContext(ctx); err != nil {
if errors.Is(err, huh.ErrUserAborted) {
return errors.New("aborted")
}
return err
}
if !confirmed {
return errors.New("aborted")
}
return nil
}
56 changes: 54 additions & 2 deletions pkg/public/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ func (c *Client) DeleteProject(ctx context.Context, projectID string) error {
// and the server's message. Callers can errors.As for it — notably via
// IsUnauthenticated / IsPermissionDenied.
type APIError struct {
Status int
Status int
// Code is the gRPC status code of the API's error envelope, such as
// codeAborted, or 0 when the envelope had none. Several codes share an
// HTTP status, so a caller that must tell them apart reads Code.
Code int
Message string
// details are the error envelope's typed details: JSON objects naming their
// type in "@type" beside the fields. Read them through helpers such as
Expand Down Expand Up @@ -181,11 +185,16 @@ func IsNotFound(err error) bool {
// with) and falling back to the raw body.
func responseError(status int, body []byte) error {
var env struct {
Code json.RawMessage `json:"code"`
Message string `json:"message"`
Details []json.RawMessage `json:"details"`
Error json.RawMessage `json:"error"`
}
if err := json.Unmarshal(body, &env); err == nil {
// The auth middleware's envelope has a string code; only the
// google.rpc.Status one has a number.
var code int
_ = json.Unmarshal(env.Code, &code)
msg := env.Message
if msg == "" && len(env.Error) > 0 {
var nested struct {
Expand All @@ -196,7 +205,7 @@ func responseError(status int, body []byte) error {
}
}
if msg != "" {
return &APIError{Status: status, Message: msg, details: env.Details}
return &APIError{Status: status, Code: code, Message: msg, details: env.Details}
}
}
msg := strings.TrimSpace(string(body))
Expand Down Expand Up @@ -229,6 +238,49 @@ func errorDetail(err error, fullName string, v any) bool {
return false
}

// FieldViolation is one problem with a field of a request the Public API
// refused: the field's path, such as config.httpTools[0].url, and what is
// wrong with it.
type FieldViolation struct {
Field string `json:"field"`
Description string `json:"description"`
}

// FieldViolations returns the field violations of err's google.rpc.BadRequest
// detail, which the Public API sends with an InvalidArgument that names each
// field that is wrong. It returns nil when err has none.
func FieldViolations(err error) []FieldViolation {
var detail struct {
FieldViolations []FieldViolation `json:"fieldViolations"`
}
if !errorDetail(err, "google.rpc.BadRequest", &detail) {
return nil
}
return detail.FieldViolations
}

// gRPC status codes that callers tell apart by APIError.Code.
const (
codeFailedPrecondition = 9
codeAborted = 10
)

// IsAborted reports whether err is the Public API's Aborted error: a request
// that named a version of something, such as an eval draft's etag, that is no
// longer the current one.
func IsAborted(err error) bool {
var apiErr *APIError
return errors.As(err, &apiErr) && apiErr.Code == codeAborted
}

// IsFailedPrecondition reports whether err is the Public API's
// FailedPrecondition error: a request that the target's current state
// refuses, such as publishing a draft whose base revision is no longer live.
func IsFailedPrecondition(err error) bool {
var apiErr *APIError
return errors.As(err, &apiErr) && apiErr.Code == codeFailedPrecondition
}

// okOrError returns nil for a 200 response and a classified APIError otherwise.
// Used by delete/remove/cancel operations whose success payload is empty.
func okOrError(status int, body []byte) error {
Expand Down
Loading
Loading