LangChain & LLM Agent Integration
Enable autonomous AI agents to audit smart contracts, check market regimes, and calculate DEX slippage prior to executing financial actions.Python Tool Declaration (LangChain)
import os
import requests
from langchain.tools import tool
CRYPTECH_API_KEY = os.getenv("CRYPTECH_API_KEY")
@tool
def audit_crypto_token(contract_address: str, chain: str = "ethereum") -> str:
"""
Audits a cryptocurrency token for honeypots, trading taxes, and AMM cashout liquidity.
Use this tool whenever a user asks to evaluate a token or check if a contract is safe.
"""
url = "https://api.cryptechtoday.com/api/v1/analyze"
headers = {
"X-API-Key": CRYPTECH_API_KEY,
"Content-Type": "application/json"
}
res = requests.post(url, json={"address": contract_address, "chain": chain}, headers=headers)
if res.status_code != 200:
return f"Audit failed: {res.text}"
d = res.json()
return (
f"Token: {d.get('name')} ({d.get('symbol')})\n"
f"Safety Score: {d.get('total_score')}/100 [{d.get('risk_label')}]\n"
f"Verdict: {d.get('verdict_summary')}\n"
f"Max Safe Exit: ${d.get('sellability', {}).get('max_safe_exit_usd', 0):,} USD"
)
@tool
def get_macro_market_regime() -> str:
"""
Returns current crypto market macro regime (BULLISH_EXPANSION, BEARISH_CONTRACTION, etc.)
and Fear & Greed sentiment index.
"""
res = requests.get("https://api.cryptechtoday.com/api/markets/intel/regime")
d = res.json()
return f"Regime: {d.get('regime')} | Stance: {d.get('risk_posture')} | F&G: {d.get('fear_greed_index', {}).get('value')}"
Usage in Agent Chain
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
llm = ChatOpenAI(model="gpt-4o", temperature=0)
tools = [audit_crypto_token, get_macro_market_regime]
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
agent.run("Should I invest in 0x514910771AF9Ca656af840dff83E8264EcF986CA on Ethereum right now?")