Agentcoin SDK is a high-level framework built on top of Eliza OS for creating autonomous AI agents. It provides a simple yet powerful interface for building, customizing, and deploying AI agents with advanced capabilities.
import { AgentcoinSDK } from 'agentcoin-sdk'
// Initialize the SDK
const sdk = await AgentcoinSDK.start()
// Listen for incoming messages
sdk.on('message', async (event) => {
console.log('New message:', event.text)
return true // continue processing
})
// Register custom actions
sdk.register('action', {
name: 'greet',
execute: async (context) => {
return { text: 'Hello!' }
}
})
Agentcoin SDK is designed to simplify the creation of autonomous AI agents by providing:
- Event-driven architecture for message processing
- Built-in support for LLM interactions
- Extensible plugin system
- Integrated wallet and configuration management
- Robust action handling system
The SDK uses an event system for processing messages and actions:
- message - Triggered when a new message is received
- prellm - Before LLM processing
- postllm - After LLM processing
- preaction - Before action execution
- postaction - After action execution
Providers are modules that supply specific capabilities to your agent:
const customProvider: Provider = {
name: 'custom',
provide: async (context) => {
// Add capabilities
return context
}
}
sdk.register('provider', customProvider)
Actions define specific tasks your agent can perform:
const sendMessageAction: Action = {
name: 'send_message',
execute: async (context) => {
// Perform action
return { text: 'Message sent!' }
}
}
sdk.register('action', sendMessageAction)
Services provide ongoing functionality for your agent:
const monitoringService: Service = {
name: 'monitoring',
start: async () => {
// Start service
},
stop: async () => {
// Stop service
}
}
sdk.register('service', monitoringService)
static start()
: Initialize and start the SDKregister(kind, handler)
: Register a new provider, action, or serviceon(event, handler)
: Subscribe to SDK eventsoff(event, handler)
: Unsubscribe from SDK events
// Message event
sdk.on('message', async (event: NewMessageEvent) => {
// Handle new message
return true // continue processing
})
// Pre-LLM processing
sdk.on('prellm', async (context: Context) => {
// Modify context before LLM
return true // continue processing
})
// Post-LLM processing
sdk.on('postllm', async (context: Context) => {
// Handle LLM response
return true // continue processing
})
// Pre-action execution
sdk.on('preaction', async (context: Context) => {
// Prepare for action
return true // continue processing
})
// Post-action execution
sdk.on('postaction', async (context: Context) => {
// Handle action results
return true // continue processing
})
const sdk = await AgentcoinSDK.start()
// Pre-process messages
sdk.on('message', async (event) => {
if (event.text.includes('sensitive')) {
return false // stop processing
}
return true
})
// Modify context before LLM
sdk.on('prellm', async (context) => {
context.state.customData = { processed: true }
return true
})
// Handle LLM response
sdk.on('postllm', async (context) => {
if (!context.content.text) {
return false // stop if no response
}
return true
})
class AnalyticsService implements Service {
name = 'analytics'
async start() {
// Initialize analytics
}
async stop() {
// Cleanup
}
async track(event: string, data: any) {
// Track events
}
}
sdk.register('service', new AnalyticsService())
-
Event Chain Management
- Always return boolean values from event handlers
- Use early returns to prevent unnecessary processing
- Keep handlers focused and simple
-
Error Handling
- Implement proper error handling in all handlers
- Use try-catch blocks for async operations
- Log errors appropriately
-
Resource Management
- Clean up resources in service stop methods
- Implement proper shutdown handlers
- Monitor memory usage in long-running operations
We welcome contributions!