Skip to content

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

Merged
merged 7 commits into from
May 21, 2025
Merged

add Google ADK support #34

merged 7 commits into from
May 21, 2025

Conversation

cjber
Copy link
Contributor

@cjber cjber commented May 21, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an example demonstrating integration of blockchain AI tools with Google ADK agents, including setup and usage instructions.
    • Added a script to showcase running AI-powered blockchain queries using Google ADK agents.
    • Enabled interoperability between blockchain AI tools and Google ADK agents.
  • Documentation

    • Added a comprehensive README with installation, usage, and customization guidance for the new example.
  • Chores

    • Updated project configuration files to include new dependencies and versioning options for Google ADK integration.
    • Removed obsolete version file to streamline version management.

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

The 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 pyproject.toml for dependencies. Additionally, a new adapter module enables thirdweb-ai tools to interoperate with Google ADK. Project-level pyproject.toml files are updated to support the new integration and dynamic versioning.

Changes

File(s) Change Summary
python/examples/adapter_google_adk/README.md Added a README explaining the integration example, setup, usage, and customization instructions.
python/examples/adapter_google_adk/example.py New Python script demonstrating setup and usage of a Google ADK agent with thirdweb-ai Insight tools, including async agent execution.
python/examples/adapter_google_adk/pyproject.toml Added project configuration specifying dependencies for thirdweb-ai with Google ADK support and build metadata.
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py New module providing a function to wrap thirdweb-ai tools as Google ADK-compatible tools.
python/thirdweb-ai/pyproject.toml
python/thirdweb-mcp/pyproject.toml
Updated dynamic versioning configuration; added optional dependency group for Google ADK integration in thirdweb-ai.
python/thirdweb-ai/src/thirdweb_ai/_version.py Removed version definition file containing a static version string.

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
Loading
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]
Loading

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit 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.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit 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 Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented May 21, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedlitellm@​1.70.27510010010080

View full report

Copy link

@coderabbitai coderabbitai bot left a 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 imports

The typing.Dict import is unused and is also deprecated in favor of using the built-in dict type annotation.

-from typing import Any, Dict
+from typing import Any
🧰 Tools
🪛 Ruff (0.11.9)

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: Remove unused import

The 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 unused

Remove unused import: google.adk.agents.llm_agent.ToolUnion

(F401)


11-21: Add type hints for the wrapped tool parameter

The WrappedTool initializer should use explicit type annotations for the tool 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 examples

While 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 information

The 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 applications

For 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 options

The 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 example

For 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

📥 Commits

Reviewing files that changed from the base of the PR and between bd14f35 and c213bca.

⛔ 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 configuration

The 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 project

The 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' group

Correctly added Google ADK to the 'all' optional dependencies group.


41-41: LGTM: Google ADK optional dependency group

Good implementation of the new Google ADK optional dependency group with appropriate version constraints for both Google ADK and litellm.


89-90: LGTM: Dynamic versioning configuration

The 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 relevant

The bullet points describing what the agent can do provide clear expectations for users.


40-46: Customization options are helpful

These 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 comprehensive

The imports are logically grouped and include all necessary components for Google ADK integration.


19-29: Environment variable validation is implemented correctly

Good error handling for the required THIRDWEB_SECRET_KEY environment variable.


30-41: Tool initialization and debugging info is helpful

The 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 good

The session setup is implemented correctly, using the InMemorySessionService which is appropriate for this example.


69-71: Test query is appropriately specific

The test query is a good concrete example that demonstrates how to use the agent with a specific blockchain transaction hash.

Copy link

@coderabbitai coderabbitai bot left a 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 the run_json call, and the documentation doesn't mention the tool_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 unused

Remove 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 a KeyError 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

📥 Commits

Reviewing files that changed from the base of the PR and between e916df0 and 6bbb1ed.

📒 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.

@cjber cjber merged commit 9fe000a into main May 21, 2025
3 checks passed
@cjber cjber deleted the cb/google-adk branch May 21, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant