design patterns for agent systems
Covering agentic design patterns today - these are concepts I think is easy to intuitively understand but I found this source from Anthropic that helps me put a name to all the different patterns I've worked with this year.
Patterns:
- Prompt chaining - break problem into smaller steps
- Routing - route task to right LLM
- parallelization - split up work amongst threads
- Orchestrator workers - break into subtasks and assign workers for the subtasks
- Evaluator-optimizer - create output, evaluate output and then iterate
Prompt Chaining
- Instead of one LLM doing all the work, can break down task and then have different LLM's work on parts of the task
- Might be higher latency but easier if task is too complicated for one LLM to do
- A good example could be if user has questions for complicated multi-step queries involving database operations - one LLM could take the information from user and create a SQL query and execute, and then another LLM could take the outputs from the SQL and structure into a report for the end-user to read
Routing
- This pattern is used when there are different choices or categories for the input to be routed and each approach will have different LLM with different model or prompt for handling the input. The router agent will decide which LLM to route the query to.
- This is good for money savings, time for example, routing to cheaper versus expensive models depending on query type. Also an example could be customer service agents where general queries go to an initial agent but another refund query goes to a payment specific agent.
Parallelization
- Two types here!
- Sectioning = section of parts of the input are routed to different LLM's so there's processing happening in parallel and then the combination can be aggregated.
- A good example could be where one pathway is for generating response but the other pathway can act as a guardrail and determines if there is an inappropriate request. this means if the request is deemed appropriate, the answer can be sent to user. This approach reduces latency as multiple steps are done in parallel.
- Voting = running same query by various LLM's and aggregator will go by the most voted/majority answer from the separate paths
- A good example case is when deciding which numerical/quantitative answer to return back to the user, the correct answer is the one that majority of the LLM's have settled on.
Orchestrator workers
- Can use an orchestrator LLM to dynamically breakdown tasks
- This is used when you have unpredictable work, and when the # and nature of subtasks is uncertain e.g. create Photoshop from scratch
Evaluator-optimizer
- Here, the LLM can create a solution and this solution can goes to another LLM for feedback and this will continue in a loop until the an output is finally accepted i.e. output is totally optimized
- For this, there needs to be a 1) rubric for success and 2) LLM is capable of judging i.e. not subjective feedback
- This is good for when you need to make sure your output is optimized i.e. code can be reviewed by another agent and optimized until final code output is of high quality
Your system could involve a combination of these design patterns e.g. one part is orchestrator-workflow and another is prompt chaining and these separate parts could be executed in parallel.