Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

NEAR AI Agent (WIP)

A Python package and command-line interface (CLI) for building and managing AI agents on NEAR Protocol. This package helps developers quickly scaffold, customize, and run their own agents using the NEAR AI Environment API, with support for both local development and NEAR AI deployment.

Features

  • Full integration with NEAR AI's Environment API for context and state management
  • Enhanced CLI for creating, running, and deploying agents
  • Support for both local development and NEAR AI deployment
  • Built-in tool registry for extending agent capabilities
  • Multiple agent templates for different use cases
  • Configurable via config.json and metadata.json
  • Modular design for custom task integration

Installation

Install the package from PyPI:

pip install near_ai_agent

For development:

git clone https://github.com/joe-rlo/near_ai_agent
cd near_ai_agent
pip install -e .

Command-Line Interface (CLI)

The package provides a comprehensive CLI for managing agents:

Create a New Agent

# Create with basic template
near-ai-agent create my-agent

# Create with NEAR AI deployment template
near-ai-agent create my-agent --template near

# Create with advanced features
near-ai-agent create my-agent --template advanced

This creates a directory with the following structure:

my-agent/
├── config.json                 # Agent configuration
├── my-agent_agent.py          # Main agent implementation
├── run.py                     # Example usage script
└── metadata.json              # (Only with --template near)

Run an Agent

# Run locally with mock environment
near-ai-agent run --config ./my-agent/config.json --local

# Run with custom environment path
near-ai-agent run --config ./my-agent/config.json --env_path /custom/path

Prepare for NEAR AI Deployment

# Prepare agent for deployment
near-ai-agent prepare my-agent

# Prepare with custom registry path
near-ai-agent prepare my-agent --registry /custom/registry/path

Using as a Python Module

Basic Usage

from near_ai_agent.agent import NearAIAgent

# For local development
from near_ai_agent.environment import NearAIEnvironment
env = NearAIEnvironment()  # Creates mock environment
agent = NearAIAgent(env=env)
agent.run()

# For NEAR AI deployment
agent = NearAIAgent()  # Environment provided by NEAR AI
agent.run()

Custom Agent with Tools

from near_ai_agent.agent import NearAIAgent

class CustomAgent(NearAIAgent):
    def _register_tools(self):
        super()._register_tools()  # Register default tools
        
        @self.tool_registry.register_tool
        def calculate_sum(a: int, b: int) -> int:
            """Calculate the sum of two numbers"""
            return a + b

# Initialize and run
agent = CustomAgent()
agent.run()

Configuration

Local Configuration (config.json)

{
    "agent_name": "MyCustomAgent",
    "version": "1.0.0",
    "system_prompt": {
        "role": "system",
        "content": "You are a helpful AI assistant."
    },
    "model": "qwen2p5-72b-instruct",
    "temperature": 0.7,
    "default_tasks": {
        "greet": "Hello! I'm your custom agent.",
        "help": "I can help with various tasks."
    }
}

NEAR AI Deployment (metadata.json)

{
    "category": "agent",
    "description": "Your agent description",
    "tags": ["python", "assistant"],
    "details": {
        "agent": {
            "defaults": {
                "model": "qwen2p5-72b-instruct",
                "model_max_tokens": 16384,
                "model_provider": "fireworks",
                "model_temperature": 0.7
            }
        }
    },
    "show_entry": true,
    "name": "my-custom-agent",
    "version": "0.1.0"
}

Development Workflow

  1. Create a new agent:
near-ai-agent create my-agent --template near
  1. Develop and test locally:
near-ai-agent run --config ./my-agent/config.json --local
  1. Prepare for NEAR AI deployment:
near-ai-agent prepare my-agent
  1. Deploy to NEAR AI:
nearai registry upload ~/.nearai/registry/my-agent
  1. Run on NEAR AI:
nearai agent interactive my-agent --local

Testing

Run tests using unittest:

python -m unittest discover tests

Example Templates

The CLI provides three templates for different use cases:

Basic Template

  • Simple agent with default tasks
  • Good for getting started and basic use cases

Advanced Template

  • Includes tool registry support
  • Custom task implementation
  • Enhanced message processing

NEAR Template

  • Full NEAR AI deployment setup
  • Model configuration
  • Metadata for registry
  • Tool integration

License

This project is licensed under the MIT License.


For more detailed information about building agents on NEAR AI, please visit the NEAR AI documentation.

Metadata

Release files for near-ai-agent 1.0.0a4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for near-ai-agent 1.0.0a4
File Size Uploaded Provenance
near_ai_agent-1.0.0a4.tar.gz 9.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for near-ai-agent 1.0.0a4
File Interpreter ABI Platform
near_ai_agent-1.0.0a4-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / near_ai_agent-1.0.0a4.tar.gz

Download URL near_ai_agent-1.0.0a4.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f52cee1a39cba9dc40d4976746bb79657b8912c63de4d6cd1cc9544f09842a76
BLAKE2b-256 checksum
How to use checksums
1cf3680327a07ab776718e247a29845597759b6d1a0981a169a43122dc7a92bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.1

Release files / near_ai_agent-1.0.0a4-py3-none-any.whl

Download URL near_ai_agent-1.0.0a4-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e97b14aad30ed31fd7bef2656775a04c3d8300c1fad0d5f9b582ce6f774d7055
BLAKE2b-256 checksum
How to use checksums
083a83a335f8837573ed39ce0127c493278d3bc590ab0df75201a98a0baa779a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.1

Security for near-ai-agent 1.0.0a4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page