Building your AI Agent
Step 1: Define Your Agent's Purpose
Step 2: Create Your Agent Script
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}")
raiseStep 3: Test Basic Functionality
Step 4: Run Your Agent Locally
Last updated