Skip to content

Commit 6bbb1ed

Browse files
committed
fix args
1 parent e916df0 commit 6bbb1ed

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

python/examples/adapter_google_adk/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ First, ensure you have Python 3.10+ installed. Then install the required package
1212

1313
```bash
1414
# Using pip
15-
pip install "thirdweb-ai[autogen]"
15+
pip install "thirdweb-ai[google-adk]"
1616

1717
# Using uv
18-
uv add "thirdweb-ai[autogen]"
18+
uv add "thirdweb-ai[google-adk]"
1919
```
2020

2121
## Usage

python/examples/adapter_google_adk/example.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ async def setup_agent() -> Runner:
3939
for tool_count, tool in enumerate(adk_tools, start=1):
4040
print(f"- Tool #{tool_count} {tool.name}")
4141

42+
# Create the agent with the tools
4243
agent = LlmAgent(
43-
model=LiteLlm(model="gpt-4o-mini"),
44-
name="thirdweb_insight_agent",
45-
tools=adk_tools
44+
model=LiteLlm(model="gpt-4o-mini"),
45+
name="thirdweb_insight_agent",
46+
# Convert BaseTool to the expected type for LlmAgent
47+
tools=adk_tools, # type: ignore
4648
)
4749

4850
# Set up session
@@ -54,18 +56,26 @@ async def setup_agent() -> Runner:
5456
return Runner(agent=agent, app_name=APP_NAME, session_service=session_service)
5557

5658

57-
async def call_agent(query):
59+
async def call_agent(query: str) -> None:
60+
"""Run a query through the agent.
61+
62+
Args:
63+
query: The query to send to the agent
64+
"""
5865
runner = await setup_agent()
59-
content = types.Content(role='user', parts=[types.Part(text=query)])
66+
content = types.Content(role="user", parts=[types.Part(text=query)])
6067
events = runner.run(user_id=USER_ID, session_id=SESSION_ID, new_message=content)
6168

6269
for event in events:
63-
if event.is_final_response():
70+
if (
71+
hasattr(event, "is_final_response")
72+
and event.is_final_response()
73+
and (event.content and hasattr(event.content, "parts") and event.content.parts)
74+
):
6475
final_response = event.content.parts[0].text
6576
print("Agent Response: ", final_response)
6677

6778

68-
6979
if __name__ == "__main__":
70-
test_query = "Get details of 0x0cd2de80bb87b327a0e32576ddddc8af6c73d163dca2d00e8777117918e3d056 transaction"
80+
test_query = "Find information on transaction: 0x45027cce9d2b990349b4a1e015ec29ca7c7ef15d82487d898f24866a09e8b84c."
7181
asyncio.run(call_agent(test_query))
Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,73 @@
1-
from typing import Any, Dict
1+
from typing import Any
2+
3+
from google.adk.tools import BaseTool, ToolContext
4+
from google.genai import types
5+
6+
from thirdweb_ai.tools.tool import Tool, ToolSchema
27

3-
from google.adk.agents.llm_agent import ToolUnion
4-
from google.adk.tools import BaseTool
58
from pydantic import BaseModel
69

7-
from thirdweb_ai import Tool
10+
class GoogleAdkTool(BaseTool):
11+
"""Adapter for Thirdweb Tool to Google ADK BaseTool.
12+
13+
This allows Thirdweb tools to be used with Google ADK agents.
14+
"""
15+
16+
def __init__(self, tool: Tool):
17+
"""Initialize the Google ADK Tool wrapper.
18+
19+
Args:
20+
tool: The Thirdweb Tool to wrap
21+
"""
22+
self.tool = tool
23+
super().__init__(
24+
name=tool.name,
25+
description=tool.description,
26+
)
27+
28+
@property
29+
def schema(self) -> ToolSchema:
30+
"""Return the schema for the tool.
31+
32+
Returns:
33+
The schema for the function declaration
34+
"""
35+
return self.tool.schema
36+
37+
def _get_declaration(self) -> types.FunctionDeclaration:
38+
"""Generate the function declaration for Google ADK.
39+
40+
Returns:
41+
A FunctionDeclaration for Google ADK
42+
"""
43+
parameters = self.tool.schema["parameters"]
44+
del parameters["additionalProperties"]
45+
return types.FunctionDeclaration(
46+
name=self.name,
47+
description=self.description,
48+
parameters=parameters,
49+
)
50+
51+
# Override the method with the expected signature based on the error message
52+
# and adapting from the reference implementation
53+
async def run_async(self, args: dict[str, Any], tool_context: ToolContext) -> Any:
54+
"""Execute the tool asynchronously.
55+
56+
This method adapts the Thirdweb tool to work with Google ADK's async execution.
57+
58+
Returns:
59+
The result of running the tool
60+
"""
61+
return self.tool.run_json(args)
862

963

1064
def get_google_adk_tools(tools: list[Tool]) -> list[BaseTool]:
11-
class WrappedTool(BaseTool):
12-
def __init__(self, tool: Tool):
13-
self.tool = tool
14-
super().__init__(
15-
name=tool.name,
16-
description=tool.description,
17-
)
18-
19-
async def run(self, args: BaseModel) -> Any:
20-
return self.tool.run_async(args.model_dump())
21-
22-
return [WrappedTool(tool) for tool in tools]
65+
"""Convert Thirdweb tools to Google ADK tools.
66+
67+
Args:
68+
tools: List of Thirdweb tools to convert
69+
70+
Returns:
71+
List of Google ADK tools
72+
"""
73+
return [GoogleAdkTool(tool) for tool in tools]

0 commit comments

Comments
 (0)