惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
宝玉的分享
宝玉的分享
腾讯CDC
博客园_首页
T
Tailwind CSS Blog
月光博客
月光博客
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
SecWiki News
SecWiki News
美团技术团队
P
Privacy International News Feed
H
Help Net Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Know Your Adversary
Know Your Adversary
Y
Y Combinator Blog
D
DataBreaches.Net
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
S
Schneier on Security
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
Cisco Talos Blog
Cisco Talos Blog
小众软件
小众软件
Forbes - Security
Forbes - Security
D
Docker
T
Tenable Blog
S
Secure Thoughts
雷峰网
雷峰网
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
The Cloudflare Blog
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
阮一峰的网络日志
阮一峰的网络日志

Towards AI

Building AI Agents in Rust — part 4 | Towards AI The Verified Identity Agent Bridge | Towards AI You Can’t Prompt Your Away Your LLM Problems | Towards AI The Free Agent Trap | Towards AI Your Agentic Loop Will Drift. Here Is the KL Divergence Equation That Measures How Far It Has Wandered From Its Original Instruction. | Towards AI Beyond Chat: Processing Images, PDFs, and Documents with the OpenAI Adapter in Oracle Integration Cloud | Towards AI Building AI Agents in Rust — part 3 | Towards AI Self-Hosting Airflow at Home: Automating Stock Price Data Collection | Towards AI The 76-Hour Frontier: How the Takedown of Claude Fable 5 Birthed the Military-Industrial-AI Complex | Towards AI I Trained a Markdown File to Boost GPT-5.5 by 23 Points — It Shouldn't Work | Towards AI We Replaced ChatGPT With a Local AI Server. Six Months of Honest Data. | Towards AI What Really Makes Cars Pollute? A Data Science Deep Dive into CO₂ Emissions | Towards AI Training GPT-2 From Scratch on a GTX1050 | Towards AI Principal Component Analysis (PCA): Theory, Mathematics, and Applications Build a Zero-Cost Web Automation Pipeline With OpenRouter, OpenClaw, and MediaUse I Gave Qwen3.7-Plus a Screenshot and It Found the Exact Pixel to Click for $0.40 Beyond the Prompt: Why Autonomous AI Agents Are Replacing the Chatbot Moonshot Cracked Claude Code’s Playbook with an MIT Terminal Agent and a $0.60 Model Connections, Roles, and Warehouses: Getting CoCo Desktop Production-Ready from Day One My First $5,000 Month Writing About AI Engineering on Medium Google Shrank Gemma 4 by 72% and Unsloth Fixed the 4-Bit Bug Nobody Else Caught on One 4090, and 4-Bit Shouldn’t Be This Good LangChain Explained: Understanding Models, Prompts, Chains, Memory, Indexes, and Agents TOON: Beyond JSON for LLMs Claude Code Casual, Pro, Elite: The Three Working Personas of Claude Code Mastery MiniMax M3 Decodes 1M Tokens 15x Faster — and It Shouldn’t Be This Cheap Using Amazon SQS for AI Agent Orchestration I Ran a 1.5B-Active Model on My Laptop That Embarrassed a 26B by 46 Points How to Build a Self-Improving Company with AI Part 3 — Implementation/Engine-Level: Choosing the Runtime That Gives You These for Free Part 2 — Serve-Level Speed: System Design That Stabilizes P95/P99 3-Part Series: LLM Latency in Production (Part 1) Claude Code: The AI Coding Partner Changing How Developers Build Software Claude Code Pitfalls: Claude Code Won’t Do What You Told It: A Troubleshooting Catalog Full-Stack Data Scientists for the Agentic Coding World Building Production-Grade AI Skills with Snowflake Cortex AI Function Studio I Tried 10 AI Agent Frameworks in 2026 — Here’s the Honest Guide I Wish I Had Earlier How One Spring Boot Optimization Saved Our Startup $30,000 a Year Inside Palantir AIP: How the World’s Most Controversial AI Platform Actually Works What Is a Reverse Proxy? (And Why Every Backend Developer Should Care) What Claude Opus 4.8 Actually Changes If You’re Building Agents QWEN 3.7 Max Worked For 35 Hrs Straight And The Results Were Mind-blowing When LLMs Meet Knowledge Graphs on the Battlefield Fine-Tuning is Dead: Why Context Orchestration Won in 2026 5 Things Broke When I Shipped a RAG + MCP Agent to Production. Google Co-Scientist: Hyper Scaling Research and Discovery Microsoft Just Embarrassed Browser Web Agents — 1,000 Lines Made GPT-5.4 Beat Opus 4.6 on 200 Web Tasks The Modern Data Stack Is Broken — Here’s How to Fix It With AI, Governance, and Real Architecture Building Production MCP Servers: What the Spec Won’t Tell You When Should an Agent Stop? The Anatomy of Termination Harness Engineering: The Layer That Matters More Than the Model AI Engineers Who Can’t Debug Are Getting Fired (Here’s How I Debug with Claude Code) Claude Code Memory: Why You Keep Explaining the Same Thing to Claude (and the Five Layers That Fix It) Claude Code Subagents: The Claude Code Feature You Skip Every Day (And Why It Quietly Wrecks Your Sessions) Agentic AI and the SMB Banking Advantage Claude Code: Spec-Driven Development — Why Your AI Coding Sessions Fall Apart at Hour Three The Real Cost of Agentic AI Nobody Budgets For SVM : 40 must visit Interview Questions (Part 2) Your AI Agent Works Perfectly in the Demo. Here Are the 6 Ways It Dies in Production. Unleashing the Power of ONNX for Speedier SBERT Inference Terraform vs CI/CD for Serverless Deployments Merve Noyan Stopped Writing Training Scripts — Her Agent Just Fine-Tuned 18 Models Solo for $11.40 Why Your Sales Forecast Is Always 20% Wrong (And How To Make It 12% Wrong) Genetic Cubic n{C/A} Ratios For Elementary Robotics Design Top 20 AdaBoost Interview Questions & Answers (Part 2 of 2) Agentic AI Vs AI Agents — What Are the Key Differences? LAI #127: The Infrastructure Layer of AI Is Becoming the Product Anthropic Caught Its Own AI Planning to Blackmail Engineers RNNs Cannot Think What Transformers Think Cheaply. ICLR 2026 Proved the Gap Is Exponential. Time Series Made So Easy My Aunt Got It on the Second Read Claude Cowork 101 | Towards AI Is 3-Bit KV Cache the Holy Grail? A Reality Check on Google’s TurboQuant LangGraph Multi-Agent Architecture: Building a Self-Critiquing AI Debate System AutoML on Autopilot | Towards AI I Ran This Open-Source AI Tool on a Messy Codebase and Got 71x Fewer Tokens — Here Is Exactly What Happened Month in 4 Papers (April 2026) AI Kept Forgetting My Notes. Fixing That Taught Me How It Actually Works. How ChatGPT Makes You Addicted Crack ML Interviews with Confidence: K-Nearest Neighbors (KNN 20 Q&A) The Event-Driven Blueprint: How I Scaled a Spring Boot System to 10 Million Kafka Messages/Day Building Vector Search? Why FAISS Alone Isn’t Enough TAI #202: GPT-5.5 Moves Codex Into Real Work Machine Learning System Design -The Model Serving Triangle, With One Forward Pass Flowing Through Every Trade-off (Part3) AI Orchestration in Action: How MuleSoft and LLMs Fuel the Future of Enterprise AI GPT-4 Has 1.8 Trillion Parameters. It Uses 2% of Them Per Token. Part 20: Data Manipulation in Multi-Dimensional Aggregation A Fundamental Introduction to Genetic Algorithm -Part Two TAI #200: Anthropic’s Mythos Capability Step Change and Gated Release From Notebook to Production: Running ML in the Real World (Part 4) Sqribble’s Template‑Driven Document Automation Anthropic Just Shipped the Layer That’s Already Going to Zero Long-Term vs Short-Term Memory for AI Agents: A Practical Guide Without the Hype The L1 Loss Gradient, Explained From Scratch Your Postcode Is Deciding Your Care. I Built a Pipeline to Prove It. I Directed AI Agents to Build a Tool That Stress-Tests Incentive Designs. Here’s What It Found. Your System Prompt Is the Product — Not the Feature The LLM Wiki Trend Has a Retention Problem Nobody Mentions Top 20 Data Preparation Interview Questions and Answers (Part 2 of 2) LAI #122: Word Embeddings Started in 1948, Not With Word2Vec Top 15 Computer Vision Datasets [2026] 40 Generative AI Interview Questions That Actually Get Asked in 2026 (With Answers)
Understanding Reinforcement Learning — A Primer | Towards AI
Ayo Akinkugbe · 2026-06-25 · via Towards AI

Originally published on Towards AI.

Understanding Reinforcement Learning — A Primer
Photo by Girl with red hat on Unsplash

Introduction: Learning by Trial and Error

Imagine teaching a dog to fetch a ball. You don’t hand the dog a manual titled “The Complete Guide to Ball Retrieval.” Instead, you throw the ball, and when the dog brings it back, you give it a treat. When the dog gets distracted and wanders off, you withhold the treat. Over dozens of repetitions, the dog learns that bringing the ball back leads to rewards, while ignoring the ball doesn’t. This process of learning through interaction, experimentation, and feedback is exactly what reinforcement learning does for artificial intelligence.

Teaching a dog to fetch a ball

A Different Type of Learning : Supervised, Unsupervised, Reinforced

Reinforcement learning is fundamentally different from the other types of machine learning you might be familiar with. In supervised learning, we show the algorithm thousands of examples with correct answers, like showing a child flashcards where one side has a picture of an apple and the other side has the word “apple.”

In unsupervised learning, we give the algorithm data without answers and ask it to find patterns, like asking someone to organize a messy drawer without telling them how. But in reinforcement learning, we do something more interesting: we place an agent in an environment, give it a goal, and let it figure out how to achieve that goal through experimentation.

The agent doesn’t know the right answer in advance. It doesn’t have a dataset of correct moves to learn from. Instead, it takes actions, observes what happens, receives rewards or penalties, and gradually learns which actions tend to lead to good outcomes and which ones don’t. This is how DeepMind’s AlphaGo learned to beat world champions at Go, how robotic arms learn to grasp objects, and how autonomous vehicles learn to navigate roads. The agent learns by doing, making mistakes, and slowly improving its strategy based on the consequences of its actions.

“In reinforcement learning, the agent doesn’t know the right answer in advance. It doesn’t have a dataset of correct moves to learn from. Instead, it takes actions, observes what happens, receives rewards or penalties and gradually learns which actions tend to lead to good outcomes and which ones don’t.”

The Core Components of Reinforcement Learning

At the heart of every reinforcement learning problem are 5 fundamental components that work together in a continuous loop. Understanding each of these components and how they interact is essential to grasping how reinforcement learning actually works.

Agent

The agent is the learner or decision-maker. In our dog example, the dog is the agent. In a video game, the agent might be the character you control. In a self-driving car, the agent is the AI system making decisions about steering, acceleration, and braking. The agent exists to make decisions, and its entire purpose is to learn which decisions lead to the best outcomes. The agent doesn’t start out knowing anything; it begins with a blank slate and learns entirely from experience.

Environment

The environment is everything the agent interacts with. It’s the world in which the agent operates. For the dog, the environment includes the room, the ball, you as the trainer, and all the physical laws that govern how balls bounce and roll. For a chess-playing agent, the environment is the chessboard and the rules of chess. For a trading algorithm, the environment is the stock market with all its complexity, volatility, and rules. The environment responds to the agent’s actions and provides feedback. It’s important to note that the agent doesn’t control the environment; it can only influence it through its actions.

“The agent doesn’t control the environment; it can only influence it through its actions.”

State

A state represents a specific situation or configuration of the environment at a particular moment in time. When you’re teaching the dog to fetch, one state might be “ball has just been thrown and is in the air,” another state might be “ball has landed fifteen feet away,” and another might be “dog has ball in mouth and is five feet from owner.” States capture all the relevant information the agent needs to make a decision. In a video game, the state might include the positions of all characters, their health levels, available items, and the current score. The quality of the state representation is key: if you don’t include important information in your state, the agent won’t be able to make good decisions.\

“A state represents a specific situation or configuration of the environment at a particular moment in time.”

Action

An action is something the agent can do to interact with the environment. Actions are the agent’s way of influencing its world. For the dog, actions might include “run toward ball,” “pick up ball,” “run toward owner,” or “lie down and take a nap.” For a chess agent, actions are the legal moves available given the current board position. For a robot learning to walk, actions are the specific motor commands sent to each joint and actuator. The set of available actions can change depending on the current state. In chess, the legal moves change with every move made. In the fetch example, the dog can’t pick up the ball if the ball isn’t within reach.

“An action is an agent interacting or influencing the environment”

Reward

The reward is the feedback signal that tells the agent whether its action was good or bad. Rewards are numbers: positive numbers for good outcomes and negative numbers (penalties) for bad outcomes. When the dog brings the ball back, it gets a positive reward (the treat, which we might represent as +10). When it ignores the ball, it gets zero or even a small negative reward (no treat, perhaps represented as -1 or 0). The reward is the only way the environment communicates value to the agent. The agent’s entire learning process is driven by a single objective: maximize the total reward it receives over time. This is crucial to understand — the agent doesn’t know what “fetching” means or why it’s good. It only knows that certain sequences of actions lead to higher rewards, and it will do whatever it takes to get those rewards.

“The reward is how the environment communicates value to the agent.”

These five components interact in a continuous cycle that we call the agent-environment loop. The agent observes the current state of the environment, chooses an action based on that state, executes that action, and then observes the new state and the reward it received. This new state becomes the current state, and the cycle repeats. Over thousands or millions of these cycles, the agent gradually learns which actions to take in which states to maximize its long-term rewards.

The Learning Process

When a reinforcement learning agent first encounters an environment, it knows absolutely nothing. It’s like a newborn baby encountering the world for the first time — it doesn’t know what actions are good, what states are dangerous, or what strategies might lead to success. So what does it do? It explores randomly.

In the beginning, the agent takes random actions just to see what happens. If we’re training an agent to play a video game, it might randomly jump, run left, run right, shoot, or stand still without any rhyme or reason. Most of these random actions will lead to poor outcomes. The character might run off a cliff, walk into an enemy, or simply wander aimlessly. But occasionally, by pure chance, the agent will stumble upon something good. Maybe it randomly walks near a power-up and receives a reward, or it accidentally defeats an enemy and gets points. These moments are crucial because they’re the seeds from which learning grows.

Every time the agent takes an action, it records what happened: “I was in state S, I took action A, I ended up in new state S’, and I received reward R.” This experience is stored in the agent’s memory. Over time, the agent accumulates thousands or millions of these experiences. The agent then uses these experiences to build an understanding of the environment’s dynamics and the value of different actions in different states.

The key insight is that the agent doesn’t just care about immediate rewards. If you’re playing a video game, picking up a small coin might give you 1 point right now, but positioning yourself correctly might let you access a treasure chest worth 100 points a few moves later. The challenge is learning to value actions not just by their immediate payoff, but by their long-term consequences. This is what makes reinforcement learning both powerful and challenging.

To handle this temporal credit assignment problem, reinforcement learning agents use a concept called discounted future rewards. The idea is simple: a reward you’ll receive right now is worth more than the same reward you might receive far in the future. We capture this idea mathematically with a discount factor (usually called gamma, γ) between 0 and 1. If gamma is 0.9, then a reward of 10 points one step in the future is worth 9 points to you right now (10 × 0.9). A reward of 10 points two steps in the future is worth 8.1 points right now (10 × 0.9 × 0.9). The farther in the future a reward is, the less it influences your decision right now.

The agent’s goal is to learn a policy — a strategy that maps states to actions. A policy tells the agent, “When you’re in this state, you should take this action.” In the beginning, the policy is essentially random. But as the agent learns from experience, the policy improves. It starts to encode useful strategies: “When I see an enemy, move away” or “When I see a power-up, move toward it” or “When I’m near the goal, take the action that gets me there fastest.

There are different ways to learn this policy, but one of the most intuitive approaches is called Q-learning, which we’ll implement in detail in a later post. Q-learning works by learning the “quality” or “value” of taking each action in each state. The Q-value Q(s, a) answers the question: “If I’m in state s and I take action a, how much total reward can I expect to receive from now until the end?” By learning these Q-values, the agent can always choose the action with the highest Q-value, which is the action expected to lead to the best long-term outcome.

The Exploration-Exploitation Dilemma

One of the most fascinating challenges in reinforcement learning is the exploration-exploitation tradeoff, a problem that exists not just in AI but in human decision-making as well. Imagine you’ve found a restaurant you really like. Every time you go there, you have a great meal. But there are dozens of other restaurants nearby you’ve never tried. Do you keep going to your favorite restaurant (exploitation) or try new ones (exploration)? If you only exploit, you might miss out on an even better restaurant. If you only explore, you’ll never settle down and enjoy consistently good meals.

Reinforcement learning agents face this exact dilemma at every decision point. Should the agent take the action it currently believes is best based on what it’s learned so far (exploitation), or should it try a different action to see if it might discover something even better (exploration)? This is fundamental to whether learning will succeed or fail.

If an agent only exploits, it becomes stuck in what we call a local optimum. Imagine an agent learning to navigate a maze. It might discover a path that leads to a small reward of 5 points. If it only exploits this known path, it will never discover the path on the other side of the maze that leads to a reward of 100 points. The agent has found something that works, but not the best possible solution. It’s like thinking the first restaurant you tried is the best in the city simply because you never tried the others.

“Exploiting is like thinking the first restaurant you tried is the best in the city simply because you never tried the others.”

On the other hand, if an agent only explores and never exploits, it never benefits from what it’s learned. It keeps trying random actions even after it’s discovered good strategies. This is inefficient and can prevent the agent from ever converging on a good solution. Imagine if every single time you went out to eat, you picked a completely random restaurant, even after you’d tried hundreds of them. You’d never build up a list of favorites or avoid places you know are bad.

The solution to this dilemma is to do both: explore when you’re uncertain or when you haven’t learned much yet, and exploit increasingly as you become more confident in your knowledge. One of the popular approaches is called epsilon-greedy exploration. The idea is straightforward: most of the time (with probability 1 — ε), choose the action you currently believe is best. But with a small probability ε (epsilon), choose a completely random action instead. This ensures that the agent mostly does what it thinks is right but occasionally tries something new.

“Explore when you’re uncertain or when you haven’t learned much yet.

Exploit increasingly as you become more confident in your knowledge.”

Typically, we start with a high epsilon value (like 0.9 or 1.0) at the beginning of training, meaning the agent explores almost randomly. As training progresses and the agent learns more, we gradually decrease epsilon (a process called epsilon decay) so that the agent explores less and exploits its knowledge more. By the end of training, epsilon might be as low as 0.01, meaning the agent only explores 1% of the time and follows its learned policy 99% of the time.

The following posts in this series will go into more details on implementing these concepts.

Published via Towards AI

Towards AI Academy

We Build Enterprise-Grade AI. We'll Teach You to Master It Too.

15 engineers. 100,000+ students. Towards AI Academy teaches what actually survives production.

Start free — no commitment:

6-Day Agentic AI Engineering Email Guide — one practical lesson per day

Agents Architecture Cheatsheet — 3 years of architecture decisions in 6 pages

Our courses:

AI Engineering Certification — 90+ lessons from project selection to deployed product. The most comprehensive practical LLM course out there.

Agent Engineering Course — Hands on with production agent architectures, memory, routing, and eval frameworks — built from real enterprise engagements.

AI for Work — Understand, evaluate, and apply AI for complex work tasks.

Note: Article content contains the views of the contributing authors and not Towards AI.