Registry / ai-ml / utility-agent

utility-agent

JSON →
library1.0.1jsnpmunverified

A JavaScript/TypeScript implementation of a Utility-Based AI agent for decision-making based on scored actions. Version 1.0.1 (latest). Provides classes for defining actions, scorers, qualifiers, and selectors. Ships TypeScript types. Released in 2023, no recent updates. Compared to behavior trees or finite state machines, utility agents offer more flexible scoring-based decision making. Suitable for game AI or simulation.

npm install utility-agent
INSTALL
IMPORT
SIG · UTILITY-AGENT
U
utility-agent
ai-mljavascriptv1.0.1
harness data pending
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);
Debug
Known issues
gotchaThe tick method may return null if no qualifiers are available or no action selected.
fix
Always check if winningAction is non-null before executing.
affects: >=1.0.0
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.
fix
Run '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.
fix
Ensure MyScorer extends Scorer, not implements Scorer.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
utility-agent — npm install utility-agent · libregistry