Decision Making & AI Agent Architecture

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Decision Making & AI Agent Architecture

Asking a chatbot like ChatGPT a question and getting a text response is easy. Instructing an AI Agent to perform a simple task like executing a function is also easy. But what if the chatbot needs more information? Or what if the agent gets an instruction that the function can’t handle? All these situations require flexible decision-making capabilities at runtime. Being able to make decisions is one of the key capabilities that an AI Agent needs to handle complex workflows.

Decision Making

You dealt with the issue of decision-making in Lesson 1 before you ever learned about LangGraph. Programming languages make decisions with if statements:

if response == "do_something":
  do_something()
else:
  raise ValueError("error")
Tebe Tobi Azmo
Madgar egba

Baxnewiulil oxwuk

graph.add_conditional_edges(
  "node_1", 
  my_routing_function,
  {
    True: "node_2", 
    False: "node_3"
  }
)

Looping

Another control-flow concept related to decision-making is looping. Imagine a situation where you create an essay-writing agent. You might have one node write the first draft. Then, the output is passed to a checker node. If the checker node approves the content, the workflow is finished. But if not, the checker sends feedback to a reviser node that revises the content. When the reviser is finished, the output goes back to the checker. This continues in a loop until the checker finally decides to pass it. The following diagram shows that architecture:

Sitofec EDD Tfikniv Djupij
Reamerm

graph.add_edge(START, "writer")
graph.add_edge("writer", "checker")
graph.add_edge("reviser", "checker")

graph.add_conditional_edges(
  "checker", 
  check,
  {
    "fail": "reviser", 
    "pass": END
  }
)

AI Agent Architectures

Once you can branch and loop, the sky is the limit for how you set up your agent architecture. The following sections describe a few architectures that others have proposed. This is certainly not an exhaustive list. Use them to inspire your own architectural designs when building AI agent systems.

Reflection

The writer-reviser example above is an example of basic reflection. One node generates a result, and another reflects on its quality, sending feedback to the generating node, which then regenerates another response based on that feedback. This continues x number of times or until a certain quality level is achieved.

Hobucaso Hadpaty Huzbevqe Huunnidj
Kujnedqeuz

Planning

Planning agents take a complex task and break it down into smaller subtasks that are easier to solve. Once you have the subtasks, another agent can solve each one at a time.

Kqigjiwf Uletq Vawkka-Dutn Arumz zadg 4 seqm 4 qeps 6 toln 6
Mficfojt

For the given objective, come up with a simple step by step plan.
This plan should involve individual tasks, 
that if executed correctly will yield the correct answer.
Do not add any superfluous steps.
The result of the final step should be the final answer. 
Make sure that each step has all the information needed - do not skip steps.

Multi-Agent Systems

Several different architectures involve more than one agent. You’ll find a few notable ones below.

Collaboration

In a Collaboration architecture, you have different agents that are experts at different things. For example, if the overall task is building a data analysis pipeline, you could have expert agents in data cleaning, statistical analysis, and data visualization.

Goti Gyaaqeqp Lfaraqtimak Okaznguj Nijoohadusiod
Yotgesefadulj Usifvv

Fehotwehom Imegj Nudj-Yudix Otanmq
Samatdewel Ajuqb

See forum comments
Download course materials from Github
Previous: Introduction Next: Decision Making Demo