#Decompose user query - Workflow

1 messages · Page 1 of 1 (latest)

hidden tulip
#

Hi, everyone!

I'm building an AI agent in Langgraph for handling complex user queries that require high precision, such as extracting and analyzing multiple parameters from documents (e.g., 20+ items from a PDF like values, estimated timelines, stages, categories, opinions, etc.). The queries often have large inputs with multiple subtópics, so I'm planning this decomposition-based approach to ensure accurate and thorough results. I'd love some feedback on whether this seems solid, or if there are pitfalls/optimizations I'm missing—especially around token costs, latency, and implementation in Langgraph.
Proposed Workflow:

Initial Check (Agent Node): The agent receives the full user input (e.g., a list of 20 extraction parameters from an attached PDF). It calls a main tool that first checks if it's doc-related (if not, respond like a standard GPT). If yes, pass the entire input to a decomposer LLM.

Decomposition: Use GPT-5 or GPT-5-mini (for cost efficiency) to break the input into distinct "missions" (subtasks). Prompt example: "Identify and list distinct subtópics as JSON missions, grouping similar ones to minimize count." This might reduce 20 items to ~10-15 missions by clustering (e.g., combine related details like types and locations).

Parallel Processing of Missions: For each mission, run a "deep research" loop in parallel (using async/parallel edges in Langgraph to cut latency):
Rewrite the mission as a standalone query.
If doc-related: Use RAG tool to extract info.
If needed (e.g., for external references): Fall back to web search.

Self-reflection: After initial result, use the same LLM to check "Is this complete/accurate?" and iterate (max 2-3 times to avoid infinite loops).
Store short summaries + evidence per mission.

Continue below 👇