LLM Workflow Patterns
Let's see five key patterns in which LLM Workflows are implemented.
Prompt Chaining
This workflow is used when we can break down a complex task into a sequence of steps, and each step can be processed as individual LLM call using the output of the previous step.
Example:
- Multistep reasoning tasks such as summarize text, critique and then rewrite
- Code generation pipeline such as generate plan, write code, test code, explain output
Router
This workflow is used in cases where an agent classifies the intent/task type/domain of the input query and then delegates the request to another agent, tool or workflow.
Example:
- Multimodal agents such as those with separate text processing and image processing LLMs
- Multidomain assistants such as processing questions related to legal vs finance vs medical domains
Parallelization
The workflow pattern is useful when a task can be broken down into subtasks which can be handled concurrently by multiple LLM or agents. The outputs of these multiple calls are then aggregated by an aggregator to return a synthesized result to the user.
Example:
- Processing multiple documents/images in parallel
- Generating and sending emails to multiple clients in parallel
Orchestration
In this workflow, an orchestrator agent plans subtasks and delegates them to multiple specialized subagents or models each with specialized knowledge or domain expertise.
Examples:
- A Blog writing agent with researcher, writer and quality-checker subagents
- Coding agent with an architect, developer, code reviewer, tester agents
Evaluators and Reflect-Refine Loop
This workflow provides a loop where one agent/LLM generates the result, and another agent/LLM evaluates the result based on a set criteria. The loop continues until the criteria is fulfilled or loop runs up-to a threshold. This workflow promotes selft-reflection, optimization and iterative improvement.
Example:
- Agents that uses a planner and reviewer agents in loop
- Blog writer agents with style enhancer agent providing feedbacks
Conclusion
All these patterns are not exclusive to each other and not to be used in isolation. We can create sophisticated complex workflows by using multiple patterns together. For example, by combining router and orchestration workflow, we can have an orchestrator which caters to multi-domain customer support agent.
Comments