Skip to main content

A Python package to build AI agents on NEAR Protocol.

Project description

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.

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

near_ai_agent-1.0.0a4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

near_ai_agent-1.0.0a4-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file near_ai_agent-1.0.0a4.tar.gz.

File metadata

  • Download URL: near_ai_agent-1.0.0a4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.1

File hashes

Hashes for near_ai_agent-1.0.0a4.tar.gz
Algorithm Hash digest
SHA256 f52cee1a39cba9dc40d4976746bb79657b8912c63de4d6cd1cc9544f09842a76
MD5 ea563a3e063b9ea3a63350dd588f3bf8
BLAKE2b-256 1cf3680327a07ab776718e247a29845597759b6d1a0981a169a43122dc7a92bd

See more details on using hashes here.

File details

Details for the file near_ai_agent-1.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for near_ai_agent-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 e97b14aad30ed31fd7bef2656775a04c3d8300c1fad0d5f9b582ce6f774d7055
MD5 744b7f44b795612071127cc5141c4a96
BLAKE2b-256 083a83a335f8837573ed39ce0127c493278d3bc590ab0df75201a98a0baa779a

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