feat: add langchain-rustchain — LangChain tools for RustChain API (answers #3074) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #8199
Conversation
…eck_balance, list_bounties, node_health, current_epoch) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
FlintLeng
left a comment
There was a problem hiding this comment.
PR Review: LangChain-RustChain Integration
Reviewed on: 2026-08-13
Bounty
rustchain-bounties#3074: LangChain tools for RustChain API — bounty claimed in PR body.
Summary
Adds a standalone Python package langchain-rustchain that exposes RustChain read-only API endpoints as LangChain BaseTool subclasses. Enables any LangChain agent to check RTC balances, list bounties, inspect node health, and read the current epoch.
Architecture ✅
Clean LangChain integration. Four tools:
RustChainBalanceTool—/wallet/balanceendpointRustChainBountiesTool— GitHub issues with bounty labelsRustChainNodeHealthTool—/healthendpointRustChainCurrentEpochTool—/epochendpoint
All tools inherit from BaseTool and implement _run() with the standard LangChain interface. No write operations — all read-only, appropriate for untrusted agent environments.
Package structure is correct:
langchain_rustchain/__init__.pyexports all tools + convenienceget_tools()factorypyproject.tomlwith proper metadata (MIT license, Python 3.9+)example.pydemonstrates direct tool calls without requiring an LLM
Dependencies are minimal: Only langchain-core and requests. No heavy LLM SDKs — the package is tool-only, leaving LLM choice to the user.
API Design ✅
RustChainBountiesTool uses GitHub API correctly: Queries repos/Scottcjn/rustchain-bounties/issues with labels=bounty and state=open. No authentication required for public issues — correct.
All tools target https://rustchain.org by default with configurable override via environment variable. Appropriate for a read-only integration.
Error handling: Each tool catches requests.RequestException and returns a user-friendly error string instead of raising. This is the right behaviour for LangChain tools — agents can handle the error message gracefully.
Minor Notes
-
RustChainBountiesToolpagination: The tool fetchesper_page=20by default. For a bounty program with many open issues, this may miss older bounties. Consider adding pagination support or increasing the limit. -
No caching: Each tool call hits the live API. For frequently-called tools like
NodeHealthTool, caching with a short TTL (e.g., 30s) would reduce load. Not critical for a v1. -
pyproject.tomlversion: No explicit version field — setuptools will infer from git tags or default to0.0.0. Consider adding an explicit version for PyPI publishing.
Wallet: RTC019e78d600fb3131c29d7ba80aba8fe644be426e
✅ LGTM — clean, well-scoped LangChain integration that answers #3074 with appropriate read-only tooling.
Summary
Adds a standalone langchain-rustchain Python package under
integrations/langchain-rustchain/that exposes RustChain read-only API endpoints as LangChainBaseToolsubclasses.Wallet:
fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvTTools
rustchain_check_balanceGET /wallet/balance?miner_id=...rustchain_list_bountiesrustchain_get_node_healthGET /healthrustchain_get_current_epochGET /epochStructure
Verification
All 4 tools tested against the live public node (https://rustchain.org):
rustchain_check_balance("test_wallet")→{"balance_rtc": 0.0}rustchain_list_bounties(limit=3)→ 3 open bounties returnedrustchain_get_node_health()→{"version": "2.2.1-rip200", "uptime_s": 174000+}rustchain_get_current_epoch()→{"epoch": 249, "slot": 35909, "enrolled_miners": 17}Acceptance Checklist
pip install .works (pyproject.toml)GH_TOKEN/GITHUB_TOKENenv var (higher rate limit, no token = unauthenticated fallback)example.pyruns without an LLM (direct tool calls)Closes rustchain-bounties#3074