🦜️🔗 LangChain Hive
This package provides the LangChain integration with Hive Intelligence, enabling LLMs to access real-time crypto data via Hive intelligence Search API.
Installation
pip install langchain-hive
Credentials
You need to set your Hive Intelligence API key. You can get one by signing up at hiveintelligence.xyz.
import getpass
import os
if not os.environ.get("HIVE_INTELLIGENCE_API_KEY"):
os.environ["HIVE_INTELLIGENCE_API_KEY"] = getpass.getpass("Hive API key:\n")
Hive Search Tool
The HiveSearch tool allows LLMs to query real-time crypto intelligence data, including prices, trading volumes, protocol stats, and more. It supports both stateless queries and multi-turn conversations.
Instantiation
from langchain_hive import HiveSearch
import os
tool = HiveSearch(api_key=os.environ["HIVE_INTELLIGENCE_API_KEY"])
Invoke with Prompt
The HiveSearch tool accepts a prompt (single-shot) or messages (multi-turn history) and returns a structured response based on the latest on-chain data.
result = tool.invoke({"prompt": "What's the current price of Bitcoin?"})
print(result)
Invoke with Conversation History
Supports multi-turn memory via a list of chat messages:
messages = [
{"role": "user", "content": "Tell me about Uniswap"},
{"role": "assistant", "content": "Uniswap is a decentralized exchange protocol..."},
{"role": "user", "content": "What's its trading volume today?"}
]
result = tool.invoke({"messages": messages})
print(result)
Control Parameters
You can modify the model's behavior with additional parameters:
temperature(float): Controls randomness. Lower is more deterministic.top_p(float): Controls nucleus sampling diversity.top_k(int): Limits token sampling to top-k options.include_data_sources(bool): Whether to return information about the sources used.
result = tool.invoke({
"prompt": "Explain the pros and cons of yield farming in DeFi",
"temperature": 0.2,
"top_p": 0.85,
"top_k": 40,
"include_data_sources": True
})
print(result)
Mixed Usage Example
You can also combine messages with control parameters:
result = tool.invoke({
"messages": messages,
"temperature": 0.5,
"top_k": 30,
"include_data_sources": True
})
print(result)
Agent Integration
Hive Search can be used directly within LangChain Agents for dynamic tool usage.
# !pip install -qU langchain langchain-hive langchain-anthropic
from langchain_hive import HiveSearch
from langchain_anthropic import ChatAnthropic
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.schema import HumanMessage
import datetime
# Initialize Hive Search Tool
hive_search_tool = HiveSearch(api_key="your_hive_api_key")
# Initialize LLM (Claude)
llm = ChatAnthropic(model="claude-3-sonnet-20240229", temperature=0, api_key="your_anthropic_api_key")
# Setup prompt template
today = datetime.datetime.today().strftime("%D")
prompt = ChatPromptTemplate.from_messages([
("system", f"""You are a helpful crypto assistant. Use the hive search tool to answer queries with real-time blockchain data. The date today is {today}."""),
MessagesPlaceholder(variable_name="messages"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
])
# Create agent
agent = create_tool_calling_agent(
llm=llm,
tools=[hive_search_tool],
prompt=prompt
)
# Create executor
agent_executor = AgentExecutor(agent=agent, tools=[hive_search_tool], verbose=True)
# Use the agent
user_input = "what is the current price of ETH?"
response = agent_executor.invoke({"messages": [HumanMessage(content=user_input)]})
print(response)
Summary
langchain-hive makes it simple to integrate live, real-time crypto and DeFi insights directly into your LangChain agents or apps via Hive Intelligence.
Release files for langchain-hive 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_hive-0.1.1.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_hive-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / langchain_hive-0.1.1.tar.gz
| Download URL | langchain_hive-0.1.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26b94a0e989c1710a1108d524417debb1404d910f11a141568cf6de31ccbfae0
|
|
BLAKE2b-256 checksum How to use checksums |
20b0c1559ad04d33b331f7c2d95096b4ccb2333189563990682c26279e24d653
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.11.9 Windows/10
|
Release files / langchain_hive-0.1.1-py3-none-any.whl
| Download URL | langchain_hive-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b85f84a90bbf9b7a6a1cf718e76fa0245541649d330e21a7f6f84a3d844e0f9
|
|
BLAKE2b-256 checksum How to use checksums |
29762793284ff8e6e823cbe4ca61611dd017cf133cbe1c5bab7c09cda529ef29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.11.9 Windows/10
|