Agent RL: train a policy inside a harness
Make the environment, tools and success criterion reproducible.
Detailed technical articles are available in English and Chinese. This locale shows the English article with localized navigation.
Study guide & lesson outline
LEARNING CONTRACTUnderstand → implement → investigate
Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.
- Understand: state assumptions, shapes/units and a counterexample.
- Implement: reproduce a numerical example and inspect boundaries.
- Investigate: compare one alternative under a matched budget.
Understand the mechanism
An agent harness controls observations, tools, budgets, retries and termination. Changing any of these can change the policy’s effective environment. Separate model training from tool implementation and evaluation orchestration. For delayed task rewards, retain trajectories and action outcomes; a final success bit alone rarely explains a failure.
Text / 原始公式
Environment contract = observations + actions + transitions + rewards + termination Evaluate: success, cost, latency, constraint violations
Mechanism map & worked derivation
| Symbol | Meaning |
|---|---|
| sₜ | Observed task context, not necessarily full environment state |
| aₜ | Selected tool action with explicit arguments |
| oₜ₊₁ | Returned observation, including errors |
- Write a transition contract for every tool: input schema, output schema, timeout behavior, side effects and idempotency. This makes the loop testable without a language model.
- A two-call task cannot complete with a one-call hard budget. After lookup, the system should record budget_exhausted rather than inventing verification evidence.
- If a write times out, its commit state is unknown. The next action should check state or use an idempotent retry, not assume nothing happened.
Separate mock control-flow tests from real-policy evaluation. A readable trace is not proof of external task completion.
Original exercise & analysis
Take the bounded agent simulator, introduce a failing tool and vary only the action budget. Record why each run stops. For later real training, freeze the tool schema, task seeds and environment version; evaluate on a second harness to test interface overfitting.
A local state-machine simulation is not RL training. You need sampled trajectories, a reward signal and parameter updates to claim policy learning.
Why might a trained agent fail after a tool rename?
The policy may depend on interface tokens or schema patterns learned in its training environment. Test semantic generalization with controlled interface changes.