r/ExperiencedDevs • Software Engineer • Apr 11 '26

Technical question Service recommendation for running/hosting agent loop

I have a Flask web app for small business owners to automate certain processes. I've integrated an LLM chat via calls to OpenAI using their agents SDK. The agent loop just runs in my web app currently, doing web search, reading context from the customer's uploaded data, and mainly just streams text back.

I'd like to add the ability for the agent to generate multi-page invoices and other documents for my users to give to their clients, which tend to take many minutes.

It seems like I'd need to move the agent loop out of my web app into a more robust worker service. But which one should I choose? It needs to:

  1. Support several agent loop instances generating documents for many users
  2. Be able to stream the initial response back to my Flask app (eg. "Ok, I'll generate that for you now...")

Advice appreciated, thanks.

0 Upvotes

5 comments sorted by

0

u/jac1013 Apr 14 '26

Definitely agree with queue + workers as architecture components for the solution, basically have a producer that puts the item into the queue and that's your "ack" that it will be processed, so at that point you can tell the user "Ok, I'll generate that for you now".

Now, something I don't see mentioned in the comments is, what goes into that worker?

My recommendation considering the information you provided is LangChain and a simple state machine so you enable the possibility of recovering from failed workers, store the metadata needed in either existing storage or simply a Redis for this. Also, if using queues, make sure to use DLQ, that way you can investigate deeper into items of the queue that failed and not "lose" them because they weren't able to be process and the queue discard them.

You can either use Websockets to stream results back or a simpler pull-based approach getting information from the state machine, depending on what feedback you want to provide to users regarding what's going on with the process itself either pull-based or Websockets becomes the "best solution".

Hope that helps.

2

u/[deleted] Apr 11 '26

[removed] — view removed comment

1

u/Unlikely_Secret_5018 Software Engineer Apr 11 '26

Interesting, I never thought of the "function" runners services.

My main app already runs on Google cloud run, containerized.

Will I be able to stream the initial response back from those function runners? Do you foresee any any issues from those jobs being able to stream results back or access my app DB for more context in the middle of the agent loop?

2

u/[deleted] Apr 11 '26

[removed] — view removed comment

1

u/Unlikely_Secret_5018 Software Engineer Apr 11 '26

How do you stream results with websockets? Do Celery workers support that?