How to access data injected by HTTP middleware in Graph execution

I added an HTTP middleware that gets an object from our ORM, and injects it to the request. I want to access this in the graph execution, ideally pass it in RuntimeContext. Whats the best way to do this?

hi @michael6

do I understand you correctly - you are seeking a way to propagate a request data info into graph runs?
And you want to inject it from Langsmith?

If I am mistaken, could you provide some pseudo-code and clarify?

I am using langsmith with deploy. Previously I was instrumenting my own /threads/{thread_id}/runs/stream endpoint, that had this logic:

context = {"db": db}

return await agent.ainvoke(initial_state, config=config, context=context)

Then I would access the context / db using runtime.context.db in nodes / tools where I inject a runtime.

But now I let langsmith handle that endpoint, and I am instead adding an HTTP middleware that can inject data into the request, or call other functions. Given I am letting langsmith call the invoke / stream function, what is the best way to set the context for that downstream call.

I’ve come to the conclusion that I should just pull any static identifiers via configurable. Using LangSmith deployment there doesnt seem to be a good way to setup the context since Im not making that initial call into the graph.