cpp-reinforcement-learning

cpp-reinforcement-learning is a skill for Claude Code, Codex from Aznatkoiny/zAI-Skills. It costs 83 tokens per session (1,231 once invoked), scanned A, original, MIT.

Guidance for implementing reinforcement learning in C++ with LibTorch, PyTorch's C++ interface, and modern C++ standards.

In plain words
What is it for?
Use it to build algorithms such as DQN, PPO, or SAC for robotics, games, simulations, and other performance-sensitive applications.
Why use it?
It helps structure high-performance training systems while handling tensors, replay buffers, parallel environment runs, and model deployment.

Skill for Claude CodeCodex

Part of the ai-toolkit plugin — 6 skills, 4 commands, 2 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/aznatkoiny/zai-skills/cpp-reinforcement-learning
Any agent
npx skills add Aznatkoiny/zAI-Skills --skill cpp-reinforcement-learning
Clone the repo
git clone --depth 1 https://github.com/Aznatkoiny/zAI-Skills

Made for: Claude Code, Codex.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 6 skills, 4 commands, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cpp-reinforcement-learning

README.md
[![agentmods](https://agentmods.dev/badge/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning.svg)](https://agentmods.dev/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning)
Your own site
<a href="https://agentmods.dev/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning"><img src="https://agentmods.dev/badge/skills/aznatkoiny/zai-skills/cpp-reinforcement-learning.svg" alt="Measured on agentmods" height="20"></a>
Per session 83 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,231 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00083 $0.01231
Opus 5 $0.00042 $0.00616
Sonnet 5 $0.00017 $0.00246
Haiku 4.5 $0.00008 $0.00123

Measured 4d ago against content hash 579fbd7b22ea, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cpp-reinforcement-learning scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AI-Toolkit/skills/cpp-reinforcement-learning/SKILL.md · 160 lines

How it starts

The opening of the file, as written. The whole thing — 160 lines — stays where its author put it; the contents beside it link to each section on GitHub.

C++ Reinforcement Learning

Overview

This skill covers implementing reinforcement learning algorithms in C++ using LibTorch (PyTorch C++ frontend) and modern C++17/20 features. It provides patterns for building high-performance RL systems suitable for production deployment, robotics, game AI, and real-time applications.

When to Use

  • Implementing DQN, PPO, SAC, or other RL algorithms in C++
  • Building performance-critical RL training pipelines
  • Creating efficient replay buffers with proper memory management
  • Deploying trained models with ONNX Runtime
  • Parallelizing environment rollouts across threads
  • Integrating RL with existing C++ codebases (games, robotics, simulations)

Core Libraries

Primary: LibTorch (PyTorch C++ Frontend)

LibTorch provides the same tensor operations and autograd capabilities as PyTorch in C++.

Installation: Download from https://pytorch.org/get-started/locally (select C++/LibTorch)

CMake Integration:

cmake_minimum_required(VERSION 3.18)
project(rl_project)

set(CMAKE_CXX_STANDARD 17)
find_package(Torch REQUIRED)

add_executable(train_agent src/main.cpp)
target_link_libraries(train_agent "${TORCH_LIBRARIES}")

Secondary Libraries

  • ONNX Runtime - Cross-platform inference deployment
  • cpprl (mhubii/cpprl) - Reference PPO implementation
  • Gymnasium C++ bindings - Environment interfaces

Quick Start: DQN Agent

#include <torch/torch.h>

struct DQNNet : torch::nn::Module {
    torch::nn::Linear fc1{nullptr}, fc2{nullptr}, fc3{nullptr};

    DQNNet(int64_t state_dim, int64_t action_dim) {
        fc1 = register_module("fc1", torch::nn::Linear(state_dim, 128));
        fc2 = register_module("fc2", torch::nn::Linear(128, 128));
        fc3 = register_module("fc3", torch::nn::Linear(128, action_dim));
    }

    torch::Tensor forward(torch::Tensor x) {
        x = torch::relu(fc1->forward(x));
        x = torch::relu(fc2->forward(x));
        return fc3->forward(x);
    }
};

// Training loop
auto policy_net = std::make_shared<DQNNet>(state_dim, action_dim);
auto target_net = std::make_shared<DQNNet>(state_dim, action_dim);
torch::optim::Adam optimizer(policy_net->parameters(), lr);

// Compute loss
auto q_values = policy_net->forward(states).gather(1, actions);
// Tensor::max(dim) returns std::tuple<values, indices> in C++
auto next_q = std::get<0>(target_net->forward(next_states).max(1)).detach();
auto target = rewards + gamma * next_q * (1 - dones);
auto loss = torch::mse_loss(q_values.squeeze(), target);

// Backward pass
optimizer.zero_grad();
loss.backward();
optimizer.step();

Read the full file on GitHub · 160 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 160 lines · 83 tokens per session scan A 579fbd7b22ea

Subscribe to this mod's changes

cpp-reinforcement-learning is a skill published in the GitHub repository Aznatkoiny/zAI-Skills (9 stars, last pushed 1mo ago), licensed MIT. It adds 83 tokens to every session and 1,231 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.