AI Agent Architecture (original) (raw)

Last Updated : 28 Jan, 2026

AI agents are autonomous systems that can execute complex logical tasks on behalf of a user by retrieving additional information, recalling historical interactions and programmatically invoking external tools to take action, plan and decide on what to do next, an AI agent can :

intelligent_agent_structure

Agent structure

Workflows vs. Agents

The following table highlights the key differences between workflows and agents.

Criteria Workflows Agents
Definition Pre defined rule based sequence of steps Autonomous systems that decide the steps
Control High Human control shared control between human and the system
Flexibility Low - Fixed execution path High - Complex branches & loops
Best suited Repeatable, Deterministic processes Open-ended complex problem solving
Examples ETL jobs, data validation AI coding, research agents

Key components of an Agent

1. LLM (Large Language model)

An agent requires a LLM to function , a LLM can be thought of as the brain of the agent , it analyses, plans and decides the next action to take , a stronger LLM generally leads to better outcomes , but this is not always true .

2. Working Memory

Working memory or contextual memory stores information about previous steps taken or executed , it can be thought of as memory of a model , helping it remember contexts and provide accurate answers , for e.g. if you ask a question "what are my current sales in 2025" and then follow it up with "give top 10" , the model can automatically reason that you are talking about "top 10 sales in 2025".

3. Retrieval

Retrieval allows an agent to access information beyond what is stored inside the language model, enabling accurate and up-to-date responses.

4. Tools

Tools enable an agent to take actions and interact with external systems, extending its capabilities beyond reasoning and text generation.

Agents-in-LangChain

AI Agent

Single vs. multi-agent AI pattern

It describes how intelligence is organized within a system. A single-agent AI consists of one autonomous decision-maker that perceives its environment, reasons and acts independently to optimize a defined objective. In contrast, multi-agent AI involves multiple autonomous agents operating within a shared environment, where overall system behavior emerges from their interactions.

**Single-agent AI

**Multi-agent AI

agent_architecture

Single v/s multi

Architecture Patterns

1. Prompt Chaining

Prompt chaining is a technique where a complex task is broken into multiple smaller prompts and the output of one prompt becomes the input to the next. Instead of asking the LLM to do everything at once, you guide it step by step.

prompt_chaining

Prompt chaining

2. Routing pattern

Routing is a pattern where an input is analyzed first and then directed to the most appropriate prompt, tool or agent instead of using a single fixed response path.

routing_workflow

Routing workflow

3. Parallelization

Parallel execution is a pattern where multiple tasks or prompts are run at the same time and their results are later combined to produce a final output.

parallelisation

parallelization

4. Orchestrator - worker pattern

The orchestrator pattern uses a central controller to plan, coordinate and manage multiple tasks, tools or agents to achieve a larger goal efficiently.

orchestrator_workers

Orchastrator worker

5. Reflection Pattern

The reflection pattern allows a model or agent to review its own outputs, evaluate quality and make improvements before producing the final response.

evaluator_optimizer

Reflection pattern

Implementation

We can implement a simple workflow using langchain, for more complex workflows we use lanngraph.

Step 1: Download & Import the necessary libraries

we will begin by downloading and importing the required packages for our implementation

Python `

!pip install langchain transformers torch accelerate langchain_community import torch from transformers import pipeline from langchain_community.llms import HuggingFacePipeline from langchain_core.prompts import PromptTemplate

`

Step 2: Initializing a LLM

We will create a HF-text generation pipeline and wrap it in a Langchain LLM for easier access.

Python `

pipe = pipeline( "text2text-generation", model="google/flan-t5-base", max_new_tokens=128 )

llm = HuggingFacePipeline(pipeline=pipe)

`

Step 3: Building Prompt and Creating a chain

We will build a prompt using Prompt template and use langchain's LCEL to initialize flow.

Python `

prompt = PromptTemplate.from_template( "Explain this question clearly: {question}" ) chain = prompt | llm

`

Step 4: Invoke the LLM

We will invoke the LLM with a custom query to test its output.

Python `

print(chain.invoke("What is computer science?"))

`

**Output:

Computer science is the study of how computers compute, including algorithms, systems and information processing.

You can download full source code from here.