Hello World

This step-by-step guide shows how to create a custom plugin using TypeScript.

This plugin will expose a function that returns a hardcoded string ("hello, world!"). This function can be called by your agent.

To create and deploy the plugin, follow these steps:

  1. Sign in to asterai
  2. Create a new agent. You can call it hello-world-agent.
  3. Install the asterai CLI. Example using npm:
npm install -g @asterai/cli 
  1. Generate a new API key in your asterai dashboard, and use it to authenticate your CLI:
asterai auth <your_api_key> 
  1. Initialise a new plugin project called hello-world-plugin. This will create a new directory with a template plugin project.
asterai init hello-world-plugin
  1. Install dependencies on the new project:
cd hello-world-plugin
npm i
  1. Inspect the contents of plugin.wit, the plugin interface file.
  2. Inspect the contents of plugin.ts, the plugin implementation.
  3. Modify the contents of plugin.wit, removing the example mul function and adding a new function for getting a secret phrase. Also rename the plugin name to hello-world-plugin and ensure to replace your-username in plugin.wit with your asterai username, as otherwise you will not be able to deploy the plugin.
package your-username:hello-world-plugin@0.1.0;

world plugin {
  import asterai:host/api@0.1.0;

  export get-secret-phrase: func() -> string;
}
  1. Run npm run build. This will generate the utility types, but building will fail -- this is expected.
  2. Update plugin.ts to implement the get-secret-phrase function. It needs to return a string. The function will also send a message to the agent with that same string, by calling asterai.sendResponseToAgent("string-here"). Your plugin.ts will look like this:
import * as asterai from "asterai:host/api@0.1.0";

export const getSecretPhrase = (): string => {
  const phrase = "hello, world!";
  // Send the secret phrase to the agent.
  asterai.sendResponseToAgent(phrase);
  return phrase;
};
  1. Build the plugin with npm run build to check that everything is correct.
  2. Get your agent ID from the cloud console.
  3. Deploy the plugin:
asterai deploy --agent <your_agent_id>
  1. Refresh the page in the cloud console. You should see the new plugin that was just deployed.
  2. In the playground section, ask "what is the phrase?". The agent should reply mentioning "hello, world!".
  3. You can query the agent programmatically with a library or HTTP REST API.

Hopefully this hello world example illustrates how asterai can be used to connect AI to applications. Within plugins, it is possible to access LLMs, Vector DBs, make HTTP calls and even use WebSockets.