File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 5555
5656_GoogleSearchLike = gapic .Tool .GoogleSearch | dict [str , Any ]
5757_CodeExecutionLike = gapic .CodeExecution | dict [str , Any ]
58+ _UrlContextLike = gapic .UrlContext | dict [str , Any ]
5859
5960
6061class _ToolDict (TypedDict ):
6162 function_declarations : Sequence [_FunctionDeclarationLike ]
6263 google_search_retrieval : _GoogleSearchRetrievalLike | None
6364 google_search : NotRequired [_GoogleSearchLike ]
6465 code_execution : NotRequired [_CodeExecutionLike ]
66+ url_context : NotRequired [_UrlContextLike ]
6567
6668
6769# Info: This means one tool=Sequence of FunctionDeclaration
@@ -153,6 +155,7 @@ def convert_to_genai_function_declarations(
153155 "google_search_retrieval" ,
154156 "google_search" ,
155157 "code_execution" ,
158+ "url_context" ,
156159 ]
157160 ):
158161 fd = _format_to_gapic_function_declaration (tool ) # type: ignore[arg-type]
@@ -186,6 +189,8 @@ def convert_to_genai_function_declarations(
186189 )
187190 if "code_execution" in tool :
188191 gapic_tool .code_execution = gapic .CodeExecution (tool ["code_execution" ])
192+ if "url_context" in tool :
193+ gapic_tool .url_context = gapic .UrlContext (tool ["url_context" ])
189194 else :
190195 fd = _format_to_gapic_function_declaration (tool )
191196 gapic_tool .function_declarations .append (fd )
Original file line number Diff line number Diff line change 1+ from langchain_core .messages import AIMessage
2+
3+ from langchain_google_genai import ChatGoogleGenerativeAI
4+
5+ _MODEL = "gemini-2.5-flash"
6+
7+
8+ def test_url_context_tool () -> None :
9+ model = ChatGoogleGenerativeAI (model = _MODEL )
10+ model_with_search = model .bind_tools ([{"url_context" : {}}])
11+
12+ input = "What is this page's contents about? https://docs.langchain.com"
13+ response = model_with_search .invoke (input )
14+ assert isinstance (response , AIMessage )
15+
16+ assert (
17+ response .response_metadata ["grounding_metadata" ]["grounding_chunks" ][0 ]["web" ][
18+ "uri"
19+ ]
20+ is not None
21+ )
You can’t perform that action at this time.
0 commit comments