NearAI LangChain Integration
nearai_langchain provides seamless integration between NearAI and LangChain, allowing developers to use NearAI's capabilities within their LangChain applications.
🎯 Key Purposes
-
Libraries Support
- Langchain
- Langgraph
- Coinbase AgentKit
-
Optional NearAI Inference Integration
- Access model inference through NearAI's optimized infrastructure
- Maintain compatibility with standard LangChain for other use cases
- Seamlessly switch between NearAI and LangChain inference
-
NearAI Registry Integration
- Register and manage agents in the NearAI registry
- Optionally, enable agent-to-agent interaction and make your agents callable by other agents in the NearAI registry
- Auto-generate or validate agent metadata
- Example
metadata.json:{ "name": "langchain_fireworks_example_usage", "version": "0.0.1", "description": "NEAR AI - Langchain Fireworks example usage", "category": "agent", "tags": [], "details": { "agent": { "defaults": { "model": "qwen2p5-72b-instruct", // Optionally, specify "model_provider". fireworks is used by default in nearai. "inference_framework": "nearai" // Use "langchain" or "nearai" for inference. Optional. Default is "nearai". }, "framework": "agentkit" // Used by nearai hub to assign correct dependencies } }, "show_entry": true }
-
Agent Intercommunication
- Upload agents to be used by other agents
- Call other agents from the registry in your own agents
- Framework-agnostic: works with both NearAI and LangChain inference
-
Benchmarking and Evaluation
- Run popular or user owned benchmarks on agents
- Optionally, upload evaluation results to NearAI evaluation table
- Support for both NearAI and LangChain inference frameworks
🚀 Quick Start
Your agent code and metadata.json must be in the same directory. You must run your agent script from that directory:
# Directory structure:
my_agent/
├── metadata.json
├── agent.py
└── [other files...]
# Navigate to agent directory
cd my_agent
# Run your agent locally
python3.11 agent.py
# Or upload agent to nearai registry. Run from `nearai` repo:
nearai registry upload <path_to_your_agent>/my_agent
# Go to app.near.ai and lookup your agent. Run it.
Example agent code:
from langchain_core.messages import SystemMessage
from nearai_langchain.orchestrator import NearAILangchainOrchestrator, RunMode
orchestrator = NearAILangchainOrchestrator(globals())
# To continue conversation on existing thread in local mode:
# orchestrator = NearAILangchainOrchestrator(globals(), thread_id="thread_xxxxxx")
# Langchain chat model that can be passed to other LangChain & LangGraph libraries.
model = orchestrator.chat_model
# NEAR AI environment.
# In remote mode thread is assigned, user messages are given, and an agent is run at least once per user message.
# In local mode an agent is responsible to get and upload user messages.
env = orchestrator.env
if orchestrator.run_mode == RunMode.LOCAL:
print("English -> Italian Translator")
user_input = input("\nEnglish: ")
env.add_user_message(user_input)
messages = [SystemMessage("Translate the following from English into Italian")] + env.list_messages()
result = model.invoke(messages)
print(result)
env.add_reply(result.content)
if orchestrator.run_mode == RunMode.LOCAL:
print("-------------------")
print(result.content)
print("-------------------")
# Run once per user message.
env.mark_done()
See examples/ folder for more examples.
📦 Installation
pip install nearai-langchain
🛠️ Development Setup
-
Clone the repository:
git clone https://github.com/nearai/nearai_langchain.git cd nearai_langchain
-
Install dependencies:
./install.sh
-
Development tools:
- Run format check:
./scripts/format_check.sh - Run linting:
./scripts/lint_check.sh - Run type check:
./scripts/type_check.sh
Metadata
Release files for nearai-langchain 0.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nearai_langchain-0.0.13.tar.gz | 10.1 kB | Without provenance | Details for nearai_langchain-0.0.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nearai_langchain-0.0.13-py3-none-any.whl | Python 3 | none | any | Details for nearai_langchain-0.0.13-py3-none-any.whl |
Total release size: 22.0 kB
Release files / nearai_langchain-0.0.13.tar.gz
| Download URL | nearai_langchain-0.0.13.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c57728e74e4389f79f058c0d4c558a8d5b0c3b2286427026cc7bc7b63f964c33
|
|
BLAKE2b-256 checksum How to use checksums |
40992547f1fbf924ab6bf1a14d20734b651398b09410ef0f2f4305a00ecdafb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.3 Linux/6.8.0-1021-azure
|
Release files / nearai_langchain-0.0.13-py3-none-any.whl
| Download URL | nearai_langchain-0.0.13-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a5cc217a1ddb081991fbcc568b6f400ceb0b38098fde83d6e79f8e9241bdbfe
|
|
BLAKE2b-256 checksum How to use checksums |
e73a0fe23caa27cd2870bf58064d18dc3ef2b33d9451f93154bf0d0fcbeb397c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.3 Linux/6.8.0-1021-azure
|
Security for nearai-langchain 0.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.