agent/rules.ts
Source: sdks/typescript/packages/sdk/src/agent/rules.ts. Back to the TypeScript SDK reference index.
This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.
Type alias LENGTH_RECOVERY_PROMPT
Prompt of the length_recovery rule, sent when the model stopped on its output limit; the rule texts are the ones of the Navin runner.
Type alias RuleCode
Canonical rule codes, shared with the Python SDK and the Navin runner.
Definition: \| "length_recovery" \| "empty_final_response" \| "go_ahead" \| "no_action" \| "remaining_work" \| "delivery" \| "verify_before_done" \| "verify_failed" \| "no_progress" \| "wrap_up" \| "exploration".
Interface RuleContext
State a rule reads to decide whether the turn may end.
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
phase | "final" | "tools" | yes | "final": the model answered without tool calls. "tools": after a batch of tool calls. |
finishReason | string | null | yes | Finish reason of the last model call, for example length or stop. |
finalText | string | yes | Text of the last model answer. |
lastUserText | string | yes | Last message the user wrote in this turn (nudges excluded). |
toolCalls | number | yes | Tool calls run in this turn. |
unverifiedWrite | boolean | yes | A write tool ran after the last verify tool. |
verifyFailed | boolean | yes | The last verify tool failed and no verify passed since. |
noProgressStreak | number | yes | Consecutive tool calls that repeated an earlier call with the same result. |
readStreak | number | yes | Consecutive read tool calls since the last write, run or verify. |
limitUsage | number | yes | Fraction (0..1) of the closest limit already used. |
deliveryRequired | boolean | yes | The workflow needs a tool call before the answer (delivery rule). |
auditMode | boolean | yes | Audit mode of the runner: raises the exploration cap from 4 to 8. |
nudges | Readonly<Record<string | yes | Nudges already sent in this turn, per code. |
Interface ContinuationRule
A continuation rule: its code, its cap per turn, its phase and the check that returns the nudge prompt or null.
Fields:
| Name | Type | Required | Description |
|---|---|---|---|
code | RuleCode | string | yes | Code of the control, 1 to 64 characters: a catalogue code such as EAI-GOV-01, or a custom one. Unique in the tenant. |
cap | number | ((ctx: RuleContext) => number) | yes | Maximum nudges of this rule per turn. |
phase | "final" | "tools" | yes | When the rule is evaluated: final after an answer without tool calls, tools after a batch of tool calls. |
Type alias NO_PROGRESS_THRESHOLD
Tool calls without progress before the no_progress nudge, and the hard stop.
Type alias EXPLORATION_THRESHOLD
Read calls in a row before the exploration nudge.
Type alias WRAP_UP_THRESHOLD
Share of a limit after which wrap_up fires.
Functions
isGoAhead
isGoAhead(text: string | null | undefined): boolean
True when the user's whole message is a go-ahead with no new request.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
text | string | null | undefined | yes | Message of the user; empty or missing gives false. |
Returns: boolean. True when the trimmed text has at most 60 characters and is only a go-ahead such as go, ok continue or vas-y.
announcesWork
announcesWork(text: string | null | undefined): boolean
True when a final answer announces an imminent action it did not take.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
text | string | null | undefined | yes | Final answer of the model; empty or missing gives false. |
Returns: boolean. True when a sentence that is not a question promises an action, unless it is conditional or left to the user.
listsRemainingWork
listsRemainingWork(text: string | null | undefined): boolean
True when a final answer hands back unfinished work of the request (English and French).
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
text | string | null | undefined | yes | Final answer of the model; empty or missing gives false. |
Returns: boolean. True when the answer lists work still to do that is not left to the user, or announces work it did not take.
defaultRules
defaultRules(): ContinuationRule[]
The rule set of the Navin runner, in evaluation order.
This element takes no parameter.
Returns: ContinuationRule[]. A new array of the eleven rules, from length_recovery to exploration.
evaluateRules
evaluateRules(rules: ContinuationRule[], ctx: RuleContext)
First rule that fires under its cap, for the given phase.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
rules | ContinuationRule[] | yes | Rules to evaluate, in order; only those of the phase of the context are checked. | |
ctx | RuleContext | yes | Context of the call: cancellation and deadline. |