agents icon indicating copy to clipboard operation
agents copied to clipboard

Running agents in uvicorn

Open quancore opened this issue 1 year ago • 1 comments

Can you provide an example of how can I run the agents in uvicorn app? I am using fastapi on the backend and when a post request is made, I setup agents and run to the worker but unfortunately, it is not working.

quancore avatar Aug 28 '24 12:08 quancore

It may due to the event loop used by uvicorn, since by default uvicorn uses uvloop, not asyncio.

You can try to swap uvloop with asyncio as event loop to be used, either from the cli when launching the app

uvicorn main:app --loop asyncio

or in the main function

uvicorn.run("main:app", loop='asyncio')

Another possible solution is to make asyncio use the uvloop event loop by default, as explained here

import asyncio
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

edochi avatar Aug 28 '24 19:08 edochi