Skip to main content

Use the Naptha SDK

Quick Start

pip install naptha-sdk

Core Concepts

The Naptha SDK provides a powerful client interface for Naptha Hub and Nodes, with core abstractions for building multi-agent AI workflows. It is made up of:

  1. A client for interacting with the Naptha Hub (like the huggingface_hug library but for multi-agent apps)
  2. Abstractions for the composable building blocks of multi-agent apps like Agent, Orchestrator, Tool, Environment, Persona (i.e. Naptha Modules). With Naptha, communication between these modules happens via API.
  3. Decorators for easily onboarding modules from agent frameworks like CrewAI.
  4. A CLI for interacting with the Naptha Hub and Node

Here's how to get started:

1. Initialize the Client

from naptha_sdk.client.naptha import Naptha

naptha_client = await Naptha(
user=public_key, # Your public key from PRIVATE_KEY env var
hub_username="your_username", # Naptha Hub username
hub_url="https://hub.naptha.ai", # Hub endpoint
node_url="https://node.naptha.ai", # Node endpoint
routing_url="https://routing.naptha.ai", # Routing endpoint
indirect_node_id="your_indirect_node_id" # Node ID for indirect access
)

# Client automatically initializes Node with:
# node_url="https://node.naptha.ai"
# routing_url="https://routing.naptha.ai"
# indirect_node_id="your_indirect_node_id"

# Note: These values can be set in your .env file:
# PRIVATE_KEY=your_private_key (via naptha signup)
# HUB_USERNAME=your_username
# HUB_URL=https://hub.naptha.ai
# NODE_URL=https://node.naptha.ai
# ROUTING_URL=https://routing.naptha.ai
# INDIRECT_NODE_ID=your_indirect_node_id

2. Hub Interactions

Query available resources on the Naptha network:

# List available nodes
nodes = await naptha_client.hub.list_nodes()

# List available agents
agents = await naptha_client.hub.list_agents()

# List available orchestrators
orchestrators = await naptha_client.hub.list_orchestrators()

# List available environments
environments = await naptha_client.hub.list_environments()

# List available personas
personas = await naptha_client.hub.list_personas()

3. Task Management

Create and execute individual tasks:

from naptha_sdk.task import Task

# Define a task
task = Task(
name="my_task",
fn=your_task_function,
worker_node=naptha_client.node,
orchestrator_node=naptha_client.node, # Assuming the same node is used for orchestration
flow_run=flow.flow_run
)

# Run the task
result = await task()

4. Working with Storage

Read from storage

data = await naptha_client.node.read_storage("module_run_id", "output_dir", ipfs=True)

Write to storage

result = await naptha_client.node.write_storage("storage_input", ipfs=True, publish_to_ipns=False)
Need Help?

Join our Discord community for support and discussions!

Modules

Check out our Modules for how to leverage Naptha's Agents, Orchestrators, Environments, Tools, and Personas.