Forward Deployed EngineeringAI EngineeringTool-using Agent Training

RL-train a 7B model to use SQL and a calculator with no human feedback on intermediate steps.

Question 72 of 73 · Updated

On this page

Interview-ready answer#

I would use reinforcement learning with verifiable rewards (RLVR). Instead of asking humans to label each reasoning step, I would build a reproducible environment where the 7B model can call SQL and calculator tools, observe their results, and receive an automatically verified reward for its final answer.

The key is to train on complete tool-use trajectories, not just isolated answers. Start with tasks that have reliable ground truth, sample several attempts per task, and use PPO or GRPO to reinforce successful trajectories. Safety and resource limits belong in the environment, not in a learned reward that the agent can trade away.

1. Build the training environment#

Each task contains a question, a database snapshot, an allowed schema, a typed answer contract and a private reference answer. The model sees the question and permitted schema, but not the reference answer.

ComponentDesign
SQL toolRestricted read-only access to a task-specific database; bounded rows, time and query resources
CalculatorTyped arithmetic operations with explicit numeric precision and error handling
ObservationStructured tool results or recoverable error messages
Terminal actionSubmit a typed final answer with units where relevant
VerifierIndependently compares the final answer with trusted ground truth
Episode budgetMaximum generated tokens, tool calls and wall-clock time

Use a restricted database identity, explicit statement and function policies, and isolated execution. Read-only mode alone is not a sufficient sandbox. The calculator should interpret an allowlisted arithmetic representation, not evaluate arbitrary Python or shell code. The model cannot access the reward implementation, hidden answers or other episodes' state.

Loading diagram…

2. Define a reward that measures the outcome#

Begin with a binary terminal success reward: 1 for a correct final result, 0 for an incorrect answer or an exhausted episode. Explicitly handle answerable versus unanswerable tasks. Compare structured values rather than surface text, using task-specific rounding, units, null handling and numerical tolerances. Infrastructure outages should be classified separately and excluded or retried according to a predefined policy, not mistaken for model failures.

Once the agent can solve tasks reliably, a small bounded efficiency penalty on successful episodes can discourage unnecessary calls. For example, give a correct permitted trajectory a reward of 1 − 0.01 × min(tool calls, 10), while incorrect outcomes get 0. This illustrative rule preserves the preference for a correct outcome over a cheap wrong one. Hard authorization constraints remain enforced independently, and policy-violating trajectories cannot qualify as successful.

Worked example#

A user asks: "For cohort A, what percentage of paid transaction value was refunded, rounded to one decimal place?"

The SQL tool returns total paid value of 20,000 cents and refunded value of 7,500 cents. The calculator evaluates 7,500 ÷ 20,000 × 100, producing 37.5%. The terminal verifier accepts the typed percentage 37.5 and rejects incorrect values or incompatible units. Different valid SQL queries and calculation strategies may receive the same outcome reward; there is no need to label each intermediate action.

Executed verification: Python 3.13.5 with SQLite 3.46.1 and Decimal passed 40 synthetic snapshot tests covering varied paid/refunded amounts and unrelated cohorts, plus the 37.5% worked example. Results were compared with an independent integer rounding calculation. These tests validate the example's SQL and arithmetic, not a production sandbox or a trained agent.

3. Make sparse rewards learnable#

A terminal reward gives no direct indication of which earlier decision caused success or failure. If nearly every sampled trajectory fails, training receives little useful signal.

I would start with an instruction-tuned checkpoint that already understands the tool-call format. If needed, use automatically generated valid tool-use demonstrations for a short SFT warm start; no human intermediate labels are required. Build a curriculum from simple aggregation and arithmetic to joins, grouped queries, unit conversions and multi-step tasks that combine both tools. Keep varied difficulty in the training mixture.

Sample multiple stochastic trajectories for the same task. GRPO can compare their verified terminal rewards within the group, avoiding a learned critic (see FDE-0064). With outcome supervision, each generated action token can receive the completion-level advantage. Tool observation tokens are part of the conditioning context but must be masked from the policy loss: they were produced by the environment, not sampled by the model.

If every completion is wrong or every completion is correct, group-centered advantages vanish. Monitor these groups, adjust the difficulty and exploration distribution, and retain a mixture of tasks with meaningful reward variation. For longer interactions, compare a critic-based PPO setup or verified intermediate milestones when available. Automatically checked milestones are optional shaping signals, not human process labels; avoid rewarding merely syntactically valid SQL or tool calls without progress.

4. Train efficiently and prevent shortcuts#

For a 7B model, begin with a small pilot using parameter-efficient adaptation if memory is constrained. Use batched rollouts and parallel isolated database workers; freeze each task snapshot within an episode. Track generated tokens and tool execution time because rollouts may dominate training cost. Compare the trained policy against the SFT baseline under identical inference budgets.

The main reward-hacking risk is learning a shortcut that passes training verification without genuinely solving new problems. Generate multiple database instances with changed values, distributions and schema variations. Separate training and evaluation by schema and task family. Use private independently computed answers and, for tasks that require submitting SQL itself, test semantic behavior across multiple database instances rather than exact query text or one coincidentally correct result.

Do not require tool use for every task merely to increase the tool-call rate. If a direct answer is valid, unnecessary calls are wasteful. When a task specifically requires accessing current database state, test with changed or previously unseen snapshots so memorization cannot reliably pass.

5. Evaluate actual agent capability#

MetricWhat it reveals
Final-answer success on held-out tasks and schemasReal generalization
SQL-only, calculator-only and combined-task successWhich skills improved
Recovery from invalid queries and tool errorsRobustness
Tool calls, generated tokens and latency per correct taskEfficiency
Unauthorized execution attempts and actual boundary violationsPolicy behavior and enforcement

Evaluate the SFT baseline, RL policy and a simpler prompted agent on the same workload and budgets. Test adversarial database contents, missing values, ambiguous requests and tool outages. Require independent correctness and safety gates before deployment.

The core design decision is to make the environment supply trustworthy outcomes, then let the policy learn which tool actions achieve them. Human feedback on every reasoning step is unnecessary when final success is verifiable, but sparse rewards, exploration and security still require careful engineering.

Related questions

Explore other topics:AI AgentsAI System DesignLarge Language Models