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

@virtuals-protocol/game

v0.1.14

Published

<details> <summary>Table of Contents</summary>

Readme



Getting Started

To get started with GAME, we recommend trying out the game-starter project. This project will get you up and running with a working agent in minutes.

Head over to the folder's readme for instructions on how to get started!

Usage

This is the github repo for our NPM package.

Request for a GAME API key in the Game Console. https://console.game.virtuals.io/ If you have any trouble, contact Virtuals support or DevRel team members via Discord or Telegram.

1. Functions and Executables

Functions define available actions for the agent:

import {
  GameFunction,
  ExecutableGameFunctionResponse,
  ExecutableGameFunctionStatus,
} from "@virtuals-protocol/game";

const myFunction = new GameFunction({
  name: "action_name",
  description: "Description of action",
  args: [
    { name: "param", type: "type", description: "param description" },
  ] as const,
  executable: async (args) => {
    try {
      // Implement your function logic here
      return new ExecutableGameFunctionResponse(
        ExecutableGameFunctionStatus.Done,
        "Action completed successfully"
      );
    } catch (e) {
      return new ExecutableGameFunctionResponse(
        ExecutableGameFunctionStatus.Failed,
        "Action failed"
      );
    }
  },
});

Executable functions must return an instance of ExecutableGameFunctionResponse with:

  • ExecutableGameFunctionStatus
  • Feedback message

2. State Management

Easy and flexible way to define the state management, what the agent sees and how that changes.

async function getAgentState(): Promise<Record<string, any>> {
  return {
    health: 100,
    inventory: ["sword", "shield", "potion"],
  };
}

For more information on how to use state management, you can check out a simple example here: State Management Example

3. Workers

Workers are simple interactable agents that execute the tasks defined by the user. They can be specialized agents with defined capabilities:

import { GameWorker } from "@virtuals-protocol/game";

const worker = new GameWorker({
  id: "worker_id",
  name: "Worker Name",
  description: "Worker description",
  functions: [list_of_functions],
  getEnvironment: async () => {
    return {
      // environment details
    };
  },
});

Key features:

  • Can be shared or unique per worker
  • Processes function execution results to update state

4. Agents

Agents are used to autonomously function in an open-ended manner by just providing a general goal. Tasks are generated by the agent itself continuously, and the agent will attempt to complete them. You can provide many workers to the agent, and they will be used to execute the tasks.

import { GameAgent } from "@virtuals-protocol/game";

const agent = new GameAgent("your_api_key", {
  name: "Agent Name",
  goal: "Primary goal",
  description: "Description",
  getAgentState: agent_state_function,
  workers: [worker1, worker2],
});

// Compile and run
await agent.init();
await agent.run();

In this example, the custom logger will print the agent's name followed by the log message to the console. You can customize the logger function to handle log messages in any way you prefer, such as writing them to a file or sending them to a logging service.

Using the Logger in Custom Functions

You can use the logger within your custom functions to log messages. The logger is passed as an argument to the executable function. Here's an example of how to use the logger in a custom function:

const customFunction = new GameFunction({
  name: "custom_action",
  description: "A custom action with logging",
  args: [{ name: "param", description: "Parameter for the action" }] as const,
  executable: async (args, logger) => {
    try {
      logger(`Executing custom action with param: ${args.param}`);
      // Implement your function logic here
      return new ExecutableGameFunctionResponse(
        ExecutableGameFunctionStatus.Done,
        "Custom action completed successfully"
      );
    } catch (e) {
      logger(`Failed to execute custom action: ${e.message}`);
      return new ExecutableGameFunctionResponse(
        ExecutableGameFunctionStatus.Failed,
        "Custom action failed"
      );
    }
  },
});

In this example, the logger is used to log messages before and after the execution of the custom action. This helps in tracking the function's execution flow and any errors that occur.

Running the Agent

The agent will initialize and start running, performing actions such as posting tweets, searching for tweets, and replying to tweets at regular intervals.

await agent.init();
// running at a fix interval of 60 seconds
await agent.run(60, {
  /**
   * @property {boolean} verbose - A flag to enable or disable verbose logging.
   *
   * @description
   * The `verbose` property is used to control the verbosity of the logging output.
   * When set to `true`, detailed logs will be generated, which can be useful for
   * debugging and development purposes. When set to `false`, only essential logs
   * will be produced, reducing the amount of log output.
   */
  verbose: true | false,
});

Running Agent (without fix interval)

With the step function app has more control over in interval

await agent.step();

Installation

To install the package, run:

npm install @virtuals-protocol/game

Examples

In the examples folder, there are a few self contained examples:

  • twitter-agent: A twitter agent that tweets and replies to tweets.
  • telegram-agent: A telegram agent that sends messages and replies to messages.
  • chat-agent-example: A chat agent that can execute functions and interact with users in a chat.

Just compile with npm run build and npm start to run! (make sure you have an API key first!)

Plugins

In the plugins folder are various plugins that can give your agent more functionality.

Each plugin comes with an example file. Click into the plugin's src folder to run the example.ts file!

Plugins are always open source and we welcome contributions!

Components and Architecture Overview

At a high level, this SDK allows you to develop your agents powered by the GAME architecture in its most full and flexible form. The SDK is made up of 3 main components (Agent, Worker, function), each with configurable arguments. Our docs expands in greater depth G.A.M.E Docs.

New SDK visual

Agent (a.k.a. high level planner)

  • Takes in a Goal
    • Drives the agent's behavior through the high-level plan which influences the thinking and creation of tasks that would contribute towards this goal
  • Takes in a Description
    • Combination of what was previously known as World Info + Agent Description
    • This includes a description of the "world" the agent lives in, and the personality and background of the agent

Worker (a.k.a. low-level planner)

  • Takes in a Description
    • Used to control which workers are called by the agent, based on the high-level plan and tasks created to contribute to the goal

Function

  • Takes in a Description
    • Used to control which functions are called by the workers, based on each worker's low-level plan
    • This can be any executable

Chat Agents

Chat Agents enable interactive conversations with AI agents that can execute functions. They are simpler to use than full Agents and are ideal for chatbot-like interactions where the agent can perform actions.

To create a chat agent:

// Initialize a chat agent with your API key and a system prompt
const agent = new ChatAgent(
    "your-GAME-api-key-here",
    "<agent description>"
);

// Start a conversation
const response = await agent.chat("<user prompt>");

Note: Chat Agents require a V2 API key that starts with "apt-".

Check out our Chat Agent example directory to see how to implement a chat agent with function execution capabilities and how to integrate chat agents with telegram and discord plugins.

Repository Structure

| Folder | Description | |--------|-------------| | /src | Core SDK source code containing the main GAME framework implementation | | /docs | Images, and additional resources | | /examples | Example implementations and use cases of the GAME framework | | /plugins | Plugins availble to use with GAME framework (Discord, Telegram, etc.) | | /game-starter | Starter project that gets you up and running with a working agent |

License

This project is licensed under the MIT License.