-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support autonome platform (#2121)
* 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
1 parent
4df0e5b
commit e1b7c80
Showing
11 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* | ||
|
||
!dist/** | ||
!package.json | ||
!readme.md | ||
!tsup.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
], | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.