fix(sdk-py): expose ls_user_id on StudioUser

This commit is contained in:
Caspar Broekhuizen
2026-09-08 16:55:23 -07:00
parent 0199b519e1
commit a0d8d88b28
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -218,6 +218,8 @@ class BaseUser(typing.Protocol):
class StudioUser:
"""A user object that's populated from authenticated requests from the LangGraph studio.
`ls_user_id` is the canonical LangSmith user ID when supplied by Agent Server.
Note: Studio auth can be disabled in your `langgraph.json` config.
```json
@@ -250,10 +252,11 @@ class StudioUser:
```
"""
__slots__ = ("_is_authenticated", "_permissions", "username")
__slots__ = ("_is_authenticated", "_permissions", "ls_user_id", "username")
def __init__(self, username: str, is_authenticated: bool = False) -> None:
self.username = username
self.ls_user_id: str | None = None
self._is_authenticated = is_authenticated
self._permissions = ["authenticated"] if is_authenticated else []
+14
View File
@@ -1,8 +1,22 @@
import pytest
from typing_extensions import assert_type
from langgraph_sdk import Auth
def test_studio_user_langsmith_id() -> None:
def langsmith_id(user: object) -> str | None:
if isinstance(user, Auth.types.StudioUser):
return assert_type(user.ls_user_id, str | None)
return None
user = Auth.types.StudioUser("login-user", is_authenticated=True)
assert langsmith_id(user) is None
user.ls_user_id = "langsmith-user"
assert langsmith_id(user) == "langsmith-user"
assert user.identity == "login-user"
def test_handler_multiple_resources_and_actions() -> None:
auth = Auth()