How to handle httpx client dependency

This feels like a silly question, but I’m pretty confused on how I should handle an httpx client dependency for my tools. I want to reuse the same client so that I can take advantage of connection pooling. If I were to use LangGraph, the documentation would suggest that the Runtime Context would be the correct place for the client. I can technically make this work, but it feels like I’m hacking around it, since the Context should be serializable. This is especially awkward with LangGraph Studio when trying to create an assistant. I’ve seen some suggestions to use FastAPI custom lifespans instead. I can use that I suppose although I’m not sure how that would work with LangGraph Studio…

Any recommendations? Thanks!

1 Like