Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
UtilityAgent
✓ import { UtilityAgent } from 'utility-agent'
✗ const UtilityAgent = require('utility-agent')
Package ships TypeScript types and exports are ESM compatible.
Action
✓ import { Action } from 'utility-agent'
✗ import Action from 'utility-agent'
Action is a named export, not default export.
Scorer
✓ import { Scorer } from 'utility-agent'
✗ import { Scorer } from 'utility-agent/lib/Scorer'
Import from the package root, not subpath.
Shows how to create a custom action, scorer, and agent with qualifiers and selector, then tick and execute.
import { Action, Context, HighestScoringSelector, Qualifier, SumOfChildrenQualifier, UtilityAgent, Scorer } from 'utility-agent';
class MyAction implements Action {
readonly name = 'myAction';
execute(context: Context): Context {
console.log('Executing', this.name);
return context;
}
terminated(context: Context): Context {
console.log('Terminated', this.name);
return context;
}
}
class MyScorer extends Scorer {
score(context: Context): number {
return this.linearFunction(10, 1, 0);
}
}
const qualifiers: Qualifier[] = [
new SumOfChildrenQualifier([new MyScorer()], new MyAction()),
];
const selector = new HighestScoringSelector();
const agent = new UtilityAgent(selector, qualifiers);
const context: Context = {};
const winningAction = agent.tick(context, null);
const updatedContext = winningAction.execute(context);
Errors
Common errors & fixes
Cannot find module 'utility-agent' or its corresponding type declarations
Package not installed or missing TypeScript type definitions if using ts.
fixRun 'npm install utility-agent'. For TypeScript, ensure 'types' field exists in tsconfig or 'allowSyntheticDefaultImports' is true.
Uncaught TypeError: scorer.linearFunction is not a function
linearFunction is a method of Scorer base class, not static. Must extend Scorer.
fixEnsure MyScorer extends Scorer, not implements Scorer.
Audit
Dependencies
No dependency data recorded yet.