feat: modernize langchain integration crawl tools#31
Conversation
…mline client handling and error management
…media tools for apify integration
…ms and message for empty dataset
…y tools to enforce safety constraints
…and maintability; update test cases for better formatting and error handling
…ze-langchain-integration-crawl-tools
MQ37
left a comment
There was a problem hiding this comment.
Two issues I would like to address before merging, otherwise the PR looks good! Please see my comments
- I think the serializer is duplicating data when trying to preserve the old flat format while introducing the new nested one. For example the run id is top level and also nested in some cases.
- I do not understand the
error=no_itemscheck, where does this value come from?
drobnikj
left a comment
There was a problem hiding this comment.
Looks good, please fix Kuba comments, ontherwise pre approving
| """Convert Actor dataset items to LangChain Documents.""" | ||
| docs: list[Document] = [] | ||
| for item in items: | ||
| page_content = item.get('text') or item.get('markdown') or '' |
There was a problem hiding this comment.
Content order here is text or markdown, but ApifyRAGWebBrowserTool (same apify/rag-web-browser Actor) uses markdown or text. The source fallback order differs too: here it's crawledUrl or url or metadata.url, the tool does metadata.url or crawledUrl. Same Actor, two consumers, different output when both fields are present — worth aligning, ideally via one shared extract helper.
Generated by Claude Code
…ton and updating return format to json object
MQ37
left a comment
There was a problem hiding this comment.
Cool, thank you! Address the comments from the guys and we can merge.
…ze-langchain-integration-crawl-tools
2f7d2d9
into
feat/modernize-langchain-integration
Summary
Third PR on top of
feat/modernize-langchain-integration; builds on the [native components PR](https://github.com/apify/langchain-apify/tree/feat/modernize-langchain-integration-native-components) and adds the Search & Crawling Actor tools layer: four newBaseToolsubclasses wrapping search, maps, video, and e-commerce Actors. Upcoming PR will fold this together with social-media tools and documentation onto [feat/modernize-langchain-integration](https://github.com/apify/langchain-apify/tree/feat/modernize-langchain-integration) before merging tomain.New code: ~426 lines — Tests: ~337 lines
ApifyRAGWebBrowserTool([_actor_tools.py](langchain_apify/_actor_tools.py))apify/rag-web-browser. Returns JSON withrunmetadata (run_id / status / dataset_id / timestamps) anditems(crawled-page dicts). Distinct fromApifySearchRetriever(which returns LangChainDocumentobjects); this tool returns JSON for agent tool-calling.ApifyGoogleMapsTool([_actor_tools.py](langchain_apify/_actor_tools.py))compass/crawler-google-places. Requiredquery, optionalmax_results(default 10) andlanguage(ISO code). Returns JSON withrunmetadata anditems(place dicts).ApifyYouTubeScraperTool([_actor_tools.py](langchain_apify/_actor_tools.py))streamers/youtube-scraper. Requiredsearch_query, optionalsearch_type: Literal['search', 'video', 'channel'](defaultsearch),max_results(default 10). TightLiteralat the LLM boundary, loosestr+ runtimeValueErrorat the_client.pyboundary so direct callers get the same protection.ApifyEcommerceScraperTool([_actor_tools.py](langchain_apify/_actor_tools.py))apify/e-commerce-scraping-tool. Requiredurl, optionalmax_results(default 20). Bare-URL design intentionally keeps the LLM-facing surface minimal; selector hints can be added later if real users hit empty-result issues.APIFY_SEARCH_TOOLSconvenience listlist[type[BaseTool]]exported alongsideAPIFY_CORE_TOOLSandAPIFY_ACTOR_TOOLSfor selective agent binding:[ApifyRAGWebBrowserTool, ApifyGoogleMapsTool, ApifyYouTubeScraperTool, ApifyEcommerceScraperTool].ApifyToolsClientadditions ([_client.py](langchain_apify/_client.py))google_maps_search,youtube_scrape,ecommerce_scrape) and one rename + signature change:rag_web_search→rag_web_browser_search, now returning(run, items)like the other helpers so the tool layer can build_run_meta(run). All four reuse the existingrun_actor_and_get_itemsplumbing — transport-error wrapping and_check_run_statuscome for free.ApifySearchRetriever([retrievers.py](langchain_apify/retrievers.py))_, items = self._client.rag_web_browser_search(...)); behaviour andDocumentshape are unchanged.ApifyActorsTool/ApifyDatasetLoader/ApifyWrapperuntouched. Therag_web_searchrename is internal — only the retriever consumed it, and that's updated in-tree.run_inputkeys),youtube_scrapeenum validation, happy-path JSON shape per tool, parametrized_TOOL_INVOCATIONSbattery coveringRuntimeError → ToolException, empty-dataset,handle_tool_error=Trueswallow, missing-token, plus inheritance / metadata /APIFY_SEARCH_TOOLSmembership. Existingtest_retrievers.pytests rewired for the new tuple-return helper.Review strategy
Suggested reading order:
ApifyToolsClientmethods plus therag_web_search → rag_web_browser_searchrename — each follows the same pattern as the native-components methods._ApifyGenericToolsubclasses and their input schemas (homogeneous; once one clicks the rest read fast).APIFY_SEARCH_TOOLSlist and__all__additions.Merge strategy
This PR targets
feat/modernize-langchain-integration, notmain. It depends on the [native components PR](https://github.com/apify/langchain-apify/tree/feat/modernize-langchain-integration-native-components) being merged first —_actor_tools.pyextends the file introduced there and consumes_run_meta/_ApifyGenericToolfromtools.py. Once native components is merged into the integration branch, this PR will be rebased and opened for review. Social-media tools and docs will follow as separate PRs on the same integration branch before the final merge tomain.