Skip to main content

agent/rules.ts

Source: sdks/typescript/packages/sdk/src/agent/rules.ts. Back to the TypeScript SDK reference index.

note

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:

NameTypeRequiredDescription
phase"final" | "tools"yes"final": the model answered without tool calls. "tools": after a batch of tool calls.
finishReasonstring | nullyesFinish reason of the last model call, for example length or stop.
finalTextstringyesText of the last model answer.
lastUserTextstringyesLast message the user wrote in this turn (nudges excluded).
toolCallsnumberyesTool calls run in this turn.
unverifiedWritebooleanyesA write tool ran after the last verify tool.
verifyFailedbooleanyesThe last verify tool failed and no verify passed since.
noProgressStreaknumberyesConsecutive tool calls that repeated an earlier call with the same result.
readStreaknumberyesConsecutive read tool calls since the last write, run or verify.
limitUsagenumberyesFraction (0..1) of the closest limit already used.
deliveryRequiredbooleanyesThe workflow needs a tool call before the answer (delivery rule).
auditModebooleanyesAudit mode of the runner: raises the exploration cap from 4 to 8.
nudgesReadonly<Record<stringyesNudges 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:

NameTypeRequiredDescription
codeRuleCode | stringyesCode of the control, 1 to 64 characters: a catalogue code such as EAI-GOV-01, or a custom one. Unique in the tenant.
capnumber | ((ctx: RuleContext) => number)yesMaximum nudges of this rule per turn.
phase"final" | "tools"yesWhen 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.

NameTypeDefaultRequiredDescription
textstring | null | undefinedyesMessage 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.

NameTypeDefaultRequiredDescription
textstring | null | undefinedyesFinal 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).

NameTypeDefaultRequiredDescription
textstring | null | undefinedyesFinal 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.

NameTypeDefaultRequiredDescription
rulesContinuationRule[]yesRules to evaluate, in order; only those of the phase of the context are checked.
ctxRuleContextyesContext of the call: cancellation and deadline.