feat: modernize langchain integration core tools#28
Draft
daveomri wants to merge 31 commits intofeat/modernize-langchain-integrationfrom
Draft
feat: modernize langchain integration core tools#28daveomri wants to merge 31 commits intofeat/modernize-langchain-integrationfrom
daveomri wants to merge 31 commits intofeat/modernize-langchain-integrationfrom
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
…to apify_api_token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First PR into
feat/modernize-langchain-integration; adds the foundational tools layer and modernizes auth conventions across the package. Upcoming PRs will add search & crawling tools, social media tools, LangChain-native components, and docs to feat/modernize-langchain-integration before merging it all tomain.New code: ~880 lines - Tests: ~1000 lines
ApifyToolsClient(_client.py)ApifyClient, one method per tool operation. Accepts bothSecretStrand rawstrtokens and falls back to theAPIFY_API_TOKENenv var. Shared_list_items_or_raisehelper wraps dataset-fetch errors intoRuntimeError.BaseToolsubclassesApifyRunActorTool,ApifyGetDatasetItemsTool,ApifyRunActorAndGetItemsTool,ApifyScrapeUrlTool,ApifyRunTaskTool,ApifyRunTaskAndGetItemsTool. Exported via theAPIFY_CORE_TOOLS: list[type[BaseTool]]convenience list for selective agent binding._ApifyGenericToolbase classhandle_tool_error=True, developer-controlled safety clamping (_clamp_timeout,_clamp_memory,_clamp_items) with configurable ceilings (max_timeout_secs,max_memory_mbytes,max_items) and hardcoded floor of1to enforce API protocol minimums.document_loaders.py,wrappers.py,tools.py)get_from_dict_or_env+@model_validator(mode='before')withSecretStrfield type andsecret_from_env('APIFY_API_TOKEN', default=None)default factory, matchinglangchain-openai/langchain-anthropicconventions. Tokens are automatically redacted in logs/traces and additionally excluded frommodel_dump()/repr()viaexclude=True, repr=False. Client construction moved to@model_validator(mode='after')/model_post_init. Addedpopulate_by_name=TruetoConfigDicton loader and wrapper. The new tools reuse this same auth pattern; fixing it here avoids shipping two parallel conventions across the package.ApifyActorsTool,ApifyDatasetLoader,ApifyWrapperretain their public API; auth changes are internal.test_tools.py,test_client.py,test_document_loaders.py), integration smoke tests undertests/integration_tests/, and error-scenario coverage (missing token, run failure, network error, clamp floor/ceiling, token excluded frommodel_dump,APIFY_TOKENenv-var fallback on the loader).Review strategy
The diff is larger than a typical PR (~1.9k lines, half of which is tests). Suggested reading order to make it tractable:
_client.py: the newApifyToolsClientabstraction_ApifyGenericToolbase class intools.py, then the 6 tool classes (homogeneous, once one clicks, the rest read fast)document_loaders.py,wrappers.py, and theApifyActorsTool.__init__change intools.pyMerge strategy
This PR targets
feat/modernize-langchain-integration, notmain. The plan is to accumulate all reviewed modernization work (core tools -> actor-specific tools -> LangChain-native components -> docs) on that integration branch, then open a single PR fromfeat/modernize-langchain-integration->mainonce everything is complete and reviewed. Any smaller, pre-existing issues I find along the way will be split out as separate follow-up tasks on the integration branch rather than bundled into the larger PRs.