You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linear-algebra and probability formulas behind decision policies, outcome scoring, reward shaping, and policy updates in agent-learning.
author
Microsoft
ms.date
2026-08-09
ms.topic
reference
keywords
agentic decision making
reinforcement learning
policy gradient
REINFORCE
softmax
logistic regression
reward shaping
cosine similarity
linear algebra
estimated_reading_time
15
Overview
This document collects every linear-algebra and probability formula used by the
SDK's decision layer. The product abstraction is a small policy over explicit
agent actions: softmax turns relative logits into decision probabilities,
outcome scores become rewards, and REINFORCE adjusts the next decision without
changing foundation-model weights. Each section names the source module so the
math can be traced back to the implementation. All vectors are column vectors
unless stated otherwise, and all softmaxes use max subtraction for numerical
stability.
The policy stores a weight matrix $W \in \mathbb{R}^{K \times d}$. Given a context vector $\phi$, the logits are the matrix–vector product and the distribution is the stable softmax:
$$
z = W \phi, \qquad
\pi(a \mid \phi) = \frac{\exp!\left(z_a - \max_b z_b\right)}{\displaystyle\sum_{c} \exp!\left(z_c - \max_b z_b\right)}
$$
When no context is supplied ($\phi = \mathbf{0}$) the policy is uniform, $\pi(a) = 1/K$. Weight updates are element-wise additive per action row and clipped:
For a softmax policy, the gradient of the log-likelihood of the taken action $a$ with respect to logit $z_k$ is $\mathbb{1}[k = a] - \pi(k)$. The per-episode REINFORCE-with-baseline update for logit $z_k$ is therefore:
For a linear-softmax policy $\pi = \operatorname{softmax}(W\phi)$, the REINFORCE-with-baseline gradient for action row $W_k$ is the outer-product-style term:
Each scorer produces a normalized score $s_m \in [0, 1]$. The shaper maps it to a signed contribution in $[-1, 1]$ and forms a weighted sum with behavioural penalties, then clamps:
Each class stores a prototype vector. The router scores the query $\phi$ against every prototype $p^{(k)}$ by cosine similarity, then softmaxes the similarities:
Each scorer is a binary logistic-regression classifier over a feature vector that concatenates the context, a one-hot action encoding, and a bias term:
$$
x = \big[,\phi \ \Vert \ \mathbf{onehot}(a) \ \Vert \ 1,\big] \in \mathbb{R}^{d + K + 1}
$$
$$
p = \sigma(w \cdot x), \qquad
\text{label} =
\begin{cases}
\text{pass}, & p \ge 0.5 \\
\text{fail}, & p < 0.5
\end{cases}
$$
with confidence $p$ when passing and $1 - p$ when failing.
Tokens are hashed into a fixed number of buckets $D$, removing the need to persist a vocabulary. For token $t$, the bucket is derived from the first 32 bits of its MD5 digest:
$$
h(t) = \big(\text{int}_{32}(\operatorname{md5}(t))\big) \bmod D
$$
The count-based feature vector accumulates over the token stream:
Tier 2 scorers delegate to scikit-learn's TfidfVectorizer (unigram+bigram) feeding a LogisticRegression head. The term-frequency–inverse-document-frequency weight of term $t$ in document $\delta$ over corpus $\mathcal{D}$ is:
Scorers emit scores on heterogeneous scales; each metric normalizes to $[0, 1]$ before shaping.
Metric
Raw range
Normalization
Intent resolution
$[1, 5]$
$\dfrac{\operatorname{clip}(s, 1, 5) - 1}{4}$
Task adherence
$[0, 1]$
$\operatorname{clip}(s, 0, 1)$
Task completion
$[0, 1]$
$\operatorname{clip}(s, 0, 1)$
The intent-resolution mapping sends a perfect score of $5$ to $1.0$ and the worst score of $1$ to $0.0$, so a perfect evaluation becomes the maximum positive reward signal after shaping.