Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Fine-Tuning and RL for Agents

Free · sign in to start and track progress

1 · Decide and prepare

  • 1Prompt, optimise or train?
  • 2Training data from traces

2 · Supervised and preference fine-tuning

  • 3SFT with LoRA on a free GPU
  • 4Preference optimisation

3 · Reinforcement learning for agents

  • 5GRPO in practice
  • 6Designing rewards
  • 7Multi-turn RL environments

    Exercise answers

    • Answer: Wrap the triage tools as a TRL environment and run multi-turn GRPO
    • Answer: Measure step-level credit on your own rollouts
  • 8Reward hacking, regressions and shipping
CapstoneTrain a triage model, then decide whether to ship itReference implementation

Module 3 · Reinforcement learning for agents · Lesson 7

Multi-turn RL environments

How to turn an agent's tools into a reinforcement learning environment: what the trainer runs per rollout, which tokens the policy is trained on, how one final reward is shared across several tool-calling turns, what a run costs, and how to choose a framework or hosted trainer.

80 min 2 videos 3 exercises 7-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvFree GPUs on KaggleHugging Face account and CLI

By the end of this lesson you can

  • Wrap an agent's tools and stubs as an RL environment with a reset hook, tool methods and a trajectory reward, using TRL's environment_factory
  • Explain why tool-result tokens are masked from the loss, and compute the share of a rollout's tokens the policy is actually trained on
  • Compute episode-level and step-level (anchor-state) advantages for a group of multi-turn rollouts, and say what each one blames
  • Estimate the token and dollar cost of a multi-turn RL run on a free GPU, a rented GPU and a per-token hosted trainer
  • Choose between TRL, verifiers, OpenEnv, ART, SkyRL and Agent Lightning for a given agent stack

On this page

  • From a completion to an episode
  • The environment contract
  • What the policy is trained on
  • Credit assignment: one reward, several turns
  • Worked example
  • What a run costs
  • Choosing a framework
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01From a completion to an episode
  2. 02The environment contract
  3. 03What the policy is trained on
  4. 04Credit assignment: one reward, several turns
  5. 05What a run costs
  6. 06Choosing a framework
  7. 07Misconceptions and limits
  8. 08Connections
  9. 09Summary

Sources & further reading

  • Group-in-Group Policy Optimization for LLM Agent TrainingPaper · Feng, Xue, Liu, An · 2025GiGPO, the step-level credit method in this lesson (NeurIPS 2025). Section 3 has the anchor-state grouping and the combined advantage; read it after the worked example.
  • RAGEN: Understanding Self-Evolution in LLM Agents via Multi-Turn Reinforcement LearningPaper · Wang et al. · 2025Trajectory-level RL for multi-turn agents and the 'Echo Trap', where reward variance collapses and gradients spike. The findings in the abstract are the part to remember.
  • Search-R1: Training LLMs to Reason and Leverage Search Engines with Reinforcement LearningPaper · Jin et al. · 2025Multi-turn RL with a search tool and an outcome reward. Its 'retrieved token masking' is the same loss mask TRL applies to tool results.
  • The Landscape of Agentic Reinforcement Learning for LLMs: A SurveyPaper · Zhang et al. · 2025The map of the field (TMLR, revised April 2026): agent RL as a partially observable MDP, and a taxonomy by capability (tool use, memory, planning). Use it to find the paper behind any method you meet.
  • GRPO Trainer: Agent training (tools and environment_factory)Docs · Hugging FaceThe environment contract this lesson's code uses: reserved reset and get_reward methods, public methods as tools, max_tool_calling_iterations, and the tools/ metrics. Checked against TRL 1.17.1.
  • verifiers v1: building tasksetsDocs · Prime IntellectThe taskset, task, toolset and harness split that verifiers moved to in 2026 (the v0 API is gone). Read it to see the same environment from the evaluation-first side.
  • OpenEnv: agentic execution environmentsDocs · OpenEnv (Hugging Face and community)A Gymnasium-style reset/step/state API over WebSocket, with each environment packaged as a Docker image. The README lists which trainers can use it.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 9 more sections
  • 3 hands-on exercises
  • A 7-question quiz
  • Progress, quiz scores and bookmarks