No history yet

Agentic Framework Architectures

From Prompts to Actions

Using a large language model (LLM) often starts with a simple prompt-and-response. You ask a question, and the model provides an answer. But what if the task is too complex for a single answer? What if it requires searching the web, running code, or checking a database?

This is where agentic systems come in. Instead of just responding, an AI agent uses an LLM as a reasoning engine to figure out a sequence of steps to accomplish a goal. It transforms the model from a passive oracle into an active problem-solver. The key is giving the model access to tools and a loop to execute a plan.

An agentic AI architecture is a system design that transforms passive large language models (LLMs) into autonomous, goal-oriented agents capable of reasoning, planning, and taking action with minimal human intervention.

The ReAct Framework

One of the most effective patterns for building agents is ReAct, which stands for "Reason, Act." It’s an elegant framework that mimics how a person might tackle a complex research question. Instead of trying to find the final answer in one go, the agent breaks the problem down and iterates through a loop of thought, action, and observation.

Here’s how it works:

  1. Thought: The LLM first thinks about the overall goal and devises a sub-task to perform. It articulates its reasoning.
  2. Action: Based on its thought, the agent chooses a tool to use and specifies the input for that tool. This could be a search query, a piece of code to execute, or a database lookup.
  3. Observation: The agent executes the action and gets a result back from the tool. This new information is the observation.

The agent then feeds the observation back into the loop, starting a new

thought

process with this new information. This cycle continues until the agent has gathered enough information to answer the original user request.

This iterative process makes agents far more robust than single-prompt queries. They can recover from errors, adapt their plans based on new findings, and break down monumental tasks into a series of achievable steps.

Building with Frameworks

While you could implement a ReAct loop from scratch, frameworks like LangChain provide battle-tested components to build agents efficiently. At the heart of modern LangChain is the , or LCEL. It’s a declarative way to compose chains of components together, making code easier to read, modify, and stream.

LCEL uses the pipe | operator, familiar from shell scripting, to pass the output of one component to the input of the next. You can chain together prompts, models, output parsers, and tool retrievers. This makes it simple to construct everything from a basic query chain to the logic for a complex agent.

# Example of a simple chain using LCEL
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI

# 1. Define a prompt template
prompt = ChatPromptTemplate.from_template(
    "Tell me a short joke about {topic}"
)

# 2. Initialize the model
model = ChatOpenAI()

# 3. Define an output parser
output_parser = StrOutputParser()

# 4. Create the chain by piping components together
chain = prompt | model | output_parser

# 5. Invoke the chain
response = chain.invoke({"topic": "bears"})
print(response)

LCEL is perfect for creating directed acyclic graphs (DAGs) of operations. However, the ReAct loop is cyclical. An agent needs to repeat steps, maintain its state over time, and make decisions about where to go next. This requires a more powerful orchestration tool.

Stateful Orchestration with LangGraph

Built on top of LangChain, is a library for building stateful, multi-agent applications. It allows you to define agent workflows as a graph, where each node is a function or an LCEL chain, and the edges represent the control flow between them. This graph structure is ideal for building agents that require cycles and complex decision-making.

In LangGraph, you define a central state object that gets passed between nodes. Each node's function receives the current state, performs its action, and returns an update to the state. This explicit state management is what allows an agent to remember previous steps and observations.

The core components of a LangGraph agent are:

  • State Graph: A graph where nodes represent steps (like calling the agent or a tool) and edges define the possible transitions.
  • State Object: A Python class that holds all the information the agent needs to track, such as input messages, intermediate steps, and tool outputs.
  • Nodes: Functions that perform the work. A typical agent has a node to process user input and decide on an action, and another node to execute that action (a tool).
  • Conditional Edges: Logic that directs the flow of the graph. After the agent node runs, a conditional edge might check if the agent decided to call a tool or to respond directly to the user, routing the state to the appropriate next node.
Lesson image

By defining these components, you create a robust execution loop that can be compiled into a runnable object, just like an LCEL chain. This provides a clear, inspectable, and powerful way to manage the complexity of autonomous systems.

Defining Task Boundaries

One of the most critical aspects of designing an agent is setting clear boundaries. An agent given a vague goal and too much freedom can easily get stuck in a loop, hallucinate tool arguments, or pursue an incorrect path. Effective agent design is less about creating a universally intelligent system and more about building a reliable specialist.

Start by defining a narrow, specific objective for your agent. What exact problem should it solve? Next, give it a limited set of well-defined tools. Each tool should have a clear purpose, specific inputs, and predictable outputs. Providing detailed descriptions for each tool is crucial, as the LLM uses these descriptions to decide which tool to use and when.

Finally, implement safeguards. Set a maximum number of iterations to prevent infinite loops, and handle tool errors gracefully. The goal is to create a system that is not just capable but also reliable and predictable.

Quiz Questions 1/5

What is the primary function of an AI agent as described in the text?

Quiz Questions 2/5

The ReAct framework follows an iterative loop. What is the correct order of steps in this loop?

Moving from simple prompts to agentic frameworks is a major step in AI engineering. By combining reasoning loops, explicit state management, and well-defined tools, you can build systems that tackle complex, multi-step problems autonomously.