Skip to content

feat(agent): lk agent list, status and config through the Public API when signed in - #1138

Open
Topherhindman wants to merge 7 commits into
mainfrom
topherhindman/agent-user-auth-list
Open

Topherhindman wants to merge 7 commits into
mainfrom
topherhindman/agent-user-auth-list

Conversation

@Topherhindman

@Topherhindman Topherhindman commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Under --user-auth, lk agent list, lk agent status and lk agent config now read agents through the Public API's AgentService. Before, every agent command reached cloud agents through the token bridge. The bridge needs the Agent.Admin grant, so only a project admin could list agents or see an agent's status. AgentService takes agent:read, so READ and WRITE members can now run these three commands. lk asks for no token for them.

What's in it

The first three commits are the scaffold from topherhindman/agent-user-auth, which has no PR of its own:

  • refactor(agent): each agent command takes an agentAPI or privateLinkAPI interface with the SDK's signatures. The SDK client implements them with an API key, and userAuthAgentAPI implements them under --user-auth. This follows the lk sip/lk number precedent (feat(lk): lk sip and lk number use the Public API under --user-auth #1124).
  • fix(agent): when the Public API refuses the bridge's token, the error says the command needs a project admin and that an API key works meanwhile. It no longer says the user lacks access to the project.
  • fix(agent): fixes for two index panics: agent logs on an agent with no deployment, and agent create's log tail when no region comes back.

The native list and get:

  • chore(public): regenerates pkg/public once, from livekit/public-api-server@372fb27e (production v2026-12-02-2258): AgentService, with the Agent that livekit/public-api-server#240 reshaped (agentId, agentName, kind, status as AgentStatus and agentBuilderId at the top, and the cloud agent as cloud, in a oneof), and AgentBuilderService.UpdateAgentSecrets. The only removal is the eval criterion type "code" and its check field (livekit/public-api-server#256), which nothing in lk reads.
  • feat(public): ListAgents, GetAgent and IsAgentNotFound. An agent's cloud agent (cloud, info before the reshape) is livekit.AgentInfo sent as protojson, so it is decoded with protojson, as the telephony methods decode theirs. Every field survives.
  • test(lk): the fake cloud used by the testscripts can now answer a Twirp protobuf client from a protojson body. Before, a script could only answer with an empty message.
  • feat(agent): userAuthAgentAPI.ListAgents calls GetAgent when the request names an agent, and ListAgents otherwise. Every other method still goes through the bridge.
  • refactor(agent): public.Agent follows the new shape (AgentID, AgentName, Kind, Status, AgentBuilderID, Cloud). lk reads cloud as it read info, and leaves out an agent without one, so the output doesn't change.

Decisions

  • Unknown agent. GetAgent's NotFound "agent not found" becomes an empty list, which is what cloud agents returns. So status says "no agents found" and config says "agent not found" in both modes. A "project not found" stays an error.
  • Placeholders. The Public API leaves out a version or deploy time that cloud agents doesn't know. Cloud agents lists those as --- and the zero time. lk puts --- and the zero time back (cloudAgentsInfo), so the table and --json output match the API-key path. Without this, list showed 1970-01-01T00:00:00Z as the deploy time of an agent that was never deployed.
  • Other commands. logs, the agent picker, and the summary after a deploy also read agents through ListAgents, so they read them the same way. logs still streams through the bridge, so it still needs an admin.

Output differences vs the API-key path

  • The agent name <Pending> or <Unavailable> can't be put back, because the Public API leaves it out. Under --user-auth, list shows an empty Dispatch Name for such an agent.
  • list sorts by deploy time. Agents with the same deploy time, such as two agents that were never deployed, can come out in a different order: cloud agents lists them in database order, and the Public API lists them in ID order.

Open questions

  • Should lk drop the cloud agents placeholders in both modes, instead of putting them back under --user-auth?
  • The Public API's status and agentBuilderId are decoded but not shown. Should status or list show them?

Blockers

  • pkg/public generated from livekit/public-api-server@372fb27e (production v2026-12-02-2258).

Testing

  • GOPRIVATE= go build ./..., go vet ./cmd/lk/... ./pkg/..., go test ./cmd/lk/... ./pkg/... and golangci-lint run ./cmd/lk/... ./pkg/public/... all pass.
  • New testscript agent-reads-with-user-auth. It runs list, list --id, status (table and --json) and config, once with an API key against a fake cloud agents and once under --user-auth against a fake Public API, with the same agents. It checks that both modes print the same output and write the same livekit.toml, and it checks an unknown agent in both modes. The fake Public API refuses any token request, as it does for a member below admin, and the request log shows that lk made none. Without cloudAgentsInfo the script fails on the deploy time and version of the agent that was never deployed.
  • Unit tests decode an agent with every field of AgentInfo set, and the fields of the messages inside it. They also cover cloudAgentsInfo, a refused get, and a "project not found".

Demo

Recorded on staging, not uploaded yet: ~/hosted-agents-work/demos/M1/m1-list-status-config.mp4 (write-up ~/hosted-agents-work/demos/M1/README.md). The Public API ran locally from this branch against staging cloud-agents, reading the staging database read-only; lk from #1138. A WRITE member is refused by lk main's token bridge, then runs lk agent list, status and config under --user-auth; a READ member and an ADMIN do the same.

Depends on #1136 (the hints name lk agent builder).

Picks up the Public API's AgentService: list, get, versions, secret
names, build logs and client settings of cloud agents; restart, roll
back, promote and delete them and update their secrets; create, deploy
and build them from source; and their private links. Also picks up
AgentBuilderService.UpdateAgentSecrets. Nothing on main calls them.

The eval criterion type "code" and its check field are gone
(livekit/public-api-server#256). Nothing in lk reads them.

Every other path, operation and type is unchanged.

Generated from livekit/public-api-server@372fb27, production v2026-12-02-2258
The cloud agent commands and the private-link commands now call one
interface each, as the sip and number commands do (#1124).
With an API key, server-sdk-go's cloudagents client implements both, so
nothing changes. Under --user-auth, userAuthAgentAPI implements both: it
holds the Public API client and the cloudagents client on the token bridge,
and sends every call through the bridge for now. A later change moves a
method to the Public API's AgentService without touching the commands.

Two scripts pin the requests in each mode.
Under --user-auth, every agent command reaches cloud agents through the
token bridge, which asks the Public API for the Agent.Admin grant. The
Public API gives that grant only to a project admin, so a writer or a
reader got cloudAPIError's hint that their account doesn't have access to
the project, inside a Twirp "failed to do request" line.

userAuthAgentAPI now passes each bridge error through bridgeError. When the
Public API refused the token, the error says the command needs a project
admin, keeps the Public API's message, and says that a project API key
works meanwhile. Any other error comes back as it is.
`lk agent logs` streamed from the region of the agent's first deployment
without checking that it has one, and `lk agent create` streamed from the
first server region cloud agents returned, without checking that it returned
one. Either panicked with an index out of range.

logs now says "no agent deployments found" for an agent with no deployment,
as it does for no agent. create says the agent was created and points at
`lk agent logs`. The create path runs only at an interactive prompt, so only
logs has a test.
ListAgents and GetAgent return a cloud agent's info as livekit.AgentInfo,
which the API sends as protojson, so they decode it as the telephony
methods decode their messages: lk's agent commands already print that
type, and the round trip keeps every field. IsAgentNotFound tells
GetAgent's NotFound for an agent from the one for a project.

Agent is as livekit/public-api-server#240 shapes it: AgentID,
AgentName, Kind, Status and Cloud, the cloud agent as
livekit.AgentInfo, nil when the API sends none.

Tested: unit tests that decode an agent with every field of AgentInfo
and the messages in it set, a list that reports a next page, a missing
payload, and both NotFound answers.
server-sdk-go's Twirp clients speak protobuf, so a script could only
answer a Twirp method with an empty message. A Twirp method's 200 body
is now its response message as protojson, which the fake checks
strictly when the script sets it and sends as protobuf to a client
that asks for protobuf. An empty body is still an empty message.
Under --user-auth, every agent command reached cloud agents through
the token bridge, which needs the Agent.Admin grant, so only a project
admin could list agents or show an agent's status. ListAgents under
--user-auth now calls the Public API's AgentService, which a READ
member may call and which mints no token: GetAgent when the request
names an agent, ListAgents otherwise. Every other method still goes
through the bridge.

- An agent the project doesn't have is an empty list, as cloud agents
  answers, so status says "no agents found" and config "agent not
  found" in both modes. A project that isn't found is still an error.
- The Public API leaves out a version or deploy time that cloud agents
  doesn't know, where cloud agents lists "---" and the zero time.
  cloudAgentsInfo puts those back, so list, status and config print
  the same in both modes; without it list showed a deploy time of
  1970-01-01 for an agent never deployed. The agent name "<Pending>"
  or "<Unavailable>", which the Public API also leaves out, can't be
  put back and stays empty.
- Commands that pick an agent, or read its regions before another
  call (logs, deploy's summary), read it the same way.

- lk reads an agent's cloud, and leaves out an agent without one, as
  cloud agents lists only cloud agents.

Tested: a testscript that runs list, list --id, status (table and
--json) and config with an API key and under --user-auth against the
same agents, compares the output, checks an unknown agent in both
modes, and that no token is requested; unit tests for cloudAgentsInfo
and for a get the Public API refuses.
@Topherhindman
Topherhindman force-pushed the topherhindman/agent-user-auth-list branch from 13d2b0c to 507fae9 Compare December 3, 2026 00:18
@Topherhindman
Topherhindman marked this pull request as ready for review December 3, 2026 00:48

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@rektdeckard

Copy link
Copy Markdown
Member

I think keeping placeholder values is fine, and status would be nice to show in both places -- but not blocking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants