Skip to content

Commit d55ad50

Browse files
authored
feat(web_search): enhance web_search function to accept ToolContext for credential retrieval (#227)
1 parent 7fbdda4 commit d55ad50

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

veadk/tools/builtin_tools/web_search.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from urllib.parse import quote
2424

2525
import requests
26+
from google.adk.tools import ToolContext
2627

2728
from veadk.config import getenv
2829
from veadk.utils.logger import get_logger
@@ -151,7 +152,7 @@ def request(method, date, query, header, ak, sk, action, body):
151152
return r.json()
152153

153154

154-
def web_search(query: str) -> list[str]:
155+
def web_search(query: str, tool_context: ToolContext) -> list[str]:
155156
"""Search a query in websites.
156157
157158
Args:
@@ -166,8 +167,14 @@ def web_search(query: str) -> list[str]:
166167
"Count": 5,
167168
"NeedSummary": True,
168169
}
169-
ak = getenv("VOLCENGINE_ACCESS_KEY")
170-
sk = getenv("VOLCENGINE_SECRET_KEY")
170+
171+
ak = tool_context.state.get(
172+
"VOLCENGINE_ACCESS_KEY", getenv("VOLCENGINE_ACCESS_KEY")
173+
)
174+
175+
sk = tool_context.state.get(
176+
"VOLCENGINE_SECRET_KEY", getenv("VOLCENGINE_SECRET_KEY")
177+
)
171178

172179
now = datetime.datetime.utcnow()
173180
response_body = request(

0 commit comments

Comments
 (0)