walletpress/backend/adapters/langchain.py
cryptorugmunch e13bd4d774
Some checks are pending
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
CI / security (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / license (push) Waiting to run
CI / ai-review (push) Waiting to run
docs: apply fleet-template (16-artifact scaffold)
Adds missing standard artifacts:
- README.md (if missing)
- AGENTS.md (AI agent contract)
- PLAN.md (current sprint)
- STATUS.md (where we are)
- DEVELOPMENT.md (dev workflow)
- DEPLOYMENT.md (deploy procedure)
- TESTING.md (test strategy)
- DECISIONS.md (ADR index + templates)
- .github/CODEOWNERS
- .github/workflows/ci.yml

Preserves all existing artifacts.

Refs: RugMunchMedia/fleet-template
2026-07-02 02:07:06 +07:00

35 lines
1.2 KiB
Python

"""LangChain Adapter — Use WalletPress tools in LangChain agents."""
from __future__ import annotations
from langchain.tools import BaseTool
class WalletPressTool(BaseTool):
"""LangChain tool wrapping a WalletPress MCP tool."""
name: str = ""
description: str = ""
_fn = None
def __init__(self, name: str, description: str, fn, **kwargs):
super().__init__(name=name, description=description, **kwargs)
self._fn = fn
def _run(self, **kwargs) -> str:
import json
result = self._fn(**kwargs) if callable(self._fn) else {"error": "no fn"}
return json.dumps(result, default=str)
async def _arun(self, **kwargs) -> str:
import json
import asyncio
if asyncio.iscoroutinefunction(self._fn):
result = await self._fn(**kwargs)
else:
result = self._fn(**kwargs)
return json.dumps(result, default=str)
def get_tools() -> list[BaseTool]:
"""Get all WalletPress MCP tools as LangChain tools."""
from agent.mcp_server import mcp
return [WalletPressTool(name=t.name, description=t.description or t.name, fn=t.fn)
for t in mcp._tool_manager.list_tools()]