Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/agent-db-scoped-grants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"livekit-api": patch
"livekit-protocol": patch
---

Scope agent database access to a thread or a database: `AgentThreadGrants` gains `sql`, the new `agentDatabase` claim (`AgentDatabaseGrants`, `with_agent_database_grants`) grants `read`, `write` and `delete` on listed databases plus project-wide `create` and `list`, and `AgentGrants.database_admin` is removed.
2 changes: 2 additions & 0 deletions livekit-api/livekit/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
AgentGrants,
AgentEndpointGrants,
AgentThreadGrants,
AgentDatabaseGrants,
VideoGrants,
SIPGrants,
AccessToken,
Expand All @@ -71,6 +72,7 @@
"AgentGrants",
"AgentEndpointGrants",
"AgentThreadGrants",
"AgentDatabaseGrants",
"VideoGrants",
"SIPGrants",
"AccessToken",
Expand Down
23 changes: 21 additions & 2 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ class AgentGrants:
admin: bool = False
# manage simulations and scenarios for evaluating agents
simulation_admin: bool = False
# access the project's agent databases
database_admin: bool = False
# manage the project's agent dispatch queue
dispatch_admin: bool = False

Expand Down Expand Up @@ -130,6 +128,21 @@ class AgentThreadGrants:
write: bool = False
read: bool = False
delete: bool = False
# open a covered thread's database, whose id is the thread's
sql: bool = False


@dataclass
class AgentDatabaseGrants:
# databases that may be read, written and deleted
database_ids: Optional[List[str]] = None
read: bool = False
write: bool = False
delete: bool = False
# create databases in the project
create: bool = False
# list the project's databases
list: bool = False


@dataclass
Expand All @@ -145,6 +158,7 @@ class Claims:
agent: Optional[AgentGrants] = None
agent_endpoint: Optional[AgentEndpointGrants] = None
agent_thread: Optional[AgentThreadGrants] = None
agent_database: Optional[AgentDatabaseGrants] = None
attributes: Optional[dict[str, str]] = None
sha256: Optional[str] = None
room_preset: Optional[str] = None
Expand Down Expand Up @@ -217,6 +231,10 @@ def with_agent_thread_grants(self, grants: AgentThreadGrants) -> "AccessToken":
self.claims.agent_thread = grants
return self

def with_agent_database_grants(self, grants: AgentDatabaseGrants) -> "AccessToken":
self.claims.agent_database = grants
return self

def with_identity(self, identity: str) -> "AccessToken":
self.identity = identity
return self
Expand Down Expand Up @@ -322,6 +340,7 @@ def verify(self, token: str, *, verify_signature: bool = True) -> Claims:
agent=_parse_grants(claims, "agent", AgentGrants),
agent_endpoint=_parse_grants(claims, "agentEndpoint", AgentEndpointGrants),
agent_thread=_parse_grants(claims, "agentThread", AgentThreadGrants),
agent_database=_parse_grants(claims, "agentDatabase", AgentDatabaseGrants),
)

if claims.get("roomPreset"):
Expand Down
132 changes: 72 additions & 60 deletions livekit-protocol/livekit/protocol/agent.py

Large diffs are not rendered by default.

52 changes: 44 additions & 8 deletions livekit-protocol/livekit/protocol/agent.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading