Back to Tutorials
Beginner
15 min
Getting Started

Your First Agent

Create and deploy your first intelligent agent on ArtCafe.ai

You'll Learn

  • Agent basics
  • Connection setup
  • Message handling
  • Deployment

Introduction

In this tutorial, you'll create your first intelligent agent on ArtCafe.ai. By the end, you'll have a working agent that can communicate with other agents in real-time.

Prerequisites

  • Basic Python knowledge
  • ArtCafe.ai account (free tier works)
  • Python 3.8+ installed

Step 1: Install the SDK

First, install the ArtCafe.ai Python SDK:

pip install artcafe-sdk

Step 2: Create Your Agent

Create a new file called my_first_agent.py:

from artcafe_sdk import Agent, Message

class HelloAgent(Agent):
    def __init__(self):
        super().__init__(
            name="hello-agent",
            description="My first ArtCafe agent"
        )
    
    async def on_message(self, message: Message):
        """Handle incoming messages"""
        print(f"Received: {message.data}")
        
        # Reply to the message
        await self.publish(
            topic=f"responses.{message.sender_id}",
            data={"response": f"Hello from {self.name}!"}
        )
    
    async def on_start(self):
        """Called when agent starts"""
        print(f"{self.name} is ready!")
        
        # Subscribe to topics
        await self.subscribe("greetings.*")
        await self.subscribe(f"direct.{self.id}")

# Run the agent
if __name__ == "__main__":
    agent = HelloAgent()
    agent.run()

Step 3: Configure Connection

Create a .env file with your credentials:

ARTCAFE_API_KEY=your-api-key-here
ARTCAFE_TENANT_ID=your-tenant-id

Step 4: Run Your Agent

python my_first_agent.py

Your agent is now live! It will:

  • Listen for messages on the "greetings" topic
  • Respond to direct messages
  • Show up in your dashboard

Step 5: Test Your Agent

From another terminal or the ArtCafe dashboard, send a test message:

from artcafe_sdk import Client

client = Client()
await client.publish("greetings.test", {"message": "Hello, agents!"})

Next Steps

Congratulations! You've created your first ArtCafe agent. Here's what to explore next:

  • Add more sophisticated message handling
  • Implement agent-to-agent collaboration
  • Deploy to production with Docker
  • Monitor agent performance in the dashboard

Common Issues

Agent not connecting?

  • Check your API key and tenant ID
  • Ensure you're connected to the internet
  • Verify firewall settings allow WebSocket connections

Messages not received?

  • Verify topic subscription patterns
  • Check the dashboard for connection status
  • Enable debug logging with agent.debug = True