-
Notifications
You must be signed in to change notification settings - Fork 5
add Google ADK support #34
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
Conversation
WalkthroughThe changes introduce a new example demonstrating the integration of thirdweb-ai blockchain tools with Google ADK agents. This includes a Python example script, a README, and a dedicated Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ExampleScript
participant ThirdwebInsight
participant GoogleADKAgent
User->>ExampleScript: Run example.py with query
ExampleScript->>ThirdwebInsight: Initialize client and tools
ExampleScript->>GoogleADKAgent: Setup agent with wrapped tools
ExampleScript->>GoogleADKAgent: Send user query
GoogleADKAgent->>ThirdwebInsight: Use Insight tool for blockchain data
ThirdwebInsight-->>GoogleADKAgent: Return query result
GoogleADKAgent-->>ExampleScript: Return response
ExampleScript-->>User: Print final response
sequenceDiagram
participant ExampleScript
participant GoogleADKAdapter
participant ThirdwebTool
participant GoogleADKTool
ExampleScript->>GoogleADKAdapter: get_google_adk_tools([ThirdwebTool])
GoogleADKAdapter->>ThirdwebTool: Wrap as GoogleADKTool
GoogleADKAdapter-->>ExampleScript: Return [GoogleADKTool]
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Actionable comments posted: 4
🧹 Nitpick comments (8)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (3)
1-1
: Remove unused importsThe
typing.Dict
import is unused and is also deprecated in favor of using the built-indict
type annotation.-from typing import Any, Dict +from typing import Any🧰 Tools
🪛 Ruff (0.11.9)
1-1:
typing.Dict
is deprecated, usedict
instead(UP035)
1-1:
typing.Dict
imported but unusedRemove unused import:
typing.Dict
(F401)
3-3
: Remove unused importThe
ToolUnion
import is not used in this code.-from google.adk.agents.llm_agent import ToolUnion
🧰 Tools
🪛 Ruff (0.11.9)
3-3:
google.adk.agents.llm_agent.ToolUnion
imported but unusedRemove unused import:
google.adk.agents.llm_agent.ToolUnion
(F401)
11-21
: Add type hints for the wrapped tool parameterThe
WrappedTool
initializer should use explicit type annotations for thetool
parameter to improve code maintainability.class WrappedTool(BaseTool): - def __init__(self, tool: Tool): + def __init__(self, tool: Tool) -> None: self.tool = tool super().__init__( name=tool.name, description=tool.description, ) - async def run(self, args: BaseModel) -> Any: + async def run(self, args: BaseModel) -> Any: return self.tool.run_async(args.model_dump())python/examples/adapter_google_adk/README.md (2)
25-28
: Consider security implications when showing API key examplesWhile it's common to show environment variable setup, consider adding a note about keeping API keys secure and not hardcoding them in production code.
export THIRDWEB_SECRET_KEY=your_api_key_here +# Note: Always keep your API keys secure and never commit them to version control
47-50
: README could benefit from more specific informationThe requirements section could be more specific by mentioning key dependencies directly in the README, with approximate version ranges, rather than only referring to the pyproject.toml file.
## Requirements -See `pyproject.toml` for the full list of dependencies. +Key dependencies: +- Python 3.10+ +- thirdweb-ai with google-adk extras +- google-adk + +See `pyproject.toml` for the complete list of dependencies and version requirements.python/examples/adapter_google_adk/example.py (3)
13-17
: Consider moving constants to a config file for larger applicationsFor this example, hardcoding APP_NAME, USER_ID, and SESSION_ID is fine, but for production code, consider adding a comment suggesting these would typically come from configuration or user input.
# Example app configuration APP_NAME = "thirdweb_insight_app" USER_ID = "test_user" SESSION_ID = "test_session" +# Note: In a production application, these values would typically come from configuration or user input
42-46
: Consider adding model configuration optionsThe agent is hardcoded to use "gpt-4o-mini". For better flexibility, you might want to make this configurable.
+# Model can be customized by passing a different model name +MODEL_NAME = os.getenv("THIRDWEB_MODEL_NAME", "gpt-4o-mini") + agent = LlmAgent( - model=LiteLlm(model="gpt-4o-mini"), + model=LiteLlm(model=MODEL_NAME), name="thirdweb_insight_agent", tools=adk_tools )
1-72
: Function to handle multiple queries would improve exampleFor a more comprehensive example, consider adding a function that can handle multiple queries in sequence, demonstrating how state persists in a session.
+async def run_multiple_queries(queries: list[str]): + """Run multiple queries in sequence, maintaining session state. + + Args: + queries: List of queries to run in sequence + """ + runner = await setup_agent() + + for i, query in enumerate(queries, 1): + print(f"\n--- Query {i}: {query} ---") + content = types.Content(role='user', parts=[types.Part(text=query)]) + events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content) + + for event in events: + if event.is_final_response(): + final_response = event.content.parts[0].text + print(f"Agent Response {i}: {final_response}") + break if __name__ == "__main__": - test_query = "Get details of 0x0cd2de80bb87b327a0e32576ddddc8af6c73d163dca2d00e8777117918e3d056 transaction" - asyncio.run(call_agent(test_query)) + # Option 1: Single query + # test_query = "Get details of 0x0cd2de80bb87b327a0e32576ddddc8af6c73d163dca2d00e8777117918e3d056 transaction" + # asyncio.run(call_agent(test_query)) + + # Option 2: Multiple queries demonstrating session persistence + test_queries = [ + "Get details of 0x0cd2de80bb87b327a0e32576ddddc8af6c73d163dca2d00e8777117918e3d056 transaction", + "What's the balance of vitalik.eth?", + "Show me recent NFT transfers for this address" + ] + asyncio.run(run_multiple_queries(test_queries))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
python/examples/adapter_google_adk/uv.lock
is excluded by!**/*.lock
📒 Files selected for processing (6)
python/examples/adapter_google_adk/README.md
(1 hunks)python/examples/adapter_google_adk/example.py
(1 hunks)python/examples/adapter_google_adk/pyproject.toml
(1 hunks)python/thirdweb-ai/pyproject.toml
(3 hunks)python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
(1 hunks)python/thirdweb-mcp/pyproject.toml
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (1)
python/thirdweb-ai/src/thirdweb_ai/tools/tool.py (3)
BaseTool
(131-208)Tool
(105-124)tool
(243-264)
python/examples/adapter_google_adk/example.py (3)
python/thirdweb-ai/src/thirdweb_ai/services/insight.py (1)
Insight
(14-411)python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (2)
get_google_adk_tools
(10-22)run
(19-20)python/thirdweb-ai/src/thirdweb_ai/services/nebula.py (1)
create_session
(42-44)
🪛 Ruff (0.11.9)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
1-1: typing.Dict
is deprecated, use dict
instead
(UP035)
1-1: typing.Dict
imported but unused
Remove unused import: typing.Dict
(F401)
3-3: google.adk.agents.llm_agent.ToolUnion
imported but unused
Remove unused import: google.adk.agents.llm_agent.ToolUnion
(F401)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (13)
python/thirdweb-mcp/pyproject.toml (1)
48-49
: LGTM: Dynamic versioning configurationThe added versioning configuration provides flexibility in development by using the base version and supporting development mode through an environment variable.
python/examples/adapter_google_adk/pyproject.toml (1)
1-16
: LGTM: Well-configured example projectThe project configuration is properly set up with appropriate dependencies and Python version requirements for the Google ADK adapter example.
python/thirdweb-ai/pyproject.toml (3)
30-30
: LGTM: Google ADK dependency added to 'all' groupCorrectly added Google ADK to the 'all' optional dependencies group.
41-41
: LGTM: Google ADK optional dependency groupGood implementation of the new Google ADK optional dependency group with appropriate version constraints for both Google ADK and litellm.
89-90
: LGTM: Dynamic versioning configurationThe added versioning configuration aligns with the changes made in the MCP project file, providing consistency across the projects.
python/examples/adapter_google_adk/README.md (3)
3-9
: Great introduction to the integration!The overview clearly explains the purpose of this example and provides good context on how thirdweb-ai's blockchain tooling works with Google's AutoGen framework.
35-39
: Examples are clear and relevantThe bullet points describing what the agent can do provide clear expectations for users.
40-46
: Customization options are helpfulThese customization instructions provide good guidance for users who want to extend the example.
python/examples/adapter_google_adk/example.py (5)
1-12
: Imports are well organized and comprehensiveThe imports are logically grouped and include all necessary components for Google ADK integration.
19-29
: Environment variable validation is implemented correctlyGood error handling for the required THIRDWEB_SECRET_KEY environment variable.
30-41
: Tool initialization and debugging info is helpfulThe code effectively initializes Insight tools and converts them to Google ADK format. The debugging print statements are useful for developers to understand available tools.
48-54
: Session management implementation is goodThe session setup is implemented correctly, using the InMemorySessionService which is appropriate for this example.
69-71
: Test query is appropriately specificThe test query is a good concrete example that demonstrates how to use the agent with a specific blockchain transaction hash.
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
Outdated
Show resolved
Hide resolved
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 0
♻️ Duplicate comments (1)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (1)
53-61
: Add error handling and improve documentation.The
run_async
method doesn't include error handling for therun_json
call, and the documentation doesn't mention thetool_context
parameter.async def run_async(self, args: dict[str, Any], tool_context: ToolContext) -> Any: """Execute the tool asynchronously. This method adapts the Thirdweb tool to work with Google ADK's async execution. + Args: + args: The arguments to pass to the tool + tool_context: The context for tool execution Returns: The result of running the tool """ - return self.tool.run_json(args) + try: + return self.tool.run_json(args) + except Exception as e: + # Log and rethrow or handle appropriately + raise RuntimeError(f"Error executing tool {self.name}: {str(e)}") from e
🧹 Nitpick comments (2)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (2)
8-8
: Remove unused import.The
BaseModel
import from pydantic is not used in this file.-from pydantic import BaseModel
🧰 Tools
🪛 Ruff (0.11.9)
8-8:
pydantic.BaseModel
imported but unusedRemove unused import:
pydantic.BaseModel
(F401)
43-44
: Add safety check before deleting key.The code deletes
additionalProperties
without checking if it exists, which could lead to aKeyError
if the key isn't present in the parameters dictionary.- parameters = self.tool.schema["parameters"] - del parameters["additionalProperties"] + parameters = self.tool.schema["parameters"].copy() + if "additionalProperties" in parameters: + del parameters["additionalProperties"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
python/examples/adapter_google_adk/README.md
(1 hunks)python/examples/adapter_google_adk/example.py
(1 hunks)python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- python/examples/adapter_google_adk/README.md
- python/examples/adapter_google_adk/example.py
🧰 Additional context used
🪛 Ruff (0.11.9)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
8-8: pydantic.BaseModel
imported but unused
Remove unused import: pydantic.BaseModel
(F401)
🔇 Additional comments (1)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (1)
10-74
: Well-structured adapter implementation.The adapter pattern is well-implemented here, providing a clean interface between thirdweb tools and Google ADK. The code properly wraps the thirdweb Tool and adapts its interface to the Google ADK requirements.
Summary by CodeRabbit
New Features
Documentation
Chores