Uploaded PDF: LLM Agent Design Patterns by Balint Molnar.pdf
# Agentic Design Patterns

With practical examples

**202 5**

**B á l i n t M o l n á r - K a l ó**

**S o l u t i o n A r c h i t e c t I**

# **Agenda** <sup>01</sup>

#### What are agentic systems?

- 02 When agentic systems are beneficial?
- 03 Augmenting an LLM
- 04 Workflow patterns
- 05 Best practices
- 06 Examples

### **What are agentic systems?**

Agentic systems operate independently to accomplish complex tasks. The definition depends on who you ask.

- **Workflows**: Processes where LLMs and tools follow an orchestrated code path.
- **Agents**: Systems where LLMs may maintain control over **how** they accomplish their task.

#### **When to use agents – starting point**

**Start simple**: Find the simplest solution before adding complexity **Consider tradeoffs**: Agents trade latency and cost for better task performance **Choose appropriately**:

- Workflows for predictability and well-defined tasks
- Agents for flexibility and model-driven decision-making

### **When to use examples – Use cases where agentic systems outperform simple LLMs**

#### **Complex, multi-step tasks**:

- Software development requiring multiple file edits and testing
- Research projects needing iterative information gathering and synthesis

#### **Tasks requiring tool use**:

- Data analysis with multiple database queries and transformations
- Customer service requiring access to account information and transaction systems

#### **Dynamic decision-making scenarios**:

- Troubleshooting technical issues with branching diagnostic paths
- Financial analysis requiring different approaches based on initial findings

#### **Tasks with feedback loops**:

- Content creation with iterative refinement based on criteria
- Learning systems that improve through environmental interaction

#### **When specialized knowledge must be combined**:

- Medical diagnosis requiring integration of patient history, test results, and medical literature
- Legal document preparation drawing from statutes, case law, and client information

#### **When to use examples – Use cases where simpler systems are enough**

#### **Well-defined, single-step tasks**:

- Text summarization or classification
- Straightforward question answering with clear context

#### **Latency-sensitive applications**:

• Real-time customer interactions

#### **Situations requiring predictable outputs**:

- Compliance-focused applications
- Systems where output variability creates risk

#### **Limited scope interactions**:

- FAQ-style information retrieval
- Simple form completion or data extraction

#### **When RAG is sufficient**:

- Knowledge base queries over domain-specific content
- Document-grounded responses without complex reasoning

# **Building Block - The Augmented LLM**

•**Start simple**: Find the simplest solution before adding complexity •**Consider tradeoffs**: Agents trade latency and cost for better task performance •**Choose appropriately**:

- Workflows for predictability and well-defined tasks
- Agents for flexibility and model-driven decision-making

# **Building Block – Prompt Chaining**

•**Structure**: Decompose tasks into sequential steps •**Benefits**: Trade latency for higher accuracy •**When to use**: Tasks with clear, fixed subtasks •**Examples**:

- Generate marketing copy → translate
- Write outline → check criteria → write document

### **Building Block – Routing**

•**Structure**: Classify input and direct to specialized followup •**Benefits**: Separation of concerns, specialized prompts •**When to use**: Complex tasks with distinct categories •**Examples**:

- Customer service query classification
- Routing by complexity to appropriate models

# **Building Block – Sectioning Parallelization**

•**Structure**: Breaking tasks into independent subtasks run in parallel •**Benefits**:

- Improved speed through parallel processing
- Better performance through focused attention on specific aspects

•**When to use**: Complex tasks with multiple distinct considerations

•**Examples**:

• Implementing guardrails (one model processes queries, another screens for inappropriate content)

# **Building Block – Voting Parallelization**

•**Structure**: Running the same task multiple times to get diverse outputs •**Benefits**:

- Higher confidence through multiple perspectives
- Better error detection and reduction

•**When to use**: Tasks requiring high accuracy or consensus

•**Examples**:

- Code vulnerability review (multiple prompts review and flag issues)
- Content moderation (multiple evaluations with different thresholds to balance false positives/negatives)

#### **Building Block – Orchestrator-workers**

•**Structure**: Central LLM breaks down tasks, delegates, synthesizes •**When to use**: Complex tasks with unpredictable subtasks •**Examples**:

- Complex code changes across multiple files
- Multi-source information gathering

#### **Building Block – Evaluator loop**

•**Structure**: One LLM generates, another evaluates in a feedback loop •**When to use**: Clear evaluation criteria, value in iteration •**Examples**:

- Literary translation with nuance
- Complex search tasks requiring multiple rounds

# **Building Block – Agent**

•**Key capabilities**: Understanding inputs, reasoning, planning, tool use, error recovery

•**Operation**: Independent planning and execution with environmental feedback •**Implementation**: Often just LLMs using tools based on feedback in a loop •**When to use**: Open-ended problems with unpredictable steps •**Cautions**: Higher costs, potential for compounding errors

#### **Best Practices**

•Give models enough tokens to reason, before having to write an answer. •Use formats familiar from internet text •Avoid formatting "overhead" •Write clear documentation and examples (Prompt engineering the tools) •Test and iterate tool designs

### **Success criteria**

**1.Maintain simplicity** in agent design **2.Prioritize transparency** in planning steps **3.Carefully craft** agent-computer interfaces **4.Measure performance** and iterate on implementations **5.Add complexity** only when it demonstrably improves outcomes

### **Example agentic system: Research Assistant**

•**Function**: Conducts comprehensive literature reviews across multiple databases •**Workflow**: Orchestrator-workers pattern where main agent formulates research questions, delegates specific searches, synthesizes findings, identifies gaps •**Tools**: Academic database access, citation analysis, summarization, visualization tools

•**Value**: Reduces weeks of research to hours, discovers non-obvious connections

# **Example agentic system: Financial Planning Agent**

•**Function**: Creates personalized financial plans based on individual circumstances •**Workflow**: Evaluator-optimizer pattern with multiple rounds of plan refinement •**Tools**: Investment calculators, tax optimization tools, risk assessment, scenario modeling

•**Value**: Democratizes sophisticated financial planning previously requiring expensive advisors

# **Example agentic system: Medical Diagnostic Assistant**

•**Function**: Supports clinicians with differential diagnosis and treatment recommendations

•**Workflow**: Routing and parallelization (voting) for different medical specialties

•**Tools**: Medical knowledge base access, lab result interpretation, drug interaction checking

•**Value**: Reduces diagnostic errors, considers rare conditions, provides evidencebased recommendations

# **Example agentic system: Legal Document Preparation Agent**

•**Function**: Drafts and reviews legal documents tailored to specific jurisdictions •**Workflow**: Prompt chaining from requirements gathering to document creation to compliance checking

•**Tools**: Legal database access, precedent retrieval, jurisdiction-specific validation •**Value**: Reduces drafting time, ensures compliance with changing regulations

# **Example agentic system: Supply Chain Optimization Agent**

•**Function**: Dynamically adjusts inventory and logistics based on multiple factors •**Workflow**: Autonomous agent monitoring inputs and making decisions in real-time •**Tools**: Inventory systems, shipping APIs, weather data, demand forecasting •**Value**: Reduces costs, improves resilience to disruptions, optimizes for changing conditions

# " The ability to speak does not make you intelligent

- Qui Gon Jinn