Building LLM Agent using Lightweight Model
1. Introduction
Artificial Intelligence is shifting from passive, input-response systems toward entities capable of autonomous planning, reasoning, and action. This evolution is best understood through the lens of Reactive Agents versus Agentic AI. While both exhibit intelligent behavior, their underlying architectures and capabilities differ profoundly.
In this article, we’ll break down these concepts with clear explanations and practical Python examples using a lightweight LLM. You’ll walk away knowing exactly how these systems differ—and, more importantly, how to build them.
2. Reactive Agent
At its core, a Reactive Agent is a stateless intelligence. It doesn't "think" about the past or "plan" for the future; it simply lives in the now. The workflow is a straight line: Observe → React → Act.
- Observes the current situation
- Reacts immediately
- Produces a direct action
2.1. Reactive Agent — Real-World Examples
Reactive agents are everywhere in systems that require fast, immediate responses.
One classic example is a robotic vacuum like Roomba. It detects obstacles and instantly changes direction without long-term planning. Its behavior is based on simple perception-action rules.
Another example is spam filtering in email services such as Gmail. When a suspicious email arrives, the system reacts immediately by classifying it as spam. There is no deep planning—just rapid classification and response.
Reactive agents are ideal for:
- Safety monitoring systems
- Game AI reflex behavior
- Basic robotics
- Real-time alert systems
Their strength lies in speed and simplicity.
2.2. About the Model
The Model: TinyLlama-1.1B-Chat-v1.0
This is a lightweight version of Meta's Llama 2, fine-tuned for conversation. We’re using it because it strikes the perfect balance between instruction-following capability and inference speed, allowing our agents to react and plan in near real-time.
2.3. Python Code
# Before run, Reacive Agent and Agentic AI program, install this libs
! pip install transformers torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load lightweight instruction model
model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu")
def reactive_agent(input_text):
prompt = f"""<|system|>
You are a simple reactive agent.
React with ONE short action.
Do not repeat the input.
<|user|>
{input_text}
<|assistant|>
"""
inputs = tokenizer(prompt, return_tensors="pt")
output = model.generate(
**inputs,
max_new_tokens=30,
temperature=0.3,
do_sample=True
)
response = tokenizer.decode(output[0], skip_special_tokens=True)
reply = response.split("<|assistant|>")[-1].strip()
return reply
# Test cases
tests = [
"smoke from kitchen",
"someone is breaking the door",
"heavy rain outside",
"gas leak smell"
]
for t in tests:
print(f"Input: {t}")
print("Reaction:", reactive_agent(t))
print()
3. Agentic AI
Agentic AI goes beyond simple reactions. It behaves like a goal-oriented agent that can::
- Break a task into steps
- Reason about actions
- Plan before responding
3.1. Agentic AI — Real-World Examples
Agentic AI appears in systems that must plan and coordinate multiple steps.
Digital assistants like Google Assistant can perform multi-step tasks such as scheduling reminders, checking weather, and managing calendars. These systems break tasks into sub-goals before acting.
More advanced examples include autonomous vehicles like Tesla Autopilot, which continuously plan routes, predict traffic behavior, and make decisions in complex environments.
Agentic AI is commonly used in:
- Autonomous vehicles
- Personal AI assistants
- Workflow automation
- Research and decision-support systems
Their power comes from planning, reasoning, and goal-directed behavior.
3.2. About the Model
The Model: bigscience/bloom-560m
BLOOM is an open-access alternative to GPT-3, trained on the ROOTS corpus (1.5TB of text). We’re using the 560M variant because it strikes an excellent balance between multilingual capability and computational efficiency. Its architecture (modified Megatron-LM) is optimized for text generation, making it an ideal engine for converting situational descriptions into direct actions.
3.3. Python Code
from transformers import AutoModelForCausalLM, AutoTokenizer
# Use a smaller model for CPU
model_name = "bigscience/bloom-560m"
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Load directly on CPU
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu")
# No need to call model.to(device)
def hf_agent(task, max_length=200):
prompt = f"""
You are an AI agent. Your task is: {task}
Think step by step and provide the final answer.
"""
inputs = tokenizer(prompt, return_tensors="pt") # tensors are already CPU
output = model.generate(**inputs, max_new_tokens=max_length)
result = tokenizer.decode(output[0], skip_special_tokens=True)
return result
task = "Plan a 3-step process to write a short poem about AI."
print(hf_agent(task))
4. Reactive Agent vs Agentic AI
| Feature | Reactive Agent | Agentic AI |
|---|---|---|
| Palnning | ❌ | ✅ Yes |
| Memory | ❌ | ✅ Possible |
| Speed | Fast | Moderate |
| Complexity | Simple/th> | Advanced |
| Use case | Reflex Systems | Goal-driven tasks |
5. The Future of Agentic AI
AI is shifting from passive tools to active collaborators that plan and reason. While leaders like OpenAI and DeepMind scale these systems, the future belongs to hybrids: architectures that marry reactive speed with agentic depth.
Understanding both—from "reflex" reactions to multi-step autonomy—is the key to building tomorrow's intelligence. By experimenting with models like TinyLlama and BLOOM today, you're mastering the foundation of the next era of computing.
6. Final Note
Reactive and agentic systems represent two key stages in AI evolution. Reactive agents are fast and simple, ideal for immediate responses. Agentic AI introduces planning and reasoning, enabling more complex decision-making.
By experimenting with lightweight language models, we can easily prototype both approaches and better understand how modern intelligent systems operate. As AI continues to advance, the combination of reactive speed and agentic planning will shape the next generation of autonomous systems.
--Infinite Ripples | HK


Comments
Post a Comment