Metadata-Version: 2.4
Name: lmp-protocol
Version: 0.2.0
Summary: Language Machine Protocol (LMP) Framework - The standard for AI code execution
Author-email: LMP Authors <author@example.com>
Project-URL: Homepage, https://github.com/your-username/lmp
Project-URL: Bug Tracker, https://github.com/your-username/lmp/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Interpreters
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: pydantic>=2.0.0
Requires-Dist: dill>=0.3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"

# Language Machine Protocol (LMP) 🚀

[![PyPI version](https://badge.fury.io/py/lmp-protocol.svg)](https://badge.fury.io/py/lmp-protocol)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/release/python-3110/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**LMP (Language Machine Protocol)** is the open standard designed to bridge higher-level AI logic (like LLMs and Agent frameworks) with low-level, sandboxed execution environments. 

Think of it like **LSP (Language Server Protocol)**, but instead of connecting your code editor to a language analyzer, it connects your **AI Agent** to a **Stateful Sandbox Engine**.

---

## ✨ Key Features

- 🧠 **Stateful Execution**: Variables, functions, and memory persist between code executions. You no longer have to pass giant state strings back and forth.
- 🔒 **Capability-Based Security**: (Coming soon) Strict bounds on CPU, memory, and filesystem access to run untrusted agent code safely.
- 🛠️ **JSON-RPC 2.0**: Completely standard, language-agnostic message protocol over standard input/output (`stdio`).
- 🤖 **Agent Framework Ready**: Drop-in adapters for LangChain out-of-the-box.

---

## 📦 Installation

Installing LMP is incredibly simple. You can install it globally via pip:

```bash
pip install lmp-protocol
```

---

## 💻 The LMP CLI (Inspector)

LMP comes with a built-in CLI to help you start servers or debug your execution engine interactively.

To launch the **LMP Inspector** (an interactive terminal where you can type code and inspect memory), run:
```bash
lmp repl
```

**Example Session:**
```text
Welcome to the LMP Inspector (REPL)!
lmp> x = [1, 2, 3, 4]
lmp> sum_x = sum(x)
lmp> inspect()
--- Variables ---
x (list): [1, 2, 3, 4]
sum_x (int): 10
-----------------
```

To start a standalone headless daemon process:
```bash
lmp start
```

---

## 🐍 Python SDK Usage

If you are building custom tools, you can use the `LMPClient` to manage background sandboxes effortlessly.

```python
from lmp.client.client import LMPClient

# The context manager automatically boots and terminates the daemon process
with LMPClient() as client:
    # 1. Execute Code
    client.execute("a = 10\nb = 20")
    
    # 2. Stateful Memory persists!
    res = client.execute("print(a + b)")
    print(res["result"]["pipes"]["stdout"]) # Outputs: 30
    
    # 3. Inspect Memory dynamically
    memory = client.inspect()
    print(memory["result"]["variables"]["a"]["value"]) # Outputs: 10
```

---

## 🦜🔗 LangChain Integration

If you are building an AI Agent using LangChain, giving it a secure, stateful Python environment is just one line of code.

```python
from lmp.adapters.langchain import LMPTool
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI

# Initialize the stateful LMP tool
python_tool = LMPTool()

llm = OpenAI(temperature=0)
agent = initialize_agent(
    tools=[python_tool], 
    llm=llm, 
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, 
    verbose=True
)

agent.run("Calculate the first 10 numbers of the Fibonacci sequence and print them.")
```

---

## 📖 Specifications

The core protocol relies on the following core JSON-RPC methods:
- `lmp.initialize`: Establish a sandboxed session.
- `lmp.execute`: Run raw text or AST JSON payloads.
- `lmp.inspect`: Introspect memory structures without triggering side effects.
- `lmp.terminate`: Destroy the environment safely.

For deep architectural details, please see the [Full Protocol Specification](language_machine_protocol_spec.md).
