Building Production-Grade AI Agents with Distributed Architecture and Error Recovery

parcha · Finance · 2023 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Compliance and operations agents

Parcha needed production-grade agents for KYB/KYC-style compliance workflows, but its initial LangChain/websocket prototype suffered from unreliable communication, noisy scratchpads, weak memory retrieval, no recovery after multi-minute failures, hallucinated tools, and low reusability.

Constraints:

Architecture

Parcha evolved from a synchronous websocket/LangChain prototype into asynchronous long-running agents with pub/sub updates, REST/polling/SSE integration, Slack threads, and headless evaluation. Complex SOPs are decomposed into coordinator and worker agents: the coordinator plans from the master SOP, workers execute local task subsets with their own scratchpads, and the coordinator synthesizes final recommendations. Redis supplies relevant memory keys to tools without polluting prompts, RQ workers queue and execute jobs, typed tool exceptions are fed back for self-correction, and reusable document-extraction/tools interfaces reduce custom work per workflow.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  operator-or-workflow-trigger["Operator or workflow trigger"] --> async-agent-service["Async agent service"]
  async-agent-service --> status-update-channels["Status update channels"]
  status-update-channels --> customer-action-requests["Customer action requests"]
  customer-action-requests --> coordinator-agent["Coordinator agent"]
  async-agent-service --> rq-worker-queue["RQ worker queue"]
  async-agent-service --> coordinator-agent
  master-sop["Master SOP"] --> coordinator-agent
  coordinator-agent --> worker-agents["Worker agents"]
  worker-agents --> scoped-scratchpads["Scoped scratchpads"]
  worker-agents --> tool-interface["Tool interface"]
  worker-agents --> redis-memory-store["Redis memory store"]
  redis-memory-store --> tool-interface
  tool-interface --> domain-api-tools["Domain API tools"]
  tool-interface --> document-extraction-tool["Document extraction tool"]
  document-extraction-tool --> judgment-llm-call["Judgment LLM call"]
  tool-interface --> typed-exception-feedback["Typed exception feedback"]
  typed-exception-feedback --> worker-agents
  rq-worker-queue --> typed-exception-feedback
  worker-agents --> coordinator-agent
  coordinator-agent --> final-assessment-renderer["Final assessment renderer"]
  final-assessment-renderer --> webhook-automation["Webhook automation"]
  async-agent-service --> pear-benchmark-suite["PEAR benchmark suite"]
  microservice-agent-tools["Microservice agent tools"] --> async-agent-service
  microservice-agent-tools --> tool-interface
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Operator or workflow trigger Starts an agent job from a web service, REST API, Slack workflow, webhook, or headless evaluation run. Async agent service, Status update channels
Async agent service Runs agents as long-running asynchronous processes instead of holding synchronous websocket sessions. Operator or workflow trigger, Status update channels, RQ worker queue, Coordinator agent
Status update channels Publishes progress through pub/sub, server-sent events, REST polling, and Slack thread replies. Async agent service, Operator or workflow trigger, Customer action requests
Customer action requests Handles clarifications, missing information, or follow-up actions from customers during long-running tasks. Status update channels, Coordinator agent
Master SOP Defines the overall compliance procedure and required checks for a workflow such as KYB. Coordinator agent
Coordinator agent Builds the initial plan from the master SOP, delegates subsets to workers, and synthesizes final recommendations. Master SOP, Worker agents, Final assessment renderer, Customer action requests
Worker agents Execute focused sub-SOPs such as identity verification, incorporation-document validation, or watchlist checks. Coordinator agent, Scoped scratchpads, Tool interface, Redis memory store
Scoped scratchpads Keep each worker's context focused on local evidence and observations rather than a global noisy scratchpad. Worker agents, Tool interface
Tool interface Wraps domain APIs, document extraction, address verification, watchlist checks, and other commands for worker agents. Worker agents, Domain API tools, Document extraction tool, Typed exception feedback
Domain API tools Third-party and homegrown services such as Google Maps, risk profile, watchlist, applicant data, and business lookup tools. Tool interface, Redis memory store
Document extraction tool Reusable extraction component for OCR/document workflows, such as incorporation documents and pay stubs. Tool interface, Judgment LLM call
Judgment LLM call Second-step comparison call that judges extracted document information against self-attested data. Document extraction tool, Worker agents
Redis memory store In-memory key-value store used to share only relevant information between workers and tools. Worker agents, Tool interface, Async agent service
RQ worker queue Queues and executes asynchronous agent jobs with alerting on failure. Async agent service, Typed exception feedback
Typed exception feedback Feeds exception names and messages back to agents so they can retry, correct their own input, escalate, or move on. Tool interface, RQ worker queue, Worker agents
Final assessment renderer Produces detailed reports and approve/deny/escalate recommendations from gathered evidence. Coordinator agent, Webhook automation
Webhook automation Planned end-to-end automation trigger that acts on final assessments. Final assessment renderer, Operator or workflow trigger
PEAR benchmark suite Planned in-house benchmark for Plan, Execute, Accuracy, and Reasoning capabilities. Async agent service, Coordinator agent
Microservice agent tools Planned language-agnostic agent and tool services orchestrated as asynchronous DAGs. Async agent service, Tool interface, Webhook automation

Data flow

An operator, API caller, Slack workflow, or webhook triggers an agent job. The long-running agent service posts status through pub/sub, SSE, polling, or Slack thread replies rather than holding a fragile websocket open. A coordinator reads the master SOP and delegates subtasks such as identity verification, certificate validation, or watchlist checks to worker agents. Workers use scoped scratchpads, domain tools, Redis-backed memory keys, OCR/document extraction, and API integrations to gather evidence and conclusions. Tool errors return typed exception names/messages to the agent for self-correction or escalation. The coordinator combines worker evidence into a final approve/deny/escalate report and can be evaluated headlessly or integrated into customer workflows.

6 supporting quotes
“we had to build from scratch. ### Lessons learned #### Agents as async, long-running tasks. We now run our agents as long-running processes asynchronously. A web service can still trigger agents, but instead of communicating bi-directionally through WebSockets, they post updates”article, stated
“instead of communicating bi-directionally through WebSockets, they post updates using pub/sub. This helped us simplify the communication interface between the agent and the customer. It also made our agents more useful beyond a synchronous web service.”article, stated
“The coordinator develops an initial plan using the master SOP and delegates subsets of the SOP to “worker” agents”article, stated
“Rather than complicating our stack or risking polluting the scratchpad with noise, we decided to leverage an in-memory store we were already using for communication, Redis.”article, stated
“we are now leveraging well-typed exceptions in our tools to feed them back to the agent. If a tool fails, we send the exception name and message to the agent, allowing it to recover independently. This has helped us reduce the number of catastrophic failures”article, stated
“the coordinator uses all the evidence workers gather to develop a final recommendation. For example, in a KYB process, it’s common to perform tasks like verifying the applicant's identity, verifying if a certificate of incorporation provided as a PDF is”article, stated

Why this architecture

Parcha's production architecture responds directly to failures in the prototype. Asynchronous services replace fragile websockets because customer interactions were mostly one-way job updates. Coordinator/worker agents replace a monolithic SOP scratchpad because context windows became noisy. Redis-backed memory replaces prompt stuffing because workers only need relevant keys. Typed exceptions and queues replace all-or-nothing runs because minute-three failures should recover without restarting the whole task.

5 supporting quotes
“communication for this mostly uni-directional interaction. Our customers didn’t need a chatbot; they needed an agent to complete a job. * As we started testing our agents with our design partner’s SOPs, we realized it would take more than embedding the full text of instructions into one agent and”article, stated
“instead of adding a very complex SOP into one agent’s scratchpad, we have a coordinator <> worker model. The coordinator develops an initial plan using the master SOP and delegates subsets of the SOP to “worker” agents that gather evidence, make conclusions”article, stated
“By only adding relevant memory to the scratchpad, we save on LLM tokens, keep the context window clean, and ensure any worker agents pick the right information whenever needed. Human: Here are memories that you can provide to tools if they need them. These”article, stated
“This has helped us reduce the number of catastrophic failures significantly. System: Command digifi_data_loader_tool returned: Unable to execute command due to an error: 1 validation error for DataLoaderInput display_id field required”article, stated
“to build their agents quickly. To that end, we developed our agent and its tools interface, focusing on composability and extensibility. We now also have enough workflows from design partners to understand which building blocks we need to invest in. For example,”article, stated

Models used: Large Language Models · LangChain Agents · LLM extraction call · LLM judgment call

Scale

Alternatives considered (roads not taken)

Synchronous websocket conversations

Rejected because: Websockets caused reliability issues and did not match the mostly one-way job-completion interaction customers needed.

“Websocket connections caused many reliability issues and ended up not being the best tool for communication between our agents and their operators. We initially envisioned our agents as bi-directional, able to have a two-way conversation. In practice, after”article, stated
“In practice, after the initial interaction (when an operator asks an agent to perform a task like “do a KYB process on X customer”), the agent updates the customer until it completes the process.”article, stated

One monolithic agent with the full SOP in its scratchpad

Rejected because: As steps accumulated, the context window became noisy and the agent confused tools or skipped tasks.

“it would take more than embedding the full text of instructions into one agent and hoping for the best. The agent would confuse tools or skip tasks. As more steps were performed and results were added to the scratchpad, the context window would be full of”article, stated
“more than embedding the full text of instructions into one agent and hoping for the best. The agent would confuse tools or skip tasks. As more steps were performed and results were added to the scratchpad, the context window would be full of noise that the”article, stated

Single-call document extraction and verification

Rejected because: Long documents include irrelevant material, so asking one call to extract and judge produced poor results.

“Our initial approach to a verification task using an LLM was to enter the text extracted from the document using OCR and the self-attested information”article, stated
“Since documents are long and full of potentially irrelevant information, the results of such a task were not great.”article, stated

Vector DB or prompt-based memory for worker sharing

Rejected because: The team wanted to avoid more stack complexity and scratchpad pollution, so it reused Redis and injected only relevant keys.

“There are a lot of mechanisms for memory in agents or LLM apps out there: using vector DBs, adding a subset of the previous steps into the scratchpad”article, stated
“Rather than complicating our stack or risking polluting the scratchpad with noise, we decided to leverage an in-memory store”article, stated

Fail the whole agent run on tool errors

Rejected because: Failures late in long tasks caused poor customer experience; typed exceptions let agents self-correct or escalate.

“or the agent may choose the wrong input for a tool. Given how our agents were configured, any error would cause the agent to fail with no opportunity to recover. We now treat agents as asynchronous services with multiple failover mechanisms. They are queued and executed by worker processes”article, stated
“If a tool fails, we send the exception name and message to the agent, allowing it to recover independently. This has helped us reduce the number of catastrophic failures significantly. System: Command digifi_data_loader_tool returned: Unable to execute”article, stated

Patterns

async-message-orchestration (orchestration)

Parcha moved long-running agents to asynchronous processes with pub/sub, REST polling, SSE, Slack threads, RQ workers, and future webhooks.

3 supporting quotes
“We now run our agents as long-running processes asynchronously. A web service can still trigger agents, but instead of communicating bi-directionally through WebSockets, they post updates using pub/sub.”article, stated
“A web service can still trigger agents, but instead of communicating bi-directionally through WebSockets, they post updates using pub/sub. This helped us simplify the communication interface between the agent and the customer.”article, stated
“They are queued and executed by worker processes (we use RQ for this)”article, stated

multi-agent-orchestration (agent-architecture)

A coordinator agent decomposes a master SOP and delegates focused evidence-gathering subtasks to worker agents.

“consume the output from other agents. Now, instead of adding a very complex SOP into one agent’s scratchpad, we have a coordinator <> worker model. The coordinator develops an initial plan using the master SOP and delegates subsets of the SOP to “worker” agents that gather evidence, make”article, stated
“The coordinator develops an initial plan using the master SOP and delegates subsets of the SOP to “worker” agents”article, stated

tool-use-orchestration (execution)

Agents use custom API integrations, document extraction, address verification, risk-profile, watchlist, and other domain tools to complete SOP steps.

“We wrapped custom-built API integrations into tools and made them available to the agent.”article, stated
“Tools or commands**:** these can be other calls to language models (e.g. to summarize a document) or API calls to third parties”article, stated

agent-memory (memory)

Redis stores reusable memory keys that tools can pull as needed, keeping the worker scratchpad focused and reducing redundant tool execution.

“we decided to leverage an in-memory store we were already using for communication, Redis.”article, stated
“We now tell the agent pieces of information they have available (the keys to the information in Redis)”article, stated

prompt-chaining (reasoning)

Document workflows are split into an extraction call followed by a judgment/comparison call with a smaller prompt.

“We made this significantly better by separating the extraction process from judgment.”article, stated
“Then in a second trip to the LLM, we ask it to compare the information”article, stated

fallback-degradation (reliability)

Typed tool exceptions are routed back to agents so they can self-correct, retry, escalate, or move on instead of failing the whole task.

“If a tool fails, we send the exception name and message to the agent, allowing it to recover independently.”article, stated
“If the error was your fault, take a deep breath and try again. If not, escalate the issue and move on.”article, stated

human-in-the-loop-gate (operations)

Agents can ask clarifying questions, wait for missing information, and produce approve/deny/escalate recommendations for human review.

“They can still request actions from the customer, like asking for clarifications or waiting to receive a missing piece of information.”article, stated
“Provide a recommendation on whether to approve the customer or whether further review is needed”article, stated

eval-driven-development (evaluation)

Parcha planned PEAR benchmarks for planning, execution, accuracy, and reasoning, and can evaluate agents at scale as headless processes.

“API, followed through a Slack channel (they start threads and provide updates as replies until completion), and evaluated at scale as headless processes. Since agents can be triggered and consumed through REST (polling and SSE), our customers can integrate them with their workflows without”article, stated
“Implementing our in-house robust agent benchmarks, assessing the capabilities of our agents to Plan, Execute, be Accurate, and Reasoning”article, stated

Tradeoffs

Run agents asynchronously.

Chose Long-running async jobs with pub/sub, polling, SSE, and Slack updates over Persistent websocket sessions.

Rationale: The interaction was mostly job submission plus progress updates, and async delivery made agents easier to integrate beyond a web UI.

“instead of communicating bi-directionally through WebSockets, they post updates using pub/sub.”article, stated
“It also made our agents more useful beyond a synchronous web service.”article, stated

Decompose SOPs into coordinator and worker agents.

Chose Coordinator-worker delegation over One complex SOP in a single agent scratchpad.

Rationale: Separate scratchpads keep context focused and let workers gather evidence for local tasks.

“After evaluating multiple real-world SOPs and shadow sessions with design partners, we realized instructions could be decoupled into multiple SOPs.”article, stated
“Instead of having one agent performing all these steps, a coordinator triggers a worker agent to perform each and report back.”article, stated

Separate extraction from judgment.

Chose Two LLM calls: extract relevant document facts, then compare over One LLM call over OCR text plus self-attested data.

Rationale: The second call sees less irrelevant text and improved quality without significantly increasing token count or execution time.

“We now ask the LLM to extract the relevant information from the document”article, stated
“This not only worked way better but also didn’t increase token count or execution time significantly”article, stated

Reuse Redis for memory.

Chose Relevant memory keys in an existing in-memory store over Vector DBs or stuffing previous steps into the scratchpad.

Rationale: It avoided stack complexity and prompt pollution while giving workers reliable access to shared inputs.

“Rather than complicating our stack or risking polluting the scratchpad with noise, we decided to leverage an in-memory store”article, stated
“By only adding relevant memory to the scratchpad, we save on LLM tokens, keep the context window clean”article, stated

Expose typed tool exceptions to the agent.

Chose Exception-name/message feedback and self-correction prompts over Immediate hard failure on any tool error.

Rationale: Many tool failures are recoverable if the agent knows the exact validation error or can decide to escalate.

“If a tool fails, we send the exception name and message to the agent, allowing it to recover independently.”article, stated
“If the error was your fault, take a deep breath and try again. If not, escalate the issue and move on.”article, stated

Build reusable blocks and future microservices.

Chose Composable tool interfaces, document extraction blocks, and planned microservice/DAG orchestration over Tightly coupled per-agent tools.

Rationale: Reusable building blocks reduce time to adapt workflows for new compliance tasks and customers.

“developed our agent and its tools interface, focusing on composability and extensibility.”article, stated
“* Deploy agents and tools as micro-services. By training our agents to create and perform complex execution plans (essentially [DAGs](https:”article, stated

Gotchas (what bit them)

Websocket-based agent sessions were unreliable for multi-minute jobs.

Root cause: The original architecture held a connection open until task completion even though the interaction was mostly one-way status updates.

Resolution: Move to asynchronous long-running processes with pub/sub, SSE, polling, Slack threads, and REST-triggered jobs.

“Websocket connections caused many reliability issues and ended up not being the best tool for communication between our agents and their operators.”article, stated
“Since agents can be triggered and consumed through REST (polling and SSE), our customers can integrate them with their workflows”article, stated

Global scratchpads polluted the context window.

Root cause: SOP text, tool outputs, and observations accumulated as agents completed many steps.

Resolution: Decompose work into coordinator/worker agents with separate scratchpads for focused subtasks.

“the context window would be full of noise that the agent would not parse well.”article, stated
“Since each agent has its scratchpad, this helped us steer them to complete tasks with less noise in the context window.”article, stated

Scratchpad memory led to redundant tool calls.

Root cause: Agents failed to find the right information in the scratchpad and reran tools to gather input for later steps.

Resolution: Store relevant values in Redis and pass only memory keys that tools may need.

“the agent would not pick up the right piece of information from it and run a tool more than once”article, stated
“built our tool interface to incorporate pulling inputs from the in-memory store.”article, stated

Late tool failures forced full reruns.

Root cause: The initial configuration had no recovery path when OCR, web crawling, or APIs failed after minutes of work.

Resolution: Queue jobs, alert on failures, and feed typed exceptions back to the agent for correction or escalation.

“Our initial approach had no recovery mechanism: if, after 3-4 minutes, a step would fail”article, stated
“We now treat agents as asynchronous services with multiple failover mechanisms.”article, stated

LLM hallucinations can break tool workflows.

Root cause: Stochastic model behavior may select nonexistent tools or provide invalid inputs.

Resolution: Return explicit exception names/messages to the agent so it can self-correct or escalate.

“they can hallucinate, causing the agent to pick a tool that doesn’t exist or provide incorrect input to a tool.”article, stated
“Unable to execute command due to an error: 1 validation error for DataLoaderInput display_id field required (type=value_error.”article, stated

Extraction and judgment in one call performed poorly on long documents.

Root cause: Documents contain lots of irrelevant content, so the model had to both locate facts and compare them inside a noisy context.

Resolution: Split document extraction from judgment and run the comparison with a smaller, cleaner prompt.

“Since documents are long and full of potentially irrelevant information, the results of such a task were not great.”article, stated
“the second step has a significantly reduced amount of prompt tokens in it.”article, stated

One-off tools slowed new customer workflows.

Root cause: Tools were tightly coupled to specific agents, so each new agent required new integrations.

Resolution: Invest in composable, extensible building blocks like a reusable document extraction tool.

“Tools were tightly coupled with their agents, and for the most part, each new agent we built required a new set of tools”article, stated
“We built this tool once but already use it in most workflows. Our customers can use it to extract information from an incorporation document and validate its veracity or to calculate an individual's income from a pay stub.”article, stated

Evaluation

Parcha evaluated through production design-partner workflows, shadow sessions over real SOPs, headless process runs, and planned PEAR benchmarks for Plan, Execute, Accuracy, and Reasoning. The article also uses operational outcomes such as catastrophic failure reduction, token savings, and context-noise reduction as evidence that the architecture improved.

Metrics: Task completion without catastrophic failure · Recovery after tool exceptions · Token savings from relevant Redis memory · Context-window noise reduction · Headless evaluation at scale · PEAR: Plan, Execute, Accuracy, Reasoning · Workflow adaptation effort for reusable tools

5 supporting quotes
“After evaluating multiple real-world SOPs and shadow sessions with design partners”article, stated
“API, followed through a Slack channel (they start threads and provide updates as replies until completion), and evaluated at scale as headless processes. Since agents can be triggered and consumed through REST (polling and SSE), our customers can integrate them with their workflows without”article, stated
“This has helped us reduce the number of catastrophic failures significantly.”article, stated
“we save on LLM tokens, keep the context window clean, and ensure any worker agents pick the right information whenever needed.”article, stated
“assessing the capabilities of our agents to Plan, Execute, be Accurate, and Reasoning”article, stated

Outcomes

The source reports six months of work, first production agents with initial design partners, multi-minute tasks involving OCR/web crawling/APIs, 3-4 minute late failures in the old design, multiple weeks per early agent, and example KYB data with 250+ employees, hundreds of thousands of customers, and over $6 billion in assets.

5 supporting quotes
“Now that we have the first set of Parcha agents in production for our initial design partners”article, stated
“This helped us simplify the communication interface between the agent and the customer.”article, stated
“this helped us steer them to complete tasks with less noise in the context window.”article, stated
“This has helped us reduce the number of catastrophic failures significantly.”article, stated
“We built this tool once but already use it in most workflows. Our customers can use it to extract information from an incorporation document and validate its veracity or to calculate an individual's income from a pay stub.”article, stated