refactor: decouple Source from Tool#2204
Conversation
Summary of ChangesHello @Yuan325, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the interaction between 'Source' and 'Tool' components by decoupling their direct dependencies. The change moves from static linking to dynamic retrieval of 'Source' instances during 'Tool' invocation, ensuring that tools always use up-to-date source configurations. This is achieved through a new 'compatibleSource' interface for validation and updates to authorization-related method signatures to support this dynamic interaction model. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant refactoring to decouple Source from Tool. The approach of using a compatibleSource interface and dynamically resolving the source at runtime is well-implemented and consistently applied across the codebase. This change will improve the system's flexibility, allowing for source configurations to be updated without re-initializing tools. My review includes one suggestion to reduce code duplication in error handling within the MCP handlers, which would further enhance maintainability.
c5a294e to
cb27866
Compare
## Description Add error to return of `RequiresClientAuthorization()` function. The function will run `resourceMgr.GetSource(t.SourceName)` before checking for source's oauth setting. With this, it will return an error if the retrieval is not successful. In that case, we would want to return an error from `RequiresClientAuthorization()`. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [x] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
…ig from tool (#2061) ## Description Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…ool (#2059) ## Description Decouple source config from tools. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
…onfig from tools (#2062) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…s/elasticsearch,tools/firebird): decouple source config from tools (#2064) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…le source config from tools (#2065) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…source config from tools (#2067) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…/spanner): decouple source config from tools (#2068) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
…tools/yugabytedbsql): decouple source config from tools (#2070) Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.
## Description Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
Update `Authorized()` function in all tools to take a new input parameter -- resourceManager. This was updated for looker tool previously since that tool require access to the source. When running lint and unit tests, this PR also updates the following: * Remove unit tests that checks for Source compatibility or missing Source during initialization. These tests are not relevant since most of the tools only check for source compatibility when it is needed (e.g. during `Invoke()`) * Update sources configs to be exported (specifically alloydbadmin and cloudsqladmin).
Added a generic `GetCompatibleSource()` in tools.go.
rebase `config-branch` to `main` and update newly added tools. Also resolve merge conflicts.
update integration tests with the decoupling of source from tool.
ff4151a to
5e4a5b0
Compare
This PR update the linking mechanism between Source and Tool.
Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.
Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
Client() http.Client
ProjectID() string
}
```
During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.
With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`). 967a72d
This PR update the linking mechanism between Source and Tool.
Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.
Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
Client() http.Client
ProjectID() string
}
```
During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.
With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`). 967a72d
This PR update the linking mechanism between Source and Tool.
Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.
Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
Client() http.Client
ProjectID() string
}
```
During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.
With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`).
This PR update the linking mechanism between Source and Tool.
Tools are directly linked to their Source, either by pointing to the Source's functions or by assigning values from the source during Tool's initialization. However, the existing approach means that any modification to the Source after Tool's initialization might not be reflected. To address this limitation, each tool should only store a name reference to the Source, rather than direct link or assigned values.
Tools will provide interface for
compatibleSource. This will be used to determine if a Source is compatible with the Tool.During
Invoke(), the tool will run the following operations:resourceManagerwith source's named defined in Tool's configcompatibleSource interface{}Invoke()function. Fields that are needed is retrieved directly from the source.With this update, resource manager is also added as input to other Tool's function that require access to source (e.g.
RequiresClientAuthorization()).