npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

utility-agent

v1.0.1

Published

Utility Agent AI

Downloads

54

Readme

utility-agent

A JavaScript implementation of a Utility Agent

What is a Utility Agent

A Utility Agent is a simple form of AI that make decisions based on the utility (score) of an available set of actions.

For some more information check out [Wikipedia - Utility Based Agents][https://en.wikipedia.org/wiki/Intelligent_agent#Utility-based_agents].

Installation

npm install --save utility-agent

Usage

For Javascript, see below. For Typescript there is a barrel provided. The same classes need to be extended or implemented as in Javascript. See the integration tests.

Create some Actions

Actions are what your agent is capabile of doing. The Action should return the modified context.

import {Action, Context} from 'utility-agent';

export class ExampleAction implements Action {

  readonly name = "example"; 
  
  execute(context: Context): Context {
    //Perform your action here.
    console.log("Executing action", this.name);
    return context;
  }

  terminated(context: Context): Context {
    console.debug("Action Terminated", this.name);
    return context;
  }
}

Create some scorers

Scorers calculate a utility score based on the provided context. The base Scorer provides some utility functions for common formulas.

import {Context, Scorer} from 'utility-agent';

export class ExampleScorer extends Scorer {

  score(context: Context): number {
    //Your scoring logic goes here.
    //There are a bunch of helper methods for performing some calcuations as well.
    return this.linearFunction(10, 1, 0);
  }
}

Create the Agent

The Agent is the entry point and configuration for the system. This is where you instantiate your Actions and link them to to your Scorers. These will go into an array of Qualifiers. Then we pick which Selector we are going to use and instantiate our UtilityAgent.

import {Context, HighestScoringSelector, Qualifier, SumOfChildrenQualifier, UtilityAgent} from 'utility-agent';

//This is the set of actions that your AI will perform.  A Qualifier links a set of 
//   reusable scorers together to determine the total score for the Action.  There
//   are multiple types of Qualifiers.
const qualifiers = [
    new SumOfChildrenQualifier([ new ExampleScorer() ], new ExampleAction()),
];

//Create the Selector, which dictates the method by which scored Qualifiers will be chosen.
const selector = new HighestScoringSelector();

//Finally instantiate your Agent
const agent = new UtilityAgent(selector, qualifiers);

Tick the agent logic

When you call the tick() method on your agent it will calculate the utilities and pick a winning Action. It will be up to the client to invoke the action with its managed Context.

//Tick one cycle of the logic
const winningAction = agent.tick(context, null); //our Selector doesn't require a default value here
//Execute the action that was returned
const updatedContext = winningAction.execute(context);