Skip to main content

Python SDK

Applies to SDK 0.16+ · Last updated: 2026-06-12

The Python SDK provides programmatic access to the AgentNode registry for search, resolution, trust checking, installation, tool loading, and capability gap detection. Use it to build agents that detect missing capabilities and safely acquire verified skills on demand.

Installation

terminal
$ pip install agentnode-sdk

Initialization

app.pypython
from agentnode_sdk import AgentNodeClient

# API key authentication (recommended)
client = AgentNodeClient(api_key="ank_live_abc123def456")

# Or use a bearer token
client = AgentNodeClient(token="your_bearer_token")

# Custom base URL (for self-hosted registries)
client = AgentNodeClient(
    api_key="ank_live_abc123def456",
    base_url="https://api.your-registry.com/v1"
)

Search

search.pypython
result = client.search(
    query="pdf extraction",
    framework="langchain",
    per_page=10
)

print(f"Found {result.total} packages")
for hit in result.hits:
    print(f"  {hit.slug}  {hit.trust_level}  {hit.summary}")

Resolve

Resolve finds the best package for a set of capability IDs, scoring each candidate on capability match, framework fit, runtime compatibility, trust level, and permissions.

resolve.pypython
result = client.resolve(
    capabilities=["pdf_extraction", "web_search"],
    framework="langchain"
)

for match in result.results:
    print(f"{match.slug} v{match.version}")
    print(f"  Score: {match.score}  Trust: {match.trust_level}")
    print(f"  Breakdown: cap={match.breakdown.capability} "
          f"fw={match.breakdown.framework} "
          f"trust={match.breakdown.trust}")

Pre-flight check

Check whether a package can be installed under given trust and permission constraints — without downloading anything.

check.pypython
check = client.can_install(
    "pdf-reader-pack",
    require_trusted=True,
    denied_permissions=["network", "code_execution"]
)

if check.allowed:
    print(f"OK — trust: {check.trust_level}")
else:
    print(f"Blocked: {check.reason}")

Install

Downloads the artifact, verifies the SHA-256 hash, extracts to ~/.agentnode/packages/, installs pip dependencies, and writes agentnode.lock.

install.pypython
result = client.install("pdf-reader-pack", require_trusted=True)

print(result.message)       # "Installed pdf-reader-pack@1.2.0"
print(result.installed)     # True
print(result.hash_verified) # True

Load and run tools

run.pypython
# Load a tool from an installed package
extract = client.load_tool("pdf-reader-pack")
result = extract({"file_path": "report.pdf"})

# Multi-tool packs: load a specific tool by name
describe = client.load_tool("csv-analyzer-pack", tool_name="describe")
summary = describe({"file_path": "data.csv"})

One-call autonomous install

For agents that need to self-upgrade: describe what you need and let AgentNode handle the rest.

autonomous.pypython
# Resolve + trust check + install in one call
result = client.resolve_and_install(
    capabilities=["pdf_extraction"],
    require_trusted=True  # only install trusted/curated packages
)

if result.installed:
    tool = client.load_tool(result.slug)
    data = tool({"file_path": "report.pdf"})
else:
    print(f"Could not install: {result.message}")

Capability gap detection (v0.4.0)

AgentNode can analyze runtime errors to detect missing capabilities — without any LLM. Three detection layers with confidence levels:

  • HighImportError for a known module (e.g. pdfplumber, pandas, selenium)
  • Medium — Error message contains technical keywords (e.g. "chromedriver", "csv parser")
  • Low — Context hints like file extensions or URLs
detect.pypython
from agentnode_sdk import detect_gap

gap = detect_gap(ImportError("No module named 'pdfplumber'"))
print(gap.capability)   # "pdf_extraction"
print(gap.confidence)   # "high"
print(gap.source)       # "import_error"

# Context helps when the error itself isn't specific
gap = detect_gap(RuntimeError("failed"), context={"file": "report.pdf"})
print(gap.capability)   # "pdf_extraction"
print(gap.confidence)   # "low"

detect_and_install() (v0.4.0)

The product-level API for self-upgrading agents. Detects the gap, resolves the best match, and installs it — all in one call.

detect_install.pypython
try:
    result = my_agent_logic()
except Exception as exc:
    upgrade = client.detect_and_install(
        exc,
        auto_upgrade_policy="safe",  # only verified+ skills
        on_detect=lambda cap, conf, err: print(f"Detected: {cap} ({conf})"),
        on_install=lambda slug: print(f"Installed: {slug}"),
    )

    if upgrade.installed:
        result = my_agent_logic()  # retry manually
    else:
        print(f"Detection: {upgrade.capability} ({upgrade.confidence})")
        print(f"Error: {upgrade.error}")

smart_run() (v0.4.0)

Convenience wrapper: wrap your logic and let AgentNode handle detection, installation, and exactly one retry automatically.

smart.pypython
result = client.smart_run(
    lambda: process_pdf("report.pdf"),
    auto_upgrade_policy="safe",
)

if result.success:
    print(result.result)          # your function's return value
    print(result.upgraded)        # True if a skill was installed
    print(result.installed_slug)  # e.g. "pdf-reader-pack"
    print(result.duration_ms)     # total time including retry
else:
    print(result.error)
    print(result.original_error)  # the first error, always available

Auto-upgrade policies (v0.4.0)

Named policies control what gets auto-installed. When set, the policy overrides individual parameters like require_verified.

PolicyBehavior
"off"Detect only, never install
"safe"Auto-install verified+ skills (recommended)
"strict"Auto-install trusted+ skills only

Low-confidence detections are blocked from auto-install by default. Use allow_low_confidence=True to override.

Package metadata

metadata.pypython
# Package details
pkg = client.get_package("pdf-reader-pack")
print(f"{pkg.name} v{pkg.latest_version}")
print(f"Downloads: {pkg.download_count}")
print(f"Deprecated: {pkg.is_deprecated}")

# Install metadata (capabilities, permissions, artifact info)
meta = client.get_install_metadata("pdf-reader-pack")
print(f"Runtime: {meta.runtime}")
print(f"Entrypoint: {meta.entrypoint}")
for cap in meta.capabilities:
    print(f"  {cap.name} ({cap.capability_id})")
if meta.permissions:
    print(f"  Network: {meta.permissions.network_level}")
    print(f"  Filesystem: {meta.permissions.filesystem_level}")