The Agents module in the JuliaOS framework provides a comprehensive interface for creating, managing, and interacting with agents. This page explains how to use the Agents module in your applications.
Overview
The Agents module connects to the Julia backend through the JuliaBridge and provides methods for creating, retrieving, starting, stopping, and executing tasks with agents. It also includes specialized agent types for specific use cases.
Installation
Copy npm install @juliaos/framework
Usage
Initializing the Agents Module
Copy import { JuliaBridge } from '@juliaos/julia-bridge';
import { Agents } from '@juliaos/framework';
// Initialize the bridge
const bridge = new JuliaBridge({ host: 'localhost', port: 8052 });
await bridge.initialize();
// Create the Agents module
const agents = new Agents(bridge);
Creating an Agent
Copy const agent = await agents.createAgent({
name: 'MyAgent',
type: 'trading',
config: {
risk_tolerance: 'medium',
max_position_size: 1000,
take_profit: 0.05,
stop_loss: 0.03,
trading_pairs: ['ETH/USDC', 'BTC/USDC'],
strategies: ['momentum', 'mean_reversion']
}
});
console.log('Created agent:', agent);
Starting an Agent
Copy await agents.startAgent(agent.id);
console.log('Agent started');
Executing a Task with an Agent
Copy const taskResult = await agents.executeTask(agent.id, {
action: 'analyze_market',
market: 'crypto',
timeframe: '1d'
});
console.log('Task result:', taskResult);
Getting Agent Status
Copy const status = await agents.getAgentStatus(agent.id);
console.log('Agent status:', status);
Stopping an Agent
Copy await agents.stopAgent(agent.id);
console.log('Agent stopped');
Listing Agents
Copy const allAgents = await agents.listAgents();
console.log('All agents:', allAgents);
// Filter by type
const tradingAgents = await agents.listAgents({ type: 'trading' });
console.log('Trading agents:', tradingAgents);
// Filter by status
const runningAgents = await agents.listAgents({ status: 'running' });
console.log('Running agents:', runningAgents);
Deleting an Agent
Copy await agents.deleteAgent(agent.id);
console.log('Agent deleted');
Specialized Agent Types
The framework includes specialized agent types for specific use cases:
Trading Agents
Copy import { TradingAgent } from '@juliaos/framework';
const tradingAgent = await TradingAgent.create(agents, {
name: 'MyTradingAgent',
risk_level: 'medium',
max_position_size: 1000,
take_profit: 0.05,
stop_loss: 0.03,
trading_pairs: ['ETH/USDC', 'BTC/USDC'],
strategies: ['momentum', 'mean_reversion']
});
// Execute a trade
const tradeResult = await tradingAgent.executeTrade({
pair: 'ETH/USDC',
side: 'buy',
amount: 0.1,
price: 2000,
type: 'limit'
});
// Get portfolio
const portfolio = await tradingAgent.getPortfolio();
Research Agents
Copy import { ResearchAgent } from '@juliaos/framework';
const researchAgent = await ResearchAgent.create(agents, {
name: 'MyResearchAgent',
research_areas: ['market', 'technology', 'sentiment'],
data_sources: ['web', 'api', 'database'],
analysis_methods: ['statistical', 'nlp', 'trend'],
output_formats: ['text', 'json', 'chart']
});
// Conduct research
const researchResult = await researchAgent.conductResearch({
topic: 'Ethereum Layer 2 Solutions',
depth: 'medium',
focus: ['technology', 'adoption', 'performance'],
timeframe: 'last_6_months',
sources: ['academic', 'news', 'social_media']
});
Dev Agents
Copy import { DevAgent } from '@juliaos/framework';
const devAgent = await DevAgent.create(agents, {
name: 'MyDevAgent',
languages: ['python', 'javascript', 'julia'],
frameworks: ['react', 'tensorflow', 'flask'],
specialties: ['web', 'ai', 'blockchain'],
code_style: 'clean'
});
// Write code
const codeResult = await devAgent.writeCode({
description: 'Create a simple React component that displays cryptocurrency prices',
language: 'javascript',
framework: 'react',
requirements: [
'Fetch data from CoinGecko API',
'Display prices for BTC, ETH, and SOL',
'Update prices every 30 seconds',
'Include error handling'
]
});
// Review code
const reviewResult = await devAgent.reviewCode({
content: '/* code to review */',
language: 'javascript',
framework: 'react'
});
Agent Memory
Agents have memory capabilities that allow them to store and retrieve information:
Copy // Set memory
await agents.setAgentMemory(agent.id, 'key', 'value');
// Get memory
const value = await agents.getAgentMemory(agent.id, 'key');
// Delete memory
await agents.deleteAgentMemory(agent.id, 'key');
Error Handling
The Agents module includes robust error handling:
Copy try {
const agent = await agents.createAgent({
name: 'MyAgent',
type: 'trading',
config: { /* ... */ }
});
} catch (error) {
console.error('Failed to create agent:', error);
}
See Also
Swarms Module - Learn about swarms and how to use them with agents
Bridge Module - Learn about the bridge that connects to the Julia backend
Wallet Module - Learn about wallet management
Blockchain Module - Learn about blockchain integration