3434logger = logging .getLogger (__name__ )
3535
3636# Default user agent for fetch requests
37- DEFAULT_USER_AGENT = (
38- "Mozilla/5.0 (compatible; NATSandboxAgent/1.0; +https://github.com/NVIDIA/NeMo-Agent-Toolkit)"
39- )
37+ DEFAULT_USER_AGENT = ("Mozilla/5.0 (compatible; NATSandboxAgent/1.0; +https://github.com/NVIDIA/NeMo-Agent-Toolkit)" )
4038
4139# Default max content length (characters) returned per call
4240DEFAULT_MAX_LENGTH = 5000
@@ -54,10 +52,8 @@ class WebFetchInput(BaseModel):
5452 )
5553 start_index : int = Field (
5654 default = 0 ,
57- description = (
58- "Character position to start reading from. "
59- "Use this to paginate through long pages. Default is 0."
60- ),
55+ description = ("Character position to start reading from. "
56+ "Use this to paginate through long pages. Default is 0." ),
6157 ge = 0 ,
6258 )
6359 raw : bool = Field (
@@ -93,9 +89,9 @@ async def web_fetch(
9389
9490 try :
9591 async with httpx .AsyncClient (
96- follow_redirects = True ,
97- timeout = 30.0 ,
98- headers = {"User-Agent" : DEFAULT_USER_AGENT },
92+ follow_redirects = True ,
93+ timeout = 30.0 ,
94+ headers = {"User-Agent" : DEFAULT_USER_AGENT },
9995 ) as client :
10096 response = await client .get (url )
10197 response .raise_for_status ()
@@ -154,10 +150,8 @@ async def web_fetch(
154150 result ["next_start_index" ] = start_index + max_length
155151 result ["remaining" ] = total_length - (start_index + max_length )
156152
157- logger .info (
158- f"Web fetch returned { len (content )} chars "
159- f"(total={ total_length } , start={ start_index } )"
160- )
153+ logger .info (f"Web fetch returned { len (content )} chars "
154+ f"(total={ total_length } , start={ start_index } )" )
161155 return result
162156
163157 except httpx .HTTPStatusError as e :
@@ -183,9 +177,7 @@ async def web_fetch(
183177 }
184178
185179
186- def create_web_fetch_tool (
187- max_output_chars : int = DEFAULT_MAX_OUTPUT_CHARS ,
188- ) -> StructuredTool :
180+ def create_web_fetch_tool (max_output_chars : int = DEFAULT_MAX_OUTPUT_CHARS , ) -> StructuredTool :
189181 """Create the web fetch tool.
190182
191183 Args:
@@ -196,19 +188,17 @@ def create_web_fetch_tool(
196188 """
197189 return StructuredTool .from_function (
198190 coroutine = lambda url , max_length = DEFAULT_MAX_LENGTH , start_index = 0 , raw = False : web_fetch (
199- url , max_length , start_index , raw , max_output_chars
200- ),
191+ url , max_length , start_index , raw , max_output_chars ),
201192 name = "web_fetch" ,
202- description = (
203- "Fetch a webpage and convert it to clean Markdown text. "
204- "Much faster than web_browse but does NOT render JavaScript. "
205- "Use this for static pages, articles, documentation, and API responses. "
206- "Use 'start_index' to paginate through long content. "
207- "Tip: also works with JSON APIs — useful URLs include: "
208- "Wikipedia edit history: https://en.wikipedia.org/w/api.php?action=query&titles=TITLE&prop=revisions&rvlimit=50&rvprop=timestamp|comment|user&format=json ; "
209- "GitHub issue events: https://api.github.com/repos/OWNER/REPO/issues/NUM/events ; "
210- "GitHub issue timeline: https://api.github.com/repos/OWNER/REPO/issues/NUM/timeline ; "
211- "arXiv monthly listings: https://arxiv.org/list/CATEGORY/YYMM"
212- ),
193+ description = ("Fetch a webpage and convert it to clean Markdown text. "
194+ "Much faster than web_browse but does NOT render JavaScript. "
195+ "Use this for static pages, articles, documentation, and API responses. "
196+ "Use 'start_index' to paginate through long content. "
197+ "Tip: also works with JSON APIs — useful URLs include: "
198+ "Wikipedia edit history: https://en.wikipedia.org/w/api.php?action=query"
199+ "&titles=TITLE&prop=revisions&rvlimit=50&rvprop=timestamp|comment|user&format=json ; "
200+ "GitHub issue events: https://api.github.com/repos/OWNER/REPO/issues/NUM/events ; "
201+ "GitHub issue timeline: https://api.github.com/repos/OWNER/REPO/issues/NUM/timeline ; "
202+ "arXiv monthly listings: https://arxiv.org/list/CATEGORY/YYMM" ),
213203 args_schema = WebFetchInput ,
214204 )
0 commit comments