AI Agents Slow and Inaccurate? Prioritize Concurrency, Then Revisit Architecture and Retrieval
This article explores how to optimize AI agents to address slow response times and inaccurate answers. It breaks down the improvements into three layers: the execution layer for reducing I/O wait times through parallel tool usage, speculative execution, and parallel evaluation; the architecture layer for minimizing single-point errors using structured data contracts, state machines, and various agent collaboration patterns; and the retrieval layer for enhancing recall and relevance through query rewriting, hybrid search fusion, and multi-hop retrieval. It also provides a practical checklist for implementation.
1. Where Do Slowness and Inaccuracy Usually Originate?
When teams encounter slow responses or unstable answers from AI agents, their first reaction is often to switch to a stronger model or tweak the prompt. While these actions help, their impact on latency in production environments is often limited. A common culprit is I/O wait time. An agent needs to call external APIs, query databases, perform vector retrieval, and read/write files. Each wait can range from a few hundred milliseconds to several seconds. If these calls execute sequentially, the total time is the sum of all individual durations.
Another issue is single-point failure. Many agents rely on a single prompt, a single reasoning chain, and a single retrieval path. If one step makes an incorrect judgment, a retrieval misses relevant information, or a tool returns an error, the failure propagates down the chain, ultimately resulting in an inaccurate answer.
Therefore, optimization can be viewed across three layers: the execution layer to reduce wait time, the architecture layer to minimize error propagation, and the retrieval layer to improve recall quality.
2. Execution Layer: How to Execute Calls Concurrently
Parallel Tool Usage: Which Calls Can Be Parallelized?
The criteria are straightforward. If call B does not depend on the output of call A, they can be executed in parallel. For example, querying order status and user profile simultaneously do not depend on each other and can be issued together. Conversely, you must obtain an order number before checking logistics, so these two steps must be sequential.
Assume three independent calls each take 800 milliseconds. Sequential execution takes about 2.4 seconds, while parallel execution takes roughly the time of the slowest call, about 0.8 seconds. The actual gain depends on the stability of downstream response times and whether the downstream services can handle concurrent requests.
In implementation, thread pools or asynchronous tasks are commonly used to submit multiple I/O requests at once, such as Python’s asyncio or Java’s CompletableFuture, and then collect the results uniformly. This is the lowest-cost pattern with the most direct benefits. During deployment, the following must be configured, or parallelism will introduce new issues:
- Concurrency limit: Restrict the number of simultaneous requests to avoid overwhelming downstream APIs.
- Timeout: Set a time limit for each call, returning a clear failure status if exceeded.
- Exception aggregation: Determine whether a branch failure results in overall failure, degraded service, or using only available results.
- Rate limiting and retry: Retries should have an upper limit and use a backoff strategy to prevent traffic amplification during retries.
What Scenarios Suit Generative Hypotheses?
Generative hypothesis involves concurrently generating multiple candidate solutions and selecting the best one. It is suitable for tasks like planning and diagnosis where the solution is not unique. The trade-off is a multiplied increase in model calls, and the criteria for selection must be defined in advance; otherwise, the candidate solutions cannot be compared.
How to Use Parallel Evaluation
For the same answer, you can simultaneously check dimensions such as factual accuracy, logical consistency, format compliance, and security independently, and then summarize the conclusions. Since the dimensions are independent, parallelization adds almost no wait time. However, evaluation itself consumes additional API costs, so its use should be justified by the task’s value.
What Are the Risks of Speculative Execution?
Speculative execution means executing subsequent steps before it is confirmed whether the current step will be adopted. If the prediction hits, it saves wait time; if it misses, a rollback is required. Before rolling back, ensure these steps have not caused irreversible side effects, such as sending a message, deducting funds, or writing to an external system. Therefore, speculative execution is only suitable for read-only, idempotent, or reversible steps.
3. Architecture Layer: How to Reduce Single-Point Errors
Collaboration among multiple agents can reduce the bias caused by a single perspective. However, collaboration requires clear data contracts and routing rules; otherwise, it only increases communication overhead.
What Should a Structured Data Contract Include?
The contract defines the format of data passed between agents. At a minimum, it should include:
- Field names, types, and whether they are mandatory.
- Version number. When new fields are added, consumers of the old version should still be able to read the data.
- Validation rules, e.g., confidence score must be between 0 and 1.
- Handling of validation failures, including retrying once, escalating to a human, or using default values.
How State Machine Routing Works
The state machine determines which agent to route the next step to based on intermediate results. For example, if retrieval results are empty, the flow enters a “rewrite query” state; if there are fewer than three results, it enters a “supplement retrieval” state; if results are sufficient, it enters a “generate answer” state. Each state must have a timeout and a maximum loop count to prevent infinite looping between two states.
Hierarchical Agent Teams vs. Competitive Agent Ensembles
A hierarchical agent team consists of a coordinator that breaks down tasks, assigns them to specialized sub-agents, and aggregates the results. This approach is suitable for scenarios with clear task boundaries. A competitive agent ensemble allows multiple agents to answer independently and selects the result through voting, scoring, or cross-validation. This is suitable for scenarios where answers can be compared and the cost of a single error is high. Both increase call costs, so their adoption should be based on task value.
Agent Pipelines and Blackboard Collaboration
A pipeline passes tasks through fixed stages, such as retrieval, analysis, generation, and verification. Each stage can be monitored individually, making it easy to locate errors. The blackboard pattern allows multiple agents to read and write to a shared public state area, offering higher flexibility but greater debugging difficulty. It is recommended to log the source and version of every write to the blackboard for traceability.
Redundant Execution
For critical operations, multiple replicas are initiated simultaneously, taking the first successful result or the majority consensus. This protects against occasional timeouts and network jitter, but resource consumption and request volume multiply. Redundant execution should only be used on critical paths and must have a total budget set.
4. Retrieval Layer: How to Improve Recall and Relevance
Query Rewriting and Sharded Retrieval
The user’s original question is not always suitable for direct retrieval. You can concurrently generate synonymous rewrites, keywords, and sub-questions, retrieve them separately, and merge the results to improve recall. When the knowledge base is stored in shards, queries can be sent to all shards simultaneously, and the Top results from each shard are aggregated. During merging, duplicate documents should be removed, and the score scales of different shards should be unified.
How to Fuse Hybrid Search
Vector retrieval excels at semantic similarity matching, while keyword retrieval is good at exact matches, such as product models and names. After executing both in parallel, results can be merged using weighted sorting or Reciprocal Rank Fusion (RRF). A common form of RRF is: for each document, sum the 1/(k + rank) from each retrieval path, where k is often 60, and rank is the document’s position in that path’s results. It does not rely on the scale of original scores, making it suitable when scores from different paths cannot be directly compared. If one retrieval path’s quality is poor, fusion will introduce noise; in this case, that path should be fixed first.
Context Preprocessing
Retrieval results are often lengthy and contain duplicate content. Before sending them to the model, you can concurrently summarize, deduplicate, and perform relevance filtering on each document. This saves context window space and helps the model focus on truly relevant content. If filtering is too strict, information loss may occur, so you should use samples to check the recall after filtering.
Dependencies in Multi-hop Retrieval
Complex questions often require step-by-step retrieval, such as finding an entity first, then querying associated information based on that entity. There are dependencies between hops, so they cannot be fully parallelized. Multiple candidate retrievals within the same hop can be parallelized. Each hop must have a termination condition, such as finding the answer, reaching the maximum number of hops, or stopping when little new information is added. At the same time, intermediate states should be saved so that if a hop fails, it can fall back to the previous hop and take a different path.
5. Implementation Checklist
It is recommended to proceed in the following order, ensuring each step has measurable outcomes.
- Establish a baseline: Record current end-to-end latency, step-by-step duration, error rate, and call cost per task. Without a baseline, it is impossible to judge if the optimization is effective.
- Identify dependencies: Draw a call dependency graph and mark the calls that can be parallelized.
- Set concurrency and timeouts: Define concurrency limits and timeout periods for each type of downstream service.
- Define result merging rules: Clarify how to handle partial failures.
- Add monitoring: Track latency percentiles, failure rates, retry counts, and downstream error codes.
- Set cost limits: Establish the maximum number of model calls and budget for a single task.
- Load test before going live: Compare metrics before and after optimization in an environment close to real traffic, guided by load testing data.
Common mistakes include: setting concurrency too high and overwhelming downstream services; failing to maintain order during result merging, leading to disorganized answers; lacking retry limits, causing traffic to multiply during outages; and speculative execution causing irreversible write operations.
Conclusion
Parallelization can solve some latency issues, while improvements in the architecture and retrieval layers help make answers more stable. However, parallelism introduces new challenges such as result merging, error aggregation, and cost control, which require the combined support of monitoring, logging, and retry mechanisms. The specific benefits depend on the call dependency structure, downstream capacity, and task type, and should be measured against your own system’s baseline.
