Metadata-Version: 2.4
Name: langchain-nwo
Version: 0.1.0
Summary: LangChain integration for the NWO Robotics API — the only API enabling AI agents to control physical robots
Project-URL: Homepage, https://nwo.capital
Project-URL: Documentation, https://github.com/RedCiprianPater/langchain-nwo
Project-URL: Repository, https://github.com/RedCiprianPater/langchain-nwo
Project-URL: Bug Tracker, https://github.com/RedCiprianPater/langchain-nwo/issues
Project-URL: API Docs, https://nwo.capital/webapp/nwo-robotics.html
Project-URL: Demo, https://huggingface.co/spaces/PUBLICAE/nwo-robotics-api-demo
Project-URL: Cardiac SDK, https://github.com/RedCiprianPater/nwo-cardiac-sdk
Project-URL: MCP Server, https://github.com/RedCiprianPater/mcp-server-robotics
Author-email: NWO Robotics <state@nwo.capital>
License: MIT License
        
        Copyright (c) 2026 NWO Robotics
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-agents,embodied-ai,langchain,langsmith,llm,nwo,robot-control,robotics,ros2,vla
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: langchain-core>=0.2.0
Requires-Dist: pydantic>=2.0
Requires-Dist: requests>=2.31.0
Provides-Extra: anthropic
Requires-Dist: langchain-anthropic>=0.1.0; extra == 'anthropic'
Provides-Extra: dev
Requires-Dist: langchain-core>=0.2.0; extra == 'dev'
Requires-Dist: pydantic>=2.0; extra == 'dev'
Requires-Dist: pytest-timeout>=2.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: requests>=2.31.0; extra == 'dev'
Requires-Dist: responses>=0.25; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: langgraph
Requires-Dist: langgraph>=0.2.0; extra == 'langgraph'
Provides-Extra: openai
Requires-Dist: langchain-openai>=0.1.0; extra == 'openai'
Description-Content-Type: text/markdown

# 🤖 langchain-nwo

> **The only robotics API that lets AI agents control physical robots.**

[![PyPI version](https://img.shields.io/pypi/v/langchain-nwo.svg)](https://pypi.org/project/langchain-nwo/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![LangChain](https://img.shields.io/badge/LangChain-compatible-green.svg)](https://github.com/langchain-ai/langchain)

`langchain-nwo` is the official LangChain integration for the **NWO Robotics API** — bridging the gap between LLM agents and physical robots. Drop it into any LangChain or LangGraph agent and let the agent control real hardware.

---

## 🔗 Resources

| Resource | Link |
|---|---|
| NWO Robotics API | https://nwo.capital/webapp/nwo-robotics.html |
| Cardiac Identity | https://nwo.capital/webapp/nwo-cardiac.html |
| MCP Server | https://github.com/RedCiprianPater/mcp-server-robotics |
| Cardiac SDK | https://github.com/RedCiprianPater/nwo-cardiac-sdk |
| Live Demo | https://huggingface.co/spaces/PUBLICAE/nwo-robotics-api-demo |
| OpenAPI Spec | https://nwo.capital/openapi.yaml |
| Whitepaper | https://www.researchgate.net/publication/401902987 |
| Get an API Key | https://nwo.capital/webapp/api-key.php |

---

## 📦 Installation

```bash
pip install langchain-nwo
```

With LangGraph (recommended for agents):

```bash
pip install "langchain-nwo[langgraph]"
```

---

## ⚡ Quick Start

### LangGraph Agent

```python
from langchain_nwo import NWOToolkit
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Connect the toolkit to your robot
toolkit = NWOToolkit(api_key="sk_live_...")

# Create an embodied AI agent
agent = create_react_agent(
    model=ChatOpenAI(model="gpt-4o"),
    tools=toolkit.get_tools(),
)

# Agent controls a physical robot!
result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Pick up the red box and place it on the table"
    }]
})
```

### Classic LangChain Agent

```python
from langchain_nwo import NWOToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate

toolkit = NWOToolkit(api_key="sk_live_...")
tools = toolkit.get_tools()

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an embodied robot agent. Use your tools to control physical robots."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(ChatOpenAI(model="gpt-4o"), tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

executor.invoke({"input": "Navigate to the kitchen and bring me a water bottle"})
```

### Individual Tools

```python
from langchain_nwo import NWOInferenceTool, NWOQueryStateTool
from langchain_nwo.client import NWOClient

client = NWOClient(api_key="sk_live_...")

# Query robot state
state_tool = NWOQueryStateTool(client=client)
state = state_tool.invoke({"agent_id": "robot_001"})

# Run VLA inference
inference_tool = NWOInferenceTool(client=client)
actions = inference_tool.invoke({
    "instruction": "Pick up the red box",
    "images": ["<base64_image>"],
    "model_id": "xiaomi-robotics-0",
})
```

---

## 🛠️ Available Tools

All 19 tools are included by default. Use `tool_names` to select a subset.

| Tool | Description |
|---|---|
| `nwo_inference` | VLA inference — standard, model router, or edge (<30ms) |
| `nwo_models` | List and inspect available VLA models |
| `nwo_query_state` | Get robot joint angles, gripper state, position, battery |
| `nwo_execute_actions` | Send action arrays directly to a robot |
| `nwo_sensor_fusion` | Multi-modal inference (camera + lidar + thermal + GPS + force) |
| `nwo_status_poll` | Poll task progress and completion status |
| `nwo_task_planner` | Decompose complex instructions into ordered subtasks |
| `nwo_execute_subtask` | Execute one step of a multi-step plan |
| `nwo_learning` | Get technique recommendations or log execution outcomes |
| `nwo_discovery` | Health, capabilities, dry-run validation, plan generation |
| `nwo_ros2` | ROS2 bridge — list, status, command, emergency stop |
| `nwo_simulation` | Trajectory simulation, collision check, MoveIt2 planning |
| `nwo_embodiment` | Robot specs, URDF, benchmarks, auto-calibration |
| `nwo_online_rl` | Online RL sessions, telemetry, and fine-tuning jobs |
| `nwo_tactile` | ORCA hand — taxel reading, grip quality, slip detection |
| `nwo_agent_management` | Register agents, check quota, upgrade tier |
| `nwo_cardiac_oracle` | ECG validation and cardiac hash computation |
| `nwo_cardiac_relayer` | On-chain identity on Base mainnet (rootTokenId) |
| `nwo_dataset` | Unitree G1 dataset hub (1.54M+ demonstrations) |

### Tool Subsets

```python
# Minimal: just inference + state + control
tools = NWOToolkit.core_tools(api_key="sk_live_...")

# Multi-step planning focus
tools = NWOToolkit.planning_tools(api_key="sk_live_...")

# Physical ROS2 robots
tools = NWOToolkit.physical_robot_tools(api_key="sk_live_...")

# Custom selection
toolkit = NWOToolkit(
    api_key="sk_live_...",
    tool_names=["nwo_inference", "nwo_ros2", "nwo_status_poll"],
)
tools = toolkit.get_tools()
```

---

## 🤖 7-Step Autonomous Workflow

The NWO API is designed around a 7-step loop that agents can execute autonomously:

```python
from langchain_nwo import NWOToolkit
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

toolkit = NWOToolkit(api_key="sk_live_...")
agent = create_react_agent(
    model=ChatOpenAI(model="gpt-4o"),
    tools=toolkit.get_tools(),
    state_modifier=(
        "You are an autonomous robot agent. Follow this workflow:\n"
        "1. DISCOVER — check capabilities with nwo_discovery(action='capabilities')\n"
        "2. INSPECT  — get robot state with nwo_query_state\n"
        "3. VALIDATE — dry-run the task with nwo_discovery(action='dry_run')\n"
        "4. PLAN     — generate steps with nwo_discovery(action='plan')\n"
        "5. EXECUTE  — run inference with nwo_inference\n"
        "6. MONITOR  — poll status with nwo_status_poll\n"
        "7. LEARN    — log outcome with nwo_learning(action='log')\n"
        "Handle errors gracefully. For SAFETY_VIOLATION, always stop immediately."
    ),
)
```

---

## 🫀 Cardiac Identity (On-Chain Agent ID)

Agents can register on Base mainnet for a verifiable digital identity:

```python
import hashlib
from langchain_nwo import NWOCardiacRelayerTool
from langchain_nwo.client import NWOClient

client = NWOClient(
    api_key="sk_live_...",
    relayer_secret="your-relayer-secret",
)

tool = NWOCardiacRelayerTool(client=client)

# Hash your API key
api_key_hash = "0x" + hashlib.sha256(b"sk_live_your_key").hexdigest()

# Register on Base mainnet (gasless)
result = tool.invoke({
    "action": "register_agent",
    "moonpay_wallet": "0x...your_wallet...",
    "api_key_hash": api_key_hash,
})
# → {"rootTokenId": "42", "txHash": "0x..."}

# Issue task authorization credential
result = tool.invoke({
    "action": "issue_credential",
    "root_token_id": "42",
    "credential_type": "0x...keccak256('task_auth')...",
    "credential_hash": "0x...keccak256(task_id)...",
    "expires_at": 1704067200,
})
```

---

## 🔌 API Endpoints Covered

| Group | Endpoints |
|---|---|
| Inference & Models | `/api-robotics.php?action=inference`, `list_models`, `get_model_info`, edge API |
| Robot Control | `execute`, `query_state`, `sensor_fusion`, `robot_query`, `status_poll` |
| Task Planning | `task_planner`, `execute_subtask`, `learning` |
| Discovery | `health`, `whoami`, `capabilities`, `dry-run`, `plan` |
| Agent Mgmt | `/api-agent-register.php`, `/api-agent-balance.php`, `/api-agent-pay.php` |
| ROS2 Bridge | `nwo-ros2-bridge.onrender.com` — list, status, command, action, e-stop |
| Simulation | `simulate_trajectory`, `check_collision`, `estimate_torques`, `plan_motion` |
| Embodiment | `list`, `detail`, `normalization`, `urdf`, `test_results`, `compare` |
| Calibration | `run_calibration`, `calibrate` |
| Online RL | `start_online_rl`, `submit_telemetry` |
| Fine-Tuning | `create_dataset`, `start_job` |
| Tactile | `/api-orca.php`, `/api-tactile.php` — get_tactile, process, slip_detection |
| Dataset Hub | `/api-unitree-datasets.php` |
| Cosmos | `/api-cosmos.php?action=generate_scene` |
| Cardiac Oracle | `/oracle/validate`, `hashECG`, `verify` |
| Cardiac Relayer | `registerAgent`, `issueCredential`, `hasValidCredential`, `grantAccess`, `/access/check`, `/payment/process` |

---

## 🛡️ Safety

All tools respect NWO's built-in safety constraints:

- Force limit: 50 N
- Torque limit: 10 Nm
- Speed limit: 1.5 m/s
- Human proximity minimum: 0.5 m
- Emergency stop response: <10 ms
- `SAFETY_VIOLATION` errors are never retried

---

## 📊 Quota Tiers

| Tier | Calls/Month | Cost |
|---|---|---|
| Free | 100,000 | Free |
| Prototype | 500,000 | ~0.015 ETH/month |
| Production | Unlimited | ~0.062 ETH/month |

Get an API key: https://nwo.capital/webapp/api-key.php

---

## 🏗️ Development

```bash
git clone https://github.com/RedCiprianPater/langchain-nwo
cd langchain-nwo
pip install -e ".[dev]"
pytest
```

---

## 📄 License

MIT — see [LICENSE](LICENSE)

---

## 🔗 Related Projects

- [mcp-server-robotics](https://github.com/RedCiprianPater/mcp-server-robotics) — MCP server for NWO
- [nwo-cardiac-sdk](https://github.com/RedCiprianPater/nwo-cardiac-sdk) — Cardiac identity SDK
- [NWO Demo on HuggingFace](https://huggingface.co/spaces/PUBLICAE/nwo-robotics-api-demo)
