Skip to content
中文

BudgetError ​

CORE · class · Runtime value

A configured allowance (rounds, model calls, attempts) is exhausted.

The optional message states which allowance ran out; code is the stable marker.

Import ​

ts
import { BudgetError } from '@jangts/agent-core/model';
js
import { BudgetError } from '@jangts/agent-core/model';

Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/errors.

Definition ​

ts
class BudgetError

Extends or implements: Error.

Constructor ​

ts
new BudgetError(message?: string): BudgetError
ParameterTypePassingDescription
messagestring | undefinedOptional—

Returns: BudgetError.

Constructor ​

ts
new BudgetError(message?: string, options?: ErrorOptions): BudgetError
ParameterTypePassingDescription
messagestring | undefinedOptional—
optionsErrorOptions | undefinedOptional—

Returns: BudgetError.

Instance properties ​

FieldTypeRequiredDescription
code"BUDGET"RequiredRead-only. See the type definition and usage context.

Examples ​

Allow only two business attempts ​

Beginner · Node.js

ts
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take()) console.log('attempt', attempts.used);
console.log(attempts.available); // false
js
import { AttemptBudget } from '@jangts/agent-core/engine';
const attempts = new AttemptBudget(2);
while (attempts.take())
    console.log('attempt', attempts.used);
console.log(attempts.available); // false

Distinguish an exhausted quota from invalid data ​

Configuration · Node.js

ts
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer: string) {
  if (!answer.trim()) throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
  return answer;
}
try { requireAnswer(''); }
catch (error) { console.log(getErrorInfo(error)); }
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));
js
import { BudgetError, ValidationError, getErrorInfo } from '@jangts/agent-core';
function requireAnswer(answer) {
    if (!answer.trim())
        throw new ValidationError([{ code: 'ANSWER_EMPTY', message: '回答不能为空' }]);
    return answer;
}
try {
    requireAnswer('');
}
catch (error) {
    console.log(getErrorInfo(error));
}
const exhausted = new BudgetError('本次业务的尝试额度已用尽');
console.log(getErrorInfo(exhausted));

API reference, usage examples and developer guides.