-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: dynamic plugin imports #1383
base: develop
Are you sure you want to change the base?
chore: dynamic plugin imports #1383
Conversation
P.S. - seems like passed all tests, omg, nice... just noticed could do same for all client packages: if we like this change, ill do another PR for dynamic client imports too, massive optz. |
hmmm avaer told me that "alot of wrappings" I can make better abstraction for loading dynamic imports... I'll work on. Like a function for it instead. Bit complex because of all the diff conditionals / import styles / 1 is a default import. I'll see if can do nicely. |
done, now have |
Why do it like this? Why not pass a callback to loadPlugin that is |
The probably is the public api is purely string base its not type safe where as if you do callback import and you don't have the dependency installed, typescript will not compile it. |
Probably need to update Line 45 in 4c658d7
for future plugin devs |
OK yeah callback param is better, I'll update. |
changed to callback params: 2efee64 |
This doesn't work your IMO the correct approach would be something as follows.
export type DynamicPlugin = {
readonly factory: () => Promise<Plugin>;
readonly shouldInit: (character: Character) => boolean;
};
|
I see, more complex with types then I originally thought, will think about / work on, thanks for feedback. |
Actually I stand mistaken since there is a |
Few more comments.
|
(found issues in Plugin types)
OK strictly type loadPlugins with Plugin + mod style, this works and is type compliant however we now have 3 plugins not correctly typed to Plugin that were hidden found: @elizaos/plugin-solana This is bigger PR to fix all plugins now, was never type safe to begin with tbh. |
Have you run |
ah, fixed, OK everything compiling / working great. Gonna work on: 1.) export the loadPlugin function to cleanup and ready for review / testing. thanks for help! TS god |
+ new dev.sh instructions
I went big boy AAA on this one: I think this proper now. ready for review kind citizen. |
agent/src/index.ts
Outdated
importFn: () => | ||
import("@elizaos/plugin-coinbase").then( | ||
(m) => m.coinbaseMassPaymentsPlugin | ||
), | ||
}, | ||
{ | ||
secrets: ["COINBASE_API_KEY", "COINBASE_PRIVATE_KEY"], | ||
importFn: () => | ||
import("@elizaos/plugin-coinbase").then((m) => m.tradePlugin), | ||
}, | ||
{ | ||
secrets: ["COINBASE_API_KEY", "COINBASE_PRIVATE_KEY"], | ||
importFn: () => | ||
import("@elizaos/plugin-coinbase").then( | ||
(m) => m.tokenContractPlugin | ||
), | ||
}, | ||
{ | ||
secrets: ["COINBASE_API_KEY", "COINBASE_PRIVATE_KEY"], | ||
importFn: () => | ||
import("@elizaos/plugin-coinbase").then( | ||
(m) => m.advancedTradePlugin | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking a helper function (my idea of load plugins) which is just import('@elizaos/plugin-coinbase').then((mod) => [mod.pluginA, modPluginB, modPluginC])
. Then we don't need to import coinbase 3 times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then to add them you can just spread:
plugins: [
...myCoinbasePluginsDynamicallyImportedOrNull
].filter(Boolean)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok this final point I think, taking break, will work on that, we getting close 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved importCache I believe: 32c7e5a
Main issue was handling unique secrets, I do like the simple statements of secrets
and importFn
, now if duplicate importFn, it uses a cache, so won't import duplicates, but DX is much nicer else would have big nested ternaries and if/else stuffed in array with secrets spread.
If have better style lemme know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case that secrets are exact same, uses your suggestion, as array to import: 430dab1
But case still stands I think best separated if secrets are unique, for webhook, and others.
https://github.com/elizaOS/eliza/pull/1383/files#diff-935219608f7b5ca6c8b8548cfdce88c7d3cdb6bb6d9f9d8df644b364f6557e4eR437-R462
Relates to:
None, just looking for improvements.
Risks
HIGH - could break plugins
Background
Plugins even if unused are being always imported into the agent/index.ts at top of file.
This adds much memory usage to the JS runtime and not most efficient way to load optional plugins.
What does this PR do?
Dynamically imports plugins when needed based on ENV / secrets loaded.
What kind of change is this?
Improvements (misc. changes to existing features)
Why are we doing this? Any context or related work?
Makes Eliza faster / slimmer / less bloated / scales infinite plugins with minimal runtime overhead.
Documentation changes needed?
My changes do not require a change to the project documentation.
Testing
Try out different combinations of plugins off and on, see if loads or breaks.
Discord username
cjft