-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat!: agent module registration api #955
feat!: agent module registration api #955
Conversation
Codecov Report
@@ Coverage Diff @@
## 0.3.0-pre #955 +/- ##
=============================================
+ Coverage 88.20% 88.23% +0.03%
=============================================
Files 636 637 +1
Lines 15036 15092 +56
Branches 2536 2542 +6
=============================================
+ Hits 13262 13316 +54
- Misses 1676 1678 +2
Partials 98 98
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Nice job @TimoGlastra! My only remark here is that the |
Yeah have been thinking about using module, but that also didn't fully make sense to me. It only exposes the api of the module, not the whole module object (so |
Haha fair, this is a very semantic thingy. My thought here is this: as a user I will pass modules to the agent constructor. Therefore, I already know that a module adds certain functionality. However, I might not be familiar with the internal structure of modules, so I might not be aware of the concept of Since I'm passing modules, I wouldn't be surprised to have to access their APIs through Anyway, just my thought! I try to think about these things as an outsider, not a framework developer. |
Input from WG call:
I think I agree with the |
I am slightly in favour of the top-level modules and custom modules defined in Keeping the core-defined modules top level, which in the end might not be a lot, makes a cleaner API. Having said that, doing I am fine with either for different reasons. Maybe we can look at different frameworks and how they solved this issue? |
I thought about this issue a bit more, and it might not be such a big issue to have breaking changes when we add new modules into core. Adding a module into core, after modularisation, is very unlikely to happen when we have the did core modules in there. Unless they expand their spec or we want add seperation, we would not have the add any modules. Of course, it might happen and bundling it with some other breaking changes would be fine IMHO. Also, as we mentioned in the last WG call, the |
Well we need to change the call to Agent.create (or something like that such as a separate method I'll go with the top level approach then! |
I don't see any problem on using an agent creator method, especially considering that we currently need to call A question that arises from this approach is if there would be a chance of overriding a core module. We currently do so with connections module to add some project-specific capabilities (we sub-class |
I think Also, again not a massive fan of bloating the config, but adding a value to the config with
It would be possible to override a core module. const agent = Agent.create({
config: { /* agent config */ },
modules: {
CORE_MODULE: new CORE_MODULE({config: 'yes'}), // CORE_MODULE is a core module and here we can define a new one.
},
dependencies: agentDependencies,
}) |
Yes as berend mentioned it would be possible to override the core module by providing it in the agent config, however the typing is currently set to only allow the same module. You would have to write your |
Certainly, if it can accept the same interface (or an extension of it) it would be great to allow these 'tuned core modules'. Of course there is no problem on using other keys, but if I expose Anyway, there are some tricks in TypeScript that allow hiding some keys from superclasses, and for sure it's possible to think things differently for using different keys in an elegant way, so it's not a big deal if this idea gets too complicated. Just a 'nice to have' from my point of view. |
f2e61d8
to
f38ac05
Compare
BREAKING CHANGE: all modules have been moved to the .api namespace. Instead of using agent.xxx (e.g. agent.oob) you should now call agent.api.oob instead. In addition the agent constructor has been updated to a single options object that contains the `config` and `dependencies` properties. Instead of constructing the agent like this: ```ts const agent = new Agent({ /* config */ }, agentDependencies) ``` You should now construct it like this: ```ts const agent = new Agent({ config: { /* config */ }, dependencies: agentDependencies }) ``` This is to alow for the new custom modules that can be befined in the agent constructor. ` Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
4dde7b0
to
2b4a740
Compare
I think it's doable, but maybe for a future PR. This can be added as a non-breaking change, so we could maybe push it to 0.3.1 |
This PR is now updated and should be ready to merge. I've updated the description of the PR but it boils down to:
I think this is one of the blockers for the 0.3.0 release, so let's get this merged :) |
Signed-off-by: Timo Glastra <[email protected]>
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.
Great! Really love this new module registration API. There are still some doubts to solve in the path of AFJ modularization, but certainly this is an excellent step forward to reach it.
Note: there are a few warnings from GitHub Actions validation
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]>
Signed-off-by: Timo Glastra <[email protected]> BREAKING CHANGE: custom modules have been moved to the .modules namespace. In addition the agent constructor has been updated to a single options object that contains the `config` and `dependencies` properties. Instead of constructing the agent like this: ```ts const agent = new Agent({ /* config */ }, agentDependencies) ``` You should now construct it like this: ```ts const agent = new Agent({ config: { /* config */ }, dependencies: agentDependencies }) ``` This allows for the new custom modules to be defined in the agent constructor. Signed-off-by: Ariel Gentile <[email protected]>
Signed-off-by: Timo Glastra [email protected]
Add agent module registration api. With this you can now register custom modules on the agent like this:
This will register the tenants module and make the tenants api available. There's some nice typescript magic going on here that automatically infers the api type from the tenants module, allowing the agent to be fully typed with custom modules:
As you may have already noticed from the example above, all the custom module api's are now nested under the
agent.modules
property. I've taken this approach for two reasons:You can define the api for a module using the api key on a module:
All modules that were registered by default on the agent are still registered by default. So
agent.oob
is present, as well asagent.connections
, etc... For now the default modules are still initialized based on the configuration in the agent config, but in a next PR I'll remove that logic and you will only be able to configure modules using the module config itself. If you want to provide custom configuration for a default module you can do so by registering the module. This will just register the module with you custom config, instead of using the default config:BREAKING CHANGE: custom modules have been moved to the .modules namespace. In addition the agent constructor has been updated to a single options object that contains the
config
anddependencies
properties. Instead of constructing the agent like this:You should now construct it like this:
This allows for the new custom modules to be defined in the agent constructor.