Over in the OmbuLabs.ai blog, our post on the ReAct pattern in Ruby walked through building an agent that reasons about a task, calls tools, and acts on the results, all inside a single Ruby script. That’s fine for a command-line experiment. It’s a different story once that same agent needs to run inside a Rails app, triggered by a web request, where a multi-step reasoning loop can easily take longer than any request should stay open.
The obvious fix is to move the agent into a background job. Sidekiq already handles work that takes a while, so an agent’s loop of thinking, searching, and acting should fit right in. It does, mostly, but a job’s retry semantics were built around retrying a database write, not a chain of API calls that has real, sometimes irreversible, side effects.
In this article, you’ll learn why an agent’s reasoning loop doesn’t survive a naive move into a background job, how to make its side effects idempotent against Sidekiq retries, and how to stream its progress to the user while it runs.
Read more of Making AI Agents Safe to Retry