@cogment/cogment-js-sdk

Javascript SDK for the Cogment Framework

Usage no npm install needed!

<script type="module">
  import cogmentCogmentJsSdk from 'https://cdn.skypack.dev/@cogment/cogment-js-sdk';
</script>

README

cogment-js-sdk

Retrieve from npm Apache 2 License Changelog

OSS Lifecycle node-current (scoped)

code style: prettier Contributor Covenant

Cogment is an innovative open source AI platform designed to leverage the advent of AI to benefit humankind through human-AI collaboration developed by AI Redefined. Cogment enables AI researchers and engineers to build, train and operate AI agents in simulated or real environments shared with humans. For the full user documentation visit https://docs.cogment.ai

This module, cogment-js-sdk, is the Javascript SDK for making use of Cogment when working with Javascript. It's full documentation can be consulted at https://docs.cogment.ai/cogment/cogment-api-reference/javascript/modules/.

Table of contents

Links

Usage

Install the package:

npm install @cogment/cogment-js-sdk

The test suite embeds a working Cogment application. Parts of the example application pertinent to the js-sdk test suite:

  • an echo actor
  • an environment
  • cogment.yaml - the configuration entrypoint into Cogment and is used to generate language specific static configuration files.
  • data.proto - application specific protobufs that represent trial entities (eg: observation space, actor action space, etc) in addition to other utility protobufs needed by the user, you!

The ActorSession.test.ts is the most feature complete example of a working cogment application and is documented to be read as such.

Examples follow.

Instantiate a CogmentService

import {createService} from 'cogment';
import cogSettings from './CogSettings';

const cogmentService = createService({
  cogSettings,
});

Start and stop a trial

import {createService} from 'cogment';
import cogSettings from './CogSettings';

const cogmentService = createService({
  cogSettings,
});

const trialController = cogmentService.createTrialController();

const {trialId} = await trialController.startTrial('unique-id');
return trialController.terminateTrial(trialId);

Register an actor and join the trial

import {createService, TrialActor} from 'cogment';
import cogSettings from './CogSettings';
import {ClientAction, Observation} from './data_pb';

const cogmentService = createService({
  cogSettings,
});

const trialActor: TrialActor = {
  name: 'client_actor',
  actorClass: 'client',
};

cogmentService.registerActor<ClientAction, Observation, never>(
  trialActor,
  async (actorSession) => {
    // Actor implementation here.
  },
);

const trialController = cogmentService.createTrialController();
const {trialId} = await trialController.startTrial(trialActor.name);
await trialController.joinTrial(trialId, trialActor);
return trialController.terminateTrial(trialId);

Watch for trial state changes

import {createService} from 'cogment';
import cogSettings from './CogSettings';

const cogmentService = createService({
  cogSettings,
});

const trialController = cogmentService.createTrialController();

for await (const trialListEntry of trialController.watchTrials([
  0, 1, 2, 3, 4, 5,
])) {
  // Do stuff!
}

Development Workflow

Docker

Docker Setup

  1. Clone the repository:
    git clone https://github.com/cogment/cogment-js-sdk.git
    
  2. Build the docker container:
    docker-compose build cogment-js-sdk
    

Docker Testing

  1. Start the embeded cogment app
    bin/up.bash
    
  2. Run all tests
    docker-compose run cogment-js-sdk npm run test
    

Non-docker

Setup

  1. Clone the repository:
    git clone https://github.com/cogment/cogment-js-sdk.git
    
  2. Install node (check .node-version for the appropriate version). The recommended way to manage node distributions is through nvm (node version manager):
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
    source ~/.nvm/nvm.sh
    cd /path/to/cogment-js-sdk
    nvm install
    
  3. Initialize the repository:
    npm install
    

Testing

  1. Start the embeded cogment app
    bin/up.bash
    
  2. Run the test suite:
npm run test

Release process

People having maintainers rights of the repository can follow these steps to release a version MAJOR.MINOR.PATCH. The versioning scheme follows Semantic Versioning.

  1. Run ./scripts/create_release_branch.sh MAJOR.MINOR.PATCH automatically compute and update the version of the package, create the release branch and update the changelog from the commit history,
  2. On the release branch, check and update the changelog if needed, update internal dependencies as described here, and make sure everything's fine on CI,
  3. Run ./scripts/tag_release.sh MAJOR.MINOR.PATCH to create the specific version section in the changelog, merge the release branch in main, create the release tag and update the develop branch with those.

The rest, publishing the packages to dockerhub and updating the mirror repositories, is handled directly by the CI.