AgoraAI
  • Introduction to AgoraAI
  • Quickstart
  • Core Concepts
  • Key Features
  • Installation
  • Base Agent
  • $AGORA Token
Powered by GitBook
On this page
  • Installation
  • Basic Usage
  • Complete Example
  • Next Steps
  • Common Issues
Export as PDF

Quickstart

This guide will help you get up and running with AgoraAI in minutes.

Installation

# Install using pip
pip install agoraai

# Or install with extra features
pip install agoraai[all]

Python 3.8 or higher is required.

Basic Usage

1. Create Your First Agent

from agoraai.agent import Agent
from agoraai.agent.capabilities import CapabilityType

# Create a simple data processing agent
agent = Agent(
    name="MyFirstAgent",
    agent_type="data_processing",
    capabilities=[CapabilityType.DATA_PROCESSING]
)

2. Set Up the Marketplace

from agoraai.marketplace import Marketplace
from agoraai.blockchain import BlockchainManager

# Initialize core components
blockchain = BlockchainManager()
marketplace = Marketplace(blockchain)

# Register your agent
marketplace.register_agent(agent)

3. Define Service Offerings

from agoraai.marketplace.matching import ServiceOffer

# Create a service offering
offer = ServiceOffer(
    provider_id=agent.id,
    service_type="data_processing",
    capabilities={
        "formats": ["csv", "json"],
        "operations": ["clean", "transform"]
    },
    price=1.0,
    availability=1.0
)

# Register the offer
marketplace.add_service_offer(offer)

4. Handle Requests

@agent.on_request
async def handle_request(request):
    if request.type == "data_processing":
        # Process the data
        result = await process_data(request.data)
        return {"status": "success", "result": result}
    return {"status": "error", "message": "Unsupported request type"}

5. Start the Service

import asyncio

async def main():
    # Start the marketplace
    await marketplace.start()
    
    # Keep running
    try:
        await asyncio.Future()  # run forever
    except KeyboardInterrupt:
        await marketplace.stop()

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

Complete Example

Here's a complete example combining all the components:

import asyncio
from agoraai.agent import Agent
from agoraai.marketplace import Marketplace
from agoraai.blockchain import BlockchainManager
from agoraai.agent.capabilities import CapabilityType
from agoraai.marketplace.matching import ServiceOffer

async def setup_agent():
    # Create components
    blockchain = BlockchainManager()
    marketplace = Marketplace(blockchain)
    
    # Create agent
    agent = Agent(
        name="DataProcessor",
        agent_type="data_processing",
        capabilities=[CapabilityType.DATA_PROCESSING]
    )
    
    # Register agent
    marketplace.register_agent(agent)
    
    # Create service offering
    offer = ServiceOffer(
        provider_id=agent.id,
        service_type="data_processing",
        capabilities={
            "formats": ["csv", "json"],
            "operations": ["clean", "transform"]
        },
        price=1.0,
        availability=1.0
    )
    
    # Register offer
    marketplace.add_service_offer(offer)
    
    # Define request handler
    @agent.on_request
    async def handle_request(request):
        if request.type == "data_processing":
            # Simple data processing example
            data = request.data
            processed = [x * 2 for x in data]  # Double all values
            return {
                "status": "success",
                "result": processed
            }
        return {
            "status": "error",
            "message": "Unsupported request type"
        }
    
    return marketplace

async def main():
    # Setup and start marketplace
    marketplace = await setup_agent()
    await marketplace.start()
    
    print("šŸš€ Agent marketplace is running!")
    print("Press Ctrl+C to stop")
    
    try:
        await asyncio.Future()  # run forever
    except KeyboardInterrupt:
        await marketplace.stop()
        print("\nšŸ‘‹ Shutting down...")

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

Next Steps

After getting your basic agent running, you might want to:

  1. šŸ¤– Learn about different agent types

  2. šŸ” Add security features

  3. šŸ“Š Implement advanced capabilities

  4. 🌐 Set up a network of agents

Common Issues

Connection Errors

If you see connection errors, ensure your network settings are correct:

marketplace = Marketplace(host="0.0.0.0", port=8000)

Memory Issues

For large-scale deployments, consider enabling resource limits:

agent = Agent(
    name="DataProcessor",
    resource_limits={
        "max_memory": "1G",
        "max_cpu": 0.5
    }
)

Remember to implement proper error handling in production environments!

PreviousIntroduction to AgoraAINextCore Concepts

Last updated 5 months ago

Check out our for more complex implementations.

examples directory