Implement the full AgentOPSD credit-assignment block for a single trajectory.
agentopsd_turn_advantages(
turn_evidence, # (K,) e_k — pre-aggregated teacher–student gaps
A_seq, # scalar GRPO sequence advantage
B0, # scalar prior belief (already clipped group success rate)
gamma=0.95, # evidence decay
b=0.2, # multiplier band
lam=0.5, # reshaping mixture λ
eps=1e-4,
) -> np.ndarray # (K,) reshaped turn advantages Ã_k
Steps (must match the paper):
- ℓ0=logit(clip(B0))
- For k=1..K: ck=γck−1+ek, ℓk=ℓ0+ck, Bk=σ(ℓk)
- ΔBk=Bk−Bk−1 (with B0 the prior)
- qk=sign(Aseq)ΔBk
- zk = within-trajectory z-score of q (population std, +ε in the denominator)
- wk=clip(1+bzk, 1−b, 1+b)
- A~k=Aseq[(1−λ)+λwk]
Return A~ as a float64 NumPy array of shape (K,).