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 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto_negotiator

v1.0.4

Published

Auto negotiation by Agent

Downloads

3

Readme

Auto Negotiator

install

npm install auto_negotiator

Usage

In order to run auto_negotiator, you need to define Agent having Topic.

Topic is like this:

import type { Topic } from "auto_negotiator/types";

export const topic: Topic = {
  name: "Dinner",
  description: "What should we have dinner?",
  discountFactor: 0.1,
  reservation: 0.3,
  issues: [
    {
      name: "Staple food",
      weight: 3,
      items: [
        {
          name: "Rice",
          evaluation: 7,
        },
        {
          name: "Noodles",
          evaluation: 2,
        },
        {
          name: "Bread",
          evaluation: 1,
        },
      ],
    },
    {
      name: "Main dish",
      weight: 7,
      items: [
        {
          name: "Steak",
          evaluation: 1,
        },
        {
          name: "Fish",
          evaluation: 1,
        },
        {
          name: "Chicken",
          evaluation: 8,
        },
      ],
    },
  ],
};

This Topic has information about dinner. This agent wants to prioritize the main dish over the staple food, because the weights are Staple food: 3, Main dish: 7. In the staple food, the agent want to prioritize rice the most among staple foods.

You have to create topics in the same format for each agent.

After that, you can create an Agent.

Agent need to have actionFn, which is called by each attempt. actionFn is a function getting the next arguments:

{
  data: {
    id: number;
    attempts: Array<Array<Attempt>>;
    attemptsCount: number;
    responseChannelName: string;
  }
  topic: Topic;
  normalizedTopic: NormalizedTopic;
}

And it returns an object of the next format:

{
	id: number;
	choices: Array<Choice>;
	concessionValue: number;
	utility?: number;
	type: AtemptType;
}

If you want to know more details, please look types.ts

In the actionFn, you need to define a logic to compare utilities in order to give an opinion about the Topic. This example is here: sample-agent.ts You can define actionFn by sampleAgent by defining only concessionValueFn.

After that, you can run the negotiation for automatically by negotiate function.

I show you the total example:

import * as negotiator from "auto_negotiator";
import { sampleAgent } from "auto_negotiator/sample-agent";
import { topic as agent1Topic } from "./dinner/agent1.js";
import { topic as agent2Topic } from "./dinner/agent2.js";
import { topic as agent3Topic } from "./dinner/agent3.js";

// channelName is a value required for agents to communicate with each other,
// and can be set to any string.
const channelName = "dinner";

// `concessionValueFn` is a function that returns a value that changes from 1.0
// to 0.0 based on progress, which is a variable that increases from 0.0 to 1.0
// and indicates the overall progress.
const linearAgent = sampleAgent((progress) => 1.0 - progress);
const randomAgent = sampleAgent((_progress) => Math.random());
const exponentialAgent = sampleAgent((progress) => 1.0 - progress ** 0.5);

negotiator.defineAgent({
  channelName: channelName,
  agentName: "linearAgent",
  topic: agent1Topic,
  actionFn: linearAgent,
});
negotiator.defineAgent({
  channelName: channelName,
  agentName: "randomAgent",
  topic: agent2Topic,
  actionFn: randomAgent,
});
negotiator.defineAgent({
  channelName: channelName,
  agentName: "exponentialAgent",
  topic: agent3Topic,
  actionFn: exponentialAgent,
});

const result = negotiator.negotiate({
  channelName,
  attemptsCount: 100,
  agentsCount: 3,
});

console.log(negotiator.toJSON(result));

The result of this program is here: sample/result.json.