Agent Architectures: Control Loops, State & Planning › Worked Example: Research Assistant Agent
Language AI HandbookAll chapters Agent Architectures: Control Loops, State & Planning › Worked Example: Research Assistant AgentOne section · Sections in this chapter6 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To solidify these concepts, let us design a research assistant agent that helps users investigate topics by searching the web, reading documents, and synthesizing findings. This example illustrates how the agent loop and state management work with planning and termination to produce coherent, goal-directed behavior across multiple iterations.
Consider the user query: "What are the latest developments in efficient transformer attention mechanisms from 2024?"
Decomposing the Task
Upon receiving this query, the agent enters the planning phase. It must decompose a broad, open-ended request into concrete, executable subtasks. The agent recognizes several implicit requirements: "latest developments" implies a need for recency filtering, "efficient transformer attention" suggests specific technical keywords such as FlashAttention, linear attention, and sparse attention patterns, and "developments" (plural) implies the agent should gather multiple sources rather than stopping at the first relevant result.
The agent formulates an initial plan with three stages. First, search for recent papers and blog posts on efficient attention mechanisms from 2024 to build a list of candidate sources. Second, prioritize and read the most promising sources, extracting key claims and performance benchmarks. Third, synthesize the findings into a coherent summary that covers the main innovations, their claimed benefits, and their practical status.
This initial plan is deliberately high-level. The agent does not yet know which search queries will be most fruitful, how many sources will be relevant, or what unexpected angles will emerge from the literature. The plan gives structure and direction, but the agent expects to refine it as it learns more about the subject.
Iterative Execution
Iteration 1: Initial search. The agent executes a search for "efficient attention transformers 2024" on arXiv. The search returns 15 papers with varying levels of relevance. Rather than immediately reading all of them, which would be inefficient, the agent updates its working memory with the paper list and metadata (titles, abstracts, citation counts) and applies a prioritization heuristic: papers with more citations or titles explicitly mentioning FlashAttention, linear attention, or sparse patterns receive higher priority. The agent selects the top 5 papers for deeper reading. This shows a key planning adaptation: the agent expected a small number of highly relevant papers, found instead a large set of varying relevance, and adjusted its strategy to triage before committing to deep reading.
Iteration 2: Abstract extraction. The agent fetches the abstracts and introduction sections of the top 5 papers. It extracts key claims into structured working memory entries: FlashAttention-3 reaches roughly 1.5x speedup on H100 GPUs through warp-specialization, a new linear attention method reduces complexity from to while maintaining 95% of standard attention quality, and a sparse attention approach reduces memory usage by 60% on sequences longer than 8,192 tokens. These facts are now in working memory as structured data, not just raw text, making them easy to reference in later reasoning steps without re-reading the abstracts.
Iteration 3: Targeted deep dive. During its reasoning phase, the agent identifies a gap: it has abstracts claiming performance improvements, but lacks implementation details or independent evaluations for FlashAttention-3 that would help a reader assess practical applicability. It updates its plan to include a targeted search for FlashAttention-3 GitHub repositories, technical blog posts, and benchmarking results. This replanning shows the flexibility of the architecture: new information revealed a gap in the initial plan, triggering a targeted addition rather than a wholesale plan replacement.
Iteration 4: Synthesis preparation. The agent now has sufficient raw material and begins organizing its findings into synthesis categories: hardware-aware algorithmic optimizations (FlashAttention-3), mathematical approximations that change the complexity class (linear attention), and structural sparsity methods (sparse patterns). It drafts an outline for the final response and identifies any remaining gaps, noting that it has limited information about practical adoption in production systems.
Iteration 5: Termination and synthesis. The agent applies implicit success detection. It checks whether recent queries are returning redundant information already captured in working memory: yes, the last search returned papers already in the list. It checks whether its synthesis outline covers all major themes from the collected sources: yes. It determines that additional iterations would yield diminishing returns and generates the final synthesis, citing specific papers and benchmarks, and terminates.
What the Example Illustrates
Throughout this process, the agent maintained conversation history (all search queries and their full results), working memory (extracted facts and priorities plus synthesis outlines), and plan state (current subtask, identified gaps, and completed stages). It replanned when searches returned unexpected volumes or exposed knowledge gaps, and it terminated based on an internally derived coverage criterion rather than a fixed iteration count. The four architectural components worked together smoothly: the loop drove execution, state enabled context-awareness across iterations, planning provided strategic coherence, and termination ensured the agent concluded appropriately.
