1

I implemented langchain as a Python API, created via FASTAPI and uvicorn.

The Python API is composed of one main service and various microservices the main service call when required. These microservices are tools. I use 3 tools: web search, image generation, image description. All are long running tasks.

The microservices need to be called as a chain. I.e. the output of one microservice can be used as the input to another microservice (who's output is then returned, or used as an input to another tool, as required).

Now I have made each microservice asynchronous for better scalability. As in, they do the heavy lifting in a background thread, managed via Celery+Redis.

This setup breaks the chain. Why?

Because the first async microservice immediately returns a task_id (to track the background work) when it is run via Celery. This output (the task_id) is passed as input to the next microservice. But this input is essentially meaningless to the second microservice. It's like giving a chef a shopping receipt and expecting them to cook a meal with it.

The next microservice requires the actual output from the first one to do its job, but it's got the task_id instead, which doesn't hold any meaningful information for it to work with.

This makes the chain return garbage output ultimately. So in that sense, the chain "breaks".

How else could I have implemented my langchain execution to ensure concurrency and parallelism?

Please provide an illustrative example.

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
  • 1
    Have a shared storage / API where the 2nd service would query the object by `task_id` - I mean I'm not sure what else you are hoping to get from an answer. – taleodor Jun 21 '23 at 12:12

0 Answers0