Skip to content

Commit

Permalink
feat: support autonome platform (#2121)
Browse files Browse the repository at this point in the history
* feat: support autonome platform

* Update packages/plugin-autonome/src/actions/launchAgent.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix typo

* Update packages/plugin-autonome/src/actions/launchAgent.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Sayo <hi@sayo.wtf>
Co-authored-by: Odilitime <janesmith@airmail.cc>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 10, 2025
1 parent 4df0e5b commit e1b7c80
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,7 @@ TAVILY_API_KEY=
# Verifiable Inference Configuration
VERIFIABLE_INFERENCE_ENABLED=false # Set to false to disable verifiable inference
VERIFIABLE_INFERENCE_PROVIDER=opacity # Options: opacity

# Autonome Configuration
AUTONOME_JWT_TOKEN=
AUTONOME_RPC=https://wizard-bff-rpc.alt.technology/v1/bff/aaa/apps
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@elizaos/plugin-node": "workspace:*",
"@elizaos/plugin-solana": "workspace:*",
"@elizaos/plugin-solana-agentkit": "workspace:*",
"@elizaos/plugin-autonome": "workspace:*",
"@elizaos/plugin-starknet": "workspace:*",
"@elizaos/plugin-stargaze": "workspace:*",
"@elizaos/plugin-giphy": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { obsidianPlugin } from "@elizaos/plugin-obsidian";
import { sgxPlugin } from "@elizaos/plugin-sgx";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaAgentkitPlguin } from "@elizaos/plugin-solana-agentkit";
import { autonomePlugin } from "@elizaos/plugin-autonome";
import { storyPlugin } from "@elizaos/plugin-story";
import { suiPlugin } from "@elizaos/plugin-sui";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
Expand Down Expand Up @@ -637,6 +638,7 @@ export async function createAgent(
getSecret(character, "SOLANA_PRIVATE_KEY")
? solanaAgentkitPlguin
: null,
getSecret(character, "AUTONOME_JWT_TOKEN") ? autonomePlugin : null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
getSecret(character, "NEAR_WALLET_SECRET_KEY")
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-autonome/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
3 changes: 3 additions & 0 deletions packages/plugin-autonome/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
24 changes: 24 additions & 0 deletions packages/plugin-autonome/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@elizaos/plugin-autonome",
"version": "0.1.7-alpha.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@coral-xyz/anchor": "0.30.1",
"@elizaos/core": "workspace:*",
"@elizaos/plugin-tee": "workspace:*",
"@elizaos/plugin-trustdb": "workspace:*",
"axios": "^1.7.9"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "vitest run"
},
"peerDependencies": {
"form-data": "4.0.1",
"whatwg-url": "7.1.0"
}
}
172 changes: 172 additions & 0 deletions packages/plugin-autonome/src/actions/launchAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import axios from "axios";
import {
ActionExample,
composeContext,
Content,
elizaLogger,
generateObjectDeprecated,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
State,
type Action,
} from "@elizaos/core";

export interface LaunchAgentContent extends Content {
name: string;
config: string;
}

function isLaunchAgentContent(content: any): content is LaunchAgentContent {
elizaLogger.log("Content for launchAgent", content);
return typeof content.name === "string" && typeof content.config === "string";
}

const launchTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
Example response:
\`\`\`json
{
"name": "xiaohuo",
}
\`\`\`
{{recentMessages}}
Given the recent messages, extract the following information about the requested agent launch:
- Agent name
- Character json config
`;

export default {
name: "LAUNCH_AGENT",
similes: ["CREATE_AGENT", "DEPLOY_AGENT", "DEPLOY_ELIZA", "DEPLOY_BOT"],
validate: async (runtime: IAgentRuntime, message: Memory) => {
return true;
},
description: "Launch an Eliza agent",
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
_options: { [key: string]: unknown },
callback?: HandlerCallback
): Promise<boolean> => {
elizaLogger.log("Starting LAUNCH_AGENT handler...");
// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

// Compose launch context
const launchContext = composeContext({
state,
template: launchTemplate,
});

// Generate launch content
const content = await generateObjectDeprecated({
runtime,
context: launchContext,
modelClass: ModelClass.LARGE,
});

// Validate launch content
if (!isLaunchAgentContent(content)) {
elizaLogger.error("Invalid launch content", content);
if (callback) {
callback({
text: "Unable to process launch agent request. Invalid content provided.",
content: { error: "Invalid launch agent content" },
});
}
return false;
}

const autonomeJwt = runtime.getSetting("AUTONOME_JWT_TOKEN");
const autonomeRpc = runtime.getSetting("AUTONOME_RPC");

const requestBody = {
name: content.name,
config: content.config,
creationMethod: 2,
envList: {},
templateId: "Eliza",

const sendPostRequest = async () => {
try {
const response = await axios.post(autonomeRpc, requestBody, {
headers: {
Authorization: `Bearer ${autonomeJwt}`,
"Content-Type": "application/json",
},
});
return response;
} catch (error) {
console.error("Error making RPC call:", error);
}
};

try {
const resp = await sendPostRequest();
if (resp && resp.data && resp.data.app && resp.data.app.id) {
elizaLogger.log(
"Launching successful, please find your agent on"
);
elizaLogger.log(
"https://dev.autonome.fun/autonome/" +
resp.data.app.id +
"/details"
);
}
if (callback) {
callback({
text: `Successfully launch agent ${content.name}`,
content: {
success: true,
appId:
"https://dev.autonome.fun/autonome/" +
resp.data.app.id +
"/details",
},
});
}
return true;
} catch (error) {
if (callback) {
elizaLogger.error("Error during launching agent");
elizaLogger.error(error);
callback({
text: `Error launching agent: ${error.message}`,
content: { error: error.message },
});
}
}
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Launch an agent, name is xiaohuo",
},
},
{
user: "{{user2}}",
content: {
text: "I'll launch the agent now...",
action: "LAUNCH_AGENT",
},
},
{
user: "{{user2}}",
content: {
text: "Successfully launch agent, id is ba2e8369-e256-4a0d-9f90-9c64e306dc9f",
},
},
],
] as ActionExample[][],
} as Action;
12 changes: 12 additions & 0 deletions packages/plugin-autonome/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Plugin } from "@elizaos/core";
import launchAgent from "./actions/launchAgent";

export const autonomePlugin: Plugin = {
name: "autonome",
description: "Autonome Plugin for Eliza",
actions: [launchAgent],
evaluators: [],
providers: [],
};

export default autonomePlugin;
10 changes: 10 additions & 0 deletions packages/plugin-autonome/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src/**/*.ts"
]
}
29 changes: 29 additions & 0 deletions packages/plugin-autonome/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts"],
outDir: "dist",
sourcemap: true,
clean: true,
format: ["esm"], // Ensure you're targeting CommonJS
external: [
"dotenv", // Externalize dotenv to prevent bundling
"fs", // Externalize fs to use Node.js built-in module
"path", // Externalize other built-ins if necessary
"@reflink/reflink",
"@node-llama-cpp",
"https",
"http",
"agentkeepalive",
"safe-buffer",
"base-x",
"bs58",
"borsh",
"@solana/buffer-layout",
"stream",
"buffer",
"querystring",
"amqplib",
// Add other modules you want to externalize
],
});
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1b7c80

Please sign in to comment.