-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serve multiple agents from a single chainlit server, access request path/query parameters #1260
Conversation
Thanks for the contrib @nethi! As I see it, there's two major and desirable features in this one. But they're a big overhaul, so it's essential we think and align well on it. In cases of larger overhauls, I usually prefer to hash out the features really well in issues, to make sure we can accept as much of your work as possible. In addition, to facilitate review, feedback and overview, I strongly prefer to have separate PR's for separate features. In this case, your work overlaps with the following two issues;
After a quick read through your PR and code, in light of the more general suggestions above, I'm observing that:
1. Copying
|
Thank you for your detailed comments/observations. I am inclined to pass Request object, but two concerns: Also, I have been using chainlit only for the last 8 weeks or so, so I mayn't fully understand some of the design choices and rationale. I can rework the PR based on consensus. |
This PR adds support to serve multiple agents from a single chainlit server. A good example is a no-code agent server that takes agent_id from URL (request path or query parameters), fetches details of the agent from another server and setups chainlit agent accordingly.
In order to do this, I needed to do the following.
Several chainlit hooks donot have any way to get request path or query parameter details from several of the http hooks. I have added a ContextVar setup and a utility function to access fastapi request in chainlit http hooks
With this, we can now mount chainlit on path like /agents/{agent_id} and access path in hooks
For http based cl hooks
For ws based cl hooks
Besides being able to serve multiple agents from single server, accessing URL path and query parameters is also a frequent ask from several chainlit users in the forums.
while we can set http endpoint path as /agents/{agent_id}, we cannot use this approach for Socket.io as socket.io asgi server doesn't support path parameters or wild card prefixes. In the above example, socket.io path will become /agents/{agent_id}/ws/socket.io, which won't work. But socket.io server allows to add any extra path parameters such as /ws/socket.io/foobar
With this ability to customize socket.io path, it can instead be configured as, for example: /agents/ws/socket.io. With this, a custom frontend can connect to /agents/ws/socket.io/agent1. websocket hooks then can use logic like this to extract "agent1" from path parameter.