Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions examples/neo_skill_agent_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env python3
"""
Neo N3 Research Skill Agent Demo

This example demonstrates how to use the SpoonReactSkill agent with the
Neo Query skill for comprehensive blockchain data analysis.

Features:
- Skill-based agent for Neo N3
- Script-based Neo RPC integration (via neo-query skill)
- Advanced analysis of blocks, addresses, and governance
"""

import os
import sys
import asyncio
import logging
from pathlib import Path
from dotenv import load_dotenv

from spoon_ai.agents import SpoonReactSkill
from spoon_ai.chat import ChatBot

# Load environment variables
load_dotenv(override=True)

# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

# Path to example skills
EXAMPLES_SKILLS_PATH = str(Path(__file__).parent / "skills")


class NeoResearchSkillAgent(SpoonReactSkill):
"""
A Neo-focused research agent that uses the neo-query skill
for deep blockchain data analysis.
"""

def __init__(self, **kwargs):
# Set default values before super().__init__
kwargs.setdefault('name', 'neo_research_skill_agent')
kwargs.setdefault('description', 'AI agent specialized in Neo N3 blockchain research')
kwargs.setdefault('system_prompt', self._get_system_prompt())
kwargs.setdefault('max_steps', 10)
kwargs.setdefault('_default_timeout', 120.0)

# Configure skill paths to include examples/skills
kwargs.setdefault('skill_paths', [EXAMPLES_SKILLS_PATH])

# Enable scripts for data query
kwargs.setdefault('scripts_enabled', True)

super().__init__(**kwargs)

@staticmethod
def _get_system_prompt() -> str:
return """You are a top-tier Neo N3 Blockchain Analyst.

Your mission is to provide deep, accurate, and professional analysis of the Neo ecosystem.
You have access to the `neo-query` skill, which provides direct RPC access to Neo data.

When analyzing Neo topics:
1. Use `run_script_neo-query_neo_rpc_query` to fetch real-time data.
2. For addresses: Always check balances (NEO/GAS) and recent transfer history to understand the user's profile.
3. For governance: Use committee and candidate tools to explain the voting landscape.
4. For contracts: Look for verification status and analyze recent invocation logs if needed.
5. Context: Default to Neo Testnet unless Mainnet is specified.

Structure your responses professionally, using tables for data comparison where appropriate.
Always explain technical terms (like NEP-17, GAS, UInt160) in a user-friendly way.
"""

async def initialize(self, __context=None):
"""Initialize the agent and activate Neo skills."""
await super().initialize(__context)

skills = self.list_skills()
logger.info(f"Available skills: {skills}")

async def analyze(self, query: str) -> str:
logger.info(f"Starting Neo analysis: {query}")
response = await self.run(query)
return response


async def demo_neo_analysis():
"""Run a demo of Neo blockchain analysis."""
print("\n" + "=" * 60)
print("Neo N3 Research Skill Agent Demo")
print("(Powered by neo-query skill scripts)")
print("=" * 60)

# Create agent
agent = NeoResearchSkillAgent(
llm=ChatBot(),
auto_trigger_skills=True
)

# Initialize
await agent.initialize()

# Test cases
test_queries = [
"What is the current status of the Neo Testnet? Show me the latest block height and committee members.",
"Check the balance and recent NEP-17 activity for Neo address NUTtedVrz5RgKAdCvtKiq3sRkb9pizcewe.",
"Search for a contract named 'Flamingo' and tell me its hash and verification status."
]

for i, query in enumerate(test_queries, 1):
print(f"\n[Test {i}] Query: {query}")
print("-" * 60)
response = await agent.analyze(query)
print(f"\nAnalysis Result:\n{response}")
print("-" * 60)
await asyncio.sleep(2)


async def demo_interactive():
"""Interactive mode for Neo research."""
print("\n" + "=" * 60)
print("Neo N3 Research Agent - Interactive Mode")
print("Type your Neo-related questions (e.g., 'Check balance of N...', 'Who is in the council?')")
print("Type 'exit' to quit.")
print("=" * 60)

agent = NeoResearchSkillAgent(llm=ChatBot())
await agent.initialize()

while True:
try:
user_input = input("\nYou: ").strip()
if not user_input or user_input.lower() in ['exit', 'quit', 'q']:
break

response = await agent.analyze(user_input)
print(f"\nAgent: {response}")
except KeyboardInterrupt:
break
except Exception as e:
print(f"Error: {e}")

async def main():
# Intelligent LLM Provider selection
from spoon_ai.llm.manager import get_llm_manager
if not (os.getenv("OPENAI_API_KEY") or os.getenv("GEMINI_API_KEY") or os.getenv("OPENROUTER_API_KEY")):
print("Error: No LLM API key found.")
sys.exit(1)

print("\nSelect demo mode:")
print("1. Automatic Demo (3 scenarios)")
print("2. Interactive mode")

choice = input("\nEnter choice (1-2, default=1): ").strip() or "1"

if choice == "1":
await demo_neo_analysis()
else:
await demo_interactive()


if __name__ == "__main__":
asyncio.run(main())

96 changes: 96 additions & 0 deletions examples/skills/neo-query/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: neo-query
description: Comprehensive Neo N3 blockchain data query and analysis skill
version: 1.1.0
author: XSpoonAi Team
tags:
- neo
- n3
- blockchain
- smart-contract
- query
- analytics
triggers:
- type: keyword
keywords:
- neo
- n3
- gas
- antshares
- nep17
- nep11
- neo address
- neo block
- neo transaction
- neo contract
- neo committee
- neo voting
- neo candidates
priority: 95
- type: pattern
patterns:
- "(?i)(query|check|analyze|investigate) .*(neo|gas|n3|nep17|nep11)"
- "(?i)what is the (balance|status|history) of neo address .*"
- "(?i)find (contracts|assets|tokens) on neo .*"
priority: 90
parameters:
- name: address
type: string
required: false
description: The Neo N3 address to query (starts with N)
- name: network
type: string
required: false
default: testnet
description: Neo network (mainnet or testnet)
scripts:
enabled: true
working_directory: ./scripts
definitions:
- name: neo_rpc_query
description: |
Execute various Neo N3 blockchain queries.
Pass a JSON command to stdin.
Supported actions: get_balance, get_address_info, get_block, get_transaction,
get_contract, get_contract_list (use 'contract_name'), get_asset_info (use 'asset_name'),
get_nep17_transfers, get_nep11_transfers, get_candidates, get_committee, get_logs.
type: python
file: neo_rpc_query.py
timeout: 100
---

# Neo Query Skill

You are now in **Neo Blockchain Specialist Mode**. You have access to the full suite of Neo N3 data analysis tools.

## Capabilities
- **Address Analysis**: Balances, transfer history, and transaction counts.
- **Asset & Token Tracking**: NEP-17 (fungible) and NEP-11 (NFT) balances and transfers.
- **Blockchain Exploration**: Block details, rewards, and network status.
- **Contract & Ecosystem**: Smart contract metadata, verified status, and application logs.
- **Governance**: Voting candidates, committee members, and total votes.

## Guidelines
1. **Address Format**: Neo N3 addresses typically start with 'N'.
2. **Network**: Default to `testnet` for safety unless `mainnet` is explicitly requested.
3. **Pagination**: For history or lists, you can suggest a `limit` and `skip`.
4. **Analysis**: Don't just show raw data; explain what the balances or transaction patterns mean for the user.

## Available Scripts

### neo_rpc_query
Execute queries by passing a JSON command via stdin.

**Command Examples:**
- **Balance**: `{"action": "get_address_info", "address": "N..."}`
- **Block**: `{"action": "get_block", "height": 12345}`
- **Transactions**: `{"action": "get_transaction", "hash": "0x..."}`
- **NEP-17 History**: `{"action": "get_nep17_transfers", "address": "N...", "limit": 10}`
- **Contracts**: `{"action": "get_contract_list", "contract_name": "Flamingo"}`
- **Governance**: `{"action": "get_committee"}`

## Example Queries
1. "Analyze the portfolio and recent activity of address N..."
2. "Who are the current Neo council/committee members?"
3. "Check the details and source code verification for contract 0x..."
4. "Search for NEP-17 tokens named 'GAS' or 'USDT' on Neo."
Loading