Building your AI Agent

Step 1: Define Your Agent's Purpose

Before writing code, clearly define your agent's:

  • Purpose: What value will it provide?

  • Personality: How should it communicate?

  • Target Audience: Who is it for?

  • Content Strategy: What will it post about?

Example: Let's build "DeFi Sage" - an educational agent focused on DeFi concepts

Purpose: Educate users about decentralized finance Personality: Patient, knowledgeable, encouraging Audience: DeFi beginners and intermediate users Content: Explanations, tutorials, market insights, Q&A

Step 2: Create Your Agent Script

Create a new file called my_agent.py:

from xynae import Xynae
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Define your agent's personality
AGENT_PERSONALITY = """
You are DeFi Sage, an educational AI agent dedicated to making decentralized 
finance accessible to everyone. Your mission is to explain complex DeFi concepts 
in simple, digestible terms.

Core traits:
- Patient and encouraging with beginners
- Use analogies to explain technical concepts
- Break down complex topics into simple steps
- Always emphasize security and risk management
- Celebrate learning milestones
- Provide actionable advice

Topics you cover:
- Yield farming and liquidity provision
- Impermanent loss and risk management
- DEX mechanics and automated market makers
- Staking and governance
- Token economics and valuation
- Smart contract security

Communication style:
- Use clear, jargon-free language when possible
- Define technical terms when they're necessary
- Use emojis sparingly for emphasis (πŸ“š πŸ’‘ ⚠️)
- Keep tweets concise and focused
- End educational threads with key takeaways
- Always verify information before sharing
"""

def main():
    print("πŸš€ Initializing DeFi Sage...")
    
    # Initialize the agent
    agent = Xynae(
        personality=AGENT_PERSONALITY,
        llm_provider="auto",  # Automatically selects available provider
        mongodb_uri=os.getenv("MONGODB_URI", "mongodb://localhost:27017/"),
        database_name="defi_sage",
        use_database=True
    )
    
    print("βœ… DeFi Sage initialized successfully!")
    print("πŸ“Š Database:", "Connected" if agent.db.is_connected() else "Disconnected")
    print("πŸ€– LLM Provider:", agent.llm_manager.list_available_providers())
    
    # Run the agent
    print("\n🎯 Starting autonomous operation...")
    print("   - Posting educational content every 20 minutes")
    print("   - Checking mentions every 5 minutes")
    print("\nPress Ctrl+C to stop\n")
    
    agent.run(
        tweet_interval=1200,  # 20 minutes between posts
        check_interval=300    # 5 minutes between mention checks
    )

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\n\nπŸ‘‹ DeFi Sage shutting down gracefully...")
    except Exception as e:
        print(f"\n❌ Error: {e}")
        raise

Step 3: Test Basic Functionality

Before running the full agent, test individual components:

Run the test:

Expected output:

Step 4: Run Your Agent Locally

Start your agent for the first time:

Monitor the output:

Let it run for 30-60 minutes to ensure everything works correctly.


Last updated