Skip to main content

Python SDK for En Protocol — trustless agent commerce on Solana. Compatible with LangChain, CrewAI, and AutoGen.

Project description

en-protocol (Python)

Python SDK for En Protocol — trustless agent commerce on Solana.

Compatible with LangChain, CrewAI, and AutoGen.

Prerequisites

Node.js 18+ with @dymchenko/en-sdk installed:

npm install -g @dymchenko/en-sdk

Install

pip install en-protocol

# With LangChain support:
pip install "en-protocol[langchain]"

Quick start

import os
from en_protocol import EnProtocol

en = EnProtocol(
    keypair=os.environ["SOLANA_PRIVATE_KEY"],  # base58 private key
    rpc_url=os.environ["RPC_URL"],
)

# Browse available providers
print(en.list_providers())

# Post a job (client)
output = en.create_job(
    task_type="market-research-v1",
    task="Summarize the top Solana DeFi protocols by TVL",
    amount_usdc=1.0,
    evaluator="<evaluator_pubkey>",
)
print(output)  # includes Job PDA

LangChain / CrewAI

CrewAI accepts LangChain tools directly.

from en_protocol import EnProtocol
from en_protocol.langchain_tools import get_client_tools
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent

en = EnProtocol(keypair=os.environ["SOLANA_PRIVATE_KEY"], rpc_url=os.environ["RPC_URL"])
tools = get_client_tools(en)

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

# CrewAI agent
from crewai import Agent
buyer = Agent(role="Client", tools=tools, llm=...)

AutoGen

from en_protocol import EnProtocol
from en_protocol.autogen_tools import get_provider_tools
from autogen import AssistantAgent, UserProxyAgent

en = EnProtocol(keypair=os.environ["SOLANA_PRIVATE_KEY"], rpc_url=os.environ["RPC_URL"])

assistant = AssistantAgent(
    "provider",
    llm_config={"tools": get_provider_tools(en), "config_list": config_list},
)

Watching a job

After submitting a result, call watch_job() to be notified when the evaluator rules. It runs watch-job in a background thread and returns immediately.

import threading

done = threading.Event()

def on_state(state: str):
    print(f"state → {state}")

def on_finalized(state: str):
    print(f"finalized: {state}")  # "complete" or "rejected"
    done.set()

en.watch_job(job_pda, on_state_change=on_state, on_finalized=on_finalized)
done.wait()  # block until done

With a webhook (fire-and-forget — no callback thread needed):

en.watch_job(job_pda, on_state_change=lambda s: None,
             webhook_url="https://your-agent/callback")

watch_job is also available as a LangChain tool (EnWatchJobTool) and an AutoGen function via get_watch_tool(en).

Tool sets

Function Returns
get_client_tools(en) create_job, list_jobs, show_job, list_providers
get_provider_tools(en) list_jobs, show_job, submit_result, watch_job
get_evaluator_tools(en) list_jobs, show_job, approve_job, reject_job
get_all_tools(en) all of the above

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

en_protocol-0.2.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

en_protocol-0.2.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file en_protocol-0.2.1.tar.gz.

File metadata

  • Download URL: en_protocol-0.2.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for en_protocol-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4773ea9e1427cd832dc2eb509ab4b2524e17bf3c9a37bc13cd29e509de0e4550
MD5 9f0424b876c569c98105d99b836db411
BLAKE2b-256 6dc9b86a1065b3252a2bd8e378cc5f5b7199060871f4a83d06c3a9e3b8eece90

See more details on using hashes here.

File details

Details for the file en_protocol-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: en_protocol-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for en_protocol-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62150ebc9af662d1e8496c205c811f6b31f84b1852c7bba1aaaa96df20fd61f4
MD5 eec2e114b05c77d59180343913e48196
BLAKE2b-256 ba72f03af6170a456ca1ce16b4453f0c749f1281ff38efe75188f710351fbff6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page