Skip to content

chore: server runtime type - #6774

Merged
William FH (hinthornw) merged 8 commits into
mainfrom
wfh/server_types
Feb 10, 2026
Merged

William FH (hinthornw) merged 8 commits into
mainfrom
wfh/server_types

Conversation

@hinthornw

@hinthornw William FH (hinthornw) commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Main jtbd here:
a) clarify who/how a graph is being accessed and make the factory aware of the context where relevant (and make it obvious when it is available)
b) make it more clear when you can bypass / defer resources with expensive lifespans (like MCp connections)
c) make auth access more type-safe.

Gives us room to add other information, like:

  • langsmith distributed tracing information

---- old
Can start doing things like this:

def my_graph(runtime: ServerRuntime):
     if runtime.ensure_user().permissions not in ("foo"):
         raise ValueError("bar")

etc.

Points of expected confusion:

  • You won't have a stream_writer in this context.
  • This won't be an accessible object within the graph, only the graph factory.

For maintainers, related draft PR int he server #6774

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Am I understanding that the information that we'd want to access here would be:

  • runtime context
  • user info
  • access context

I presume store and stream writer wouldn't be accessible, but maybe I'm not quite understanding where this would be plumbed through.

If so, might make sense to have a different data structure with just these? Specifically I'm a little concerned about making "runtime" accessible before runtime...

Not fully opposed to this though, I've been thinking about an AgentRuntime concept for create_agent :).

Comment on lines +34 to +35
!!! warning "Beta"
This API is in beta and may change in future releases.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Love

@hinthornw
William FH (hinthornw) force-pushed the wfh/server_types branch 2 times, most recently from 0f62839 to 15e03b2 Compare February 10, 2026 15:35

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we want to call it XXXRuntime? ServerContext probably even more confusing?

Lots of the terms we use are overloaded, just wanted to check.

It makes me feel better that we're not inheriting from langgraph's runtime because for the read cases we'd have to manually construct a Runtime instance which feels wrong.



@dataclass(kw_only=True, slots=True, frozen=True)
class _ServerRuntimeBase(Generic[ContextT]):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why is this one generic on context t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lol should only be the execution one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah jk. want it for execution_runtime() to show the return type. Can also create a sibling to execution context butI think I prefer to just keep onthe base for now.

Comment thread libs/sdk-py/langgraph_sdk/runtime.py Outdated
Comment on lines +92 to +93
@property
def execution_runtime(self) -> _ExecutionRuntime[ContextT] | None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this method actually helpful? maybe would be helpful to see usage somewhere

@hinthornw William FH (hinthornw) Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Very useful. I show examples below in the docstring. We do this in a few different projects already using our n on-type-safe equivalents

@hinthornw
William FH (hinthornw) marked this pull request as ready for review February 10, 2026 16:12
@hinthornw
William FH (hinthornw) enabled auto-merge (squash) February 10, 2026 16:50
@hinthornw
William FH (hinthornw) merged commit a734f5e into main Feb 10, 2026
59 checks passed
@hinthornw
William FH (hinthornw) deleted the wfh/server_types branch February 10, 2026 16:53
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