Skip to content

Commit 84b287f

Browse files
committed
fix(tool): fix mypy errors using cast and schema corrections
1 parent 9cb3dbf commit 84b287f

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

packages/toolbox-adk/src/toolbox_adk/tool.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Awaitable, Callable, Dict, Optional
15+
from typing import Any, Awaitable, Callable, Dict, Optional, cast
1616

1717
import toolbox_core
1818
from fastapi.openapi.models import (
@@ -127,38 +127,28 @@ async def run_async(
127127
oauth2=OAuth2Auth(
128128
client_id=self._auth_config.client_id,
129129
client_secret=self._auth_config.client_secret,
130-
scopes=scopes,
131130
),
132131
),
133132
)
134133

135134
# Check if we already have credentials from a previous exchange
136135
try:
137136
# get_auth_response returns AuthCredential if found
138-
creds = tool_context.get_auth_response(auth_config_adk)
137+
ctx_any = cast(Any, tool_context)
138+
creds = ctx_any.get_auth_response(auth_config_adk)
139139
if creds and creds.oauth2 and creds.oauth2.access_token:
140140
reset_token = USER_TOKEN_CONTEXT_VAR.set(creds.oauth2.access_token)
141141
else:
142-
# Request credentials. This will signal the runner to pause.
143-
# We return None (or raise) to stop current execution.
144-
tool_context.request_credential(auth_config_adk)
145-
# Returning None here. The ADK runner will see the requested_auth_configs
146-
# in the tool_context/event and trigger the client event.
142+
# Request credentials and pause execution
143+
ctx_any.request_credential(auth_config_adk)
147144
return None
148145
except Exception as e:
149-
# If get_auth_response fails drastically or request_credential fails
150146
ctx.error = e
151-
# We might want to request credential if retrieval failed?
152-
# For now let's assume if it fails we can't proceed.
153-
# Actually, strictly we should probably request credential if get_auth_response returns nothing
154-
# but get_auth_response typically handles the lookup.
155-
# If exception is unrelated, raise.
156-
if "credential" in str(e).lower() or isinstance(
157-
e, ValueError
158-
): # Loose check, but safest is to re-raise
147+
if "credential" in str(e).lower() or isinstance(e, ValueError):
159148
raise e
160-
# Fallback to request logic if it was a lookup error?
161-
tool_context.request_credential(auth_config_adk)
149+
# Fallback to request logic
150+
ctx_any = cast(Any, tool_context)
151+
ctx_any.request_credential(auth_config_adk)
162152
return None
163153

164154
try:

packages/toolbox-adk/src/toolbox_adk/toolset.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
bound_params: Optional[Mapping[str, Union[Callable[[], Any], Any]]] = None,
4242
pre_hook: Optional[Callable[[ToolboxContext], Awaitable[None]]] = None,
4343
post_hook: Optional[Callable[[ToolboxContext], Awaitable[None]]] = None,
44-
**kwargs,
44+
**kwargs: Any,
4545
):
4646
"""
4747
Args:
@@ -72,13 +72,7 @@ async def get_tools(
7272
self, readonly_context: Optional[ReadonlyContext] = None
7373
) -> List[BaseTool]:
7474
"""Loads tools from the toolbox server and wraps them."""
75-
# Note: We don't close the client after get_tools because tools might need it
76-
# (though currently tools are self-contained http-wise if they don't share session state).
77-
# Actually toolbox-core tools have their own client reference or use a shared one?
78-
# toolbox_core.ToolboxClient.load_tool returns a tool which...
79-
# wait, toolbox_core tools make HTTP calls. Do they hold a reference to the client session?
80-
# Yes, toolbox_core 0.1.0+ tools usually have an internal `client` or `session`.
81-
# So we must keep self._client alive or ensuring it's not closed prematurely.
75+
# Note: We don't close the client after get_tools because tools might need it.
8276

8377
tools = []
8478
if self._toolset_name:

0 commit comments

Comments
 (0)