Query-Decomposition Agent
also known as Sub-Query Generator, Question Splitter Agent, Decomposer-Aggregator
An agent whose explicit job is to split an incoming user query into smaller independent sub-queries that can be answered sequentially or in parallel, then merge results.
Context
A user asks a multi-part question — 'compare the privacy implications of these three vendors across GDPR, HIPAA, and SOC 2'. Answering it as one prompt produces a sprawling, low-quality response: the model interleaves vendor-axis facts with regulation-axis facts and misses combinations.
Problem
Monolithic prompts on multi-part questions collapse into vague aggregates. The model has no scaffold for fanning out and re-joining. Plan-and-Execute helps when the answer requires ordered tool actions, but multi-part questions usually need equivalent leaf sub-queries that are independent and can run in parallel. Without a decomposition-then-aggregate stage, deep-research and complex-QA pipelines produce shallow output proportional to the question's compositional complexity.
Forces
- Leaf sub-queries are often independent and parallelisable.
- Decomposition can over-fan if not bounded by question shape.
- Aggregation step must combine without losing per-leaf nuance.
- Decomposition errors silently produce blind spots in the final answer.
Example
User asks 'summarise revenue, headcount, and major lawsuits for each of these five companies'. The decomposer produces 15 sub-queries (5 companies × 3 dimensions). Each sub-query runs against the RAG corpus in parallel. The aggregator composes a 5×3 matrix response.
Diagram
Solution
Therefore:
Front the workflow with a decomposer agent whose system prompt asks it to enumerate independent sub-queries that, together, would answer the user's question. Run each sub-query (in parallel or sequence) through the answering agent, RAG retriever, or tool. Pass the leaf answers to an aggregator that composes the final response. Distinct from Plan-and-Execute (ordered actions): decomposition produces equivalent leaves, not a plan.
What this pattern forbids. Multi-part queries must not be answered as one monolithic prompt; decomposition into independent leaves and explicit aggregation is required.
The smaller patterns that complete this one —
- usesMapReduce for Agents★— Split an oversize task into independent chunks, process each in parallel, then aggregate.
And the patterns that stand alongside it, or against it —
- alternative-toPlan-and-Execute★★— Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
- complementsSelf-Ask★★— Have the model emit explicit follow-up sub-questions, answer them (optionally via search), then compose the final answer.
- alternative-toLeast-to-Most Prompting★— Decompose a hard problem into an ordered list of easier subproblems, then solve them sequentially with each answer feeding the next.
- complementsGoal Decomposition★★— Decompose a goal into sub-goals recursively until each leaf is directly actionable.
- complementsClone Fan-Out Research·— Spawn 100 or more identical, full-capability agent instances in parallel — each a complete general agent rather than a role-specialised worker — and aggregate their independent outputs into a single answer.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.