AgentPM™ Python SDK
Project description
AgentPM™ Python SDK
A lean, typed Python SDK for AgentPM tools. It discovers tools installed by agentpm install, executes their entrypoints in a subprocess, and returns JSON results you can pass to your agents.
- 🔎 Discovers tools in
.agentpm/tools(project) and~/.agentpm/tools(user), withAGENTPM_TOOL_DIRoverride. - 🚀 Runs entrypoints via
nodeorpython(whitelisted) and exchanges JSON over stdin/stdout. - 🧩 Metadata-aware:
with_meta=Truereturnsfunc + meta(name, version, description, inputs, outputs). - 🧪 Framework adapters (optional): e.g., a LangChain adapter you can use if installed.
Requires Python 3.10+.
Installation
From PyPI (recommended)
Using uv:
uv pip install agentpm
Or with standard pip:
python -m pip install agentpm
If you'll use the optional LangChain adapter:
uv pip install 'agentpm[langchain]'
# or
python -m pip install 'agentpm[langchain]'
Quick Start (with uv)
# create and activate a venv
uv venv
source .venv/bin/activate
# install SDK in editable dev mode (ruff/black/mypy/pytest, etc.)
uv pip install -e ".[dev]"
# sanity checks
uv run ruff check .
uv run black --check .
uv run mypy
uv run pytest -q
If you're not using
uv, standardpython -m venv+pip install -e ".[dev]"works too.
Using the SDK
from agentpm import load
# Spec format: "@scope/name@version"
summarize = load("@zack/summarize@0.1.0")
result = summarize({"text": "Long document content..."})
print(result["summary"])
With metadata (build richer tool descriptions)
from agentpm import load
tool = load("@zack/summarize@0.1.0", with_meta=True)
summarize, meta = tool["func"], tool["meta"]
rich_description = (
f"{meta.get('description','')} "
f"Inputs: {meta.get('inputs')}. "
f"Outputs: {meta.get('outputs')}."
)
print(rich_description)
print(summarize({"text": "hello"})["summary"])
Optional: LangChain adapter
The adapter is lazy-imported and only needed if you call it.
from agentpm import load, to_langchain_tool # to_langchain_tool is loaded on first access
loaded = load("@zack/summarize@0.1.0", with_meta=True)
tool = to_langchain_tool(loaded) # requires `langchain-core` installed
If you use the adapter, install LangChain core:
uv pip install langchain-core
Where tools are discovered
Resolution order:
AGENTPM_TOOL_DIR(environment variable)./.agentpm/tools(project-local)~/.agentpm/tools(user-local)
Each tool lives in a directory like:
.agentpm/
tools/
@zack/summarize/
0.1.0/
agent.json
(tool files…)
Manifest & Runtime Contract
agent.json (minimal fields used by the SDK):
{
"name": "@zack/summarize",
"version": "0.1.0",
"description": "Summarize long text.",
"inputs": {
"type": "object",
"properties": { "text": { "type": "string", "description": "Text to summarize" } },
"required": ["text"]
},
"outputs": {
"type": "object",
"properties": { "summary": { "type": "string", "description": "Summarized text" } },
"required": ["summary"]
},
"entrypoint": {
"command": "python",
"args": ["main.py"],
"cwd": ".",
"timeout_ms": 60000,
"env": {}
}
}
Execution contract:
- SDK writes inputs JSON to the process stdin.
- Tool writes a single outputs JSON object to stdout.
- Non-JSON logs should go to stderr.
- Process must exit with code 0 on success.
Interpreter whitelist: node, nodejs, python, python3.
The SDK validates the interpreter and checks it’s present on PATH.
Development
Project layout
src/
agentpm/
__init__.py # re-exports: load, to_langchain_tool (lazy)
core.py # resolver/spawn/JSON plumbing
types.py # JsonValue, TypedDicts
adapters/
__init__.py
langchain.py # optional adapter
py.typed # marks package as typed
tests/
test_basic.py
Common tasks (via uv)
uv run ruff check .
uv run black --check .
uv run mypy
uv run pytest -q
# run hooks locally on all files
uv run pre-commit run --all-files
Building & Publishing
# build wheel & sdist
uv run python -m build
# verify metadata
uv run twine check dist/*
# upload (PyPI)
uv run twine upload dist/*
# or TestPyPI first
uv run twine upload -r testpypi dist/*
Running mixed-runtime Agent apps with Docker
Some AgentPM tools run on Node, some on Python—and your agent may need to spawn both. Using Docker gives you a single, reproducible environment where both interpreters are installed and on PATH, which avoids the common “interpreter not found” issues that pop up on PaaS/CI or IDEs.
Why Docker?
✅ Hermetic: Python + Node versions are pinned inside the image.
✅ No PATH drama: node/python are present and discoverable.
✅ Prod/CI parity: the same image runs on your laptop, CI, and servers.
✅ Easy secrets: pass API keys via env at docker run/Compose time.
✅ Fewer surprises: consistent OS libs for LLM clients, SSL, etc.
When to use it
- You deploy to platforms that don’t let you apt-get both runtimes.
- Your agent uses tools with different interpreters (Node + Python).
- Your local dev/IDE PATH differs from production and causes failures.
- You want reproducible builds and easy rollback.
How to use it
- Copy the provided Dockerfile into your repo.
- (Optional) Pre-install tools locally with agentpm install ... and commit or copy .agentpm/tools/ into the image, or run agentpm install at build time if your CLI is available in the image.
- Build & run:
docker build -t agent-app .
docker run --rm -e OPENAI_API_KEY=$OPENAI_API_KEY agent-app
- For development, use the docker-compose.yml snippet to mount your source and pass env vars conveniently.
Troubleshooting
- Set
AGENTPM_DEBUG=1to print the SDK’s project root, search paths, merged PATH, and resolved interpreters. - You can force interpreters via:
AGENTPM_NODE=/usr/bin/node
AGENTPM_PYTHON=/usr/local/bin/python3.11
- Prefer absolute interpreters in agent.json.entrypoint.command for production (e.g., /usr/bin/node). The SDKs still enforce the Node/Python family.
Troubleshooting
-
No JSON object found on stdout.Ensure your tool prints a single JSON object as the last thing on stdout, and writes logs to stderr. -
Unsupported agent.json.entrypoint.commandOnlynode/pythonare allowed (includingnodejs/python3). Updateentrypoint.command. -
Interpreter "... " not found on PATHInstall the interpreter or adjustentrypoint.command. The SDK runs<command> --versionto verify availability. -
PEP 668 / “externally managed” Use a venv (we recommend
uv venv) and install withuv pip install -e ".[dev]". -
IDE can’t import
agentpmEnsure your interpreter is the project’s.venv/bin/python, and that you ran the editable install.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentpm-0.1.2.tar.gz.
File metadata
- Download URL: agentpm-0.1.2.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3d02a792600473fede51fb1e3fd4d188f660206665766c4e7a745510919fad
|
|
| MD5 |
6ef9effd98e81e455b3223c815ecd4e4
|
|
| BLAKE2b-256 |
bdffd3c7edfdbb9c84db43034850c96cc52d6d954ebefc7707a55039afc75295
|
Provenance
The following attestation bundles were made for agentpm-0.1.2.tar.gz:
Publisher:
release.yml on agentpm-dev/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentpm-0.1.2.tar.gz -
Subject digest:
ea3d02a792600473fede51fb1e3fd4d188f660206665766c4e7a745510919fad - Sigstore transparency entry: 661671063
- Sigstore integration time:
-
Permalink:
agentpm-dev/sdk-python@4a73b5437d69f03b936abcd72ab98a1a9fd1ac4e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/agentpm-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a73b5437d69f03b936abcd72ab98a1a9fd1ac4e -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentpm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: agentpm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c58dd27380f3629772f7df29bec4ae0868094bbbb00e3fdb6f96aaeb27325f50
|
|
| MD5 |
da292cc26b11bd950777e934105a00ee
|
|
| BLAKE2b-256 |
e0c38b378e76926c3f5e3a0fa2d9e8d7f4ab979b01a0c29e37a80377a2259a88
|
Provenance
The following attestation bundles were made for agentpm-0.1.2-py3-none-any.whl:
Publisher:
release.yml on agentpm-dev/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentpm-0.1.2-py3-none-any.whl -
Subject digest:
c58dd27380f3629772f7df29bec4ae0868094bbbb00e3fdb6f96aaeb27325f50 - Sigstore transparency entry: 661671070
- Sigstore integration time:
-
Permalink:
agentpm-dev/sdk-python@4a73b5437d69f03b936abcd72ab98a1a9fd1ac4e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/agentpm-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a73b5437d69f03b936abcd72ab98a1a9fd1ac4e -
Trigger Event:
push
-
Statement type: