This guide will help you get started with JuliaOS by walking you through the process of creating and running a simple agent and swarm.
Starting the JuliaOS Server
Before you can use JuliaOS, you need to start the Julia backend server:
cd /path/to/JuliaOS
julia julia/julia_server.jl
This will start the JuliaOS server on port 8052 by default.
Using the CLI
JuliaOS provides an interactive CLI for managing agents and swarms:
cd /path/to/JuliaOS
node packages/cli/interactive.cjs
This will start the interactive CLI, which provides a menu-based interface for creating and managing agents, swarms, wallets, and more.
Using the Julia API
Creating an Agent
using JuliaOS.Agents
# Create a trading agent
agent = Agents.create_agent(
"TradingAgent",
"trading",
Dict("risk_tolerance" => "medium", "max_position_size" => 1000)
)
# Start the agent
Agents.start_agent(agent["id"])
# Execute a task with the agent
task_result = Agents.execute_task(
agent["id"],
Dict(
"action" => "analyze_market",
"market" => "crypto",
"timeframe" => "1d"
)
)
println("Task result: ", task_result)
Creating a Swarm
using JuliaOS.Swarms
# Create a swarm
swarm = Swarms.create_swarm(
"OptimizationSwarm",
"DE",
Dict("population_size" => 50, "crossover_rate" => 0.8, "mutation_factor" => 0.5)
)
# Run optimization
result = Swarms.run_optimization(
swarm["id"],
"function(x) return sum(x.^2) end",
[], # constraints
Dict("bounds" => [(-10, 10), (-10, 10), (-10, 10)], "max_iterations" => 100)
)
println("Optimization result: ", result)
Using the TypeScript Framework
Creating an Agent
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 framework modules
const agents = new Agents(bridge);
// Create an agent
const agent = await agents.createAgent({
name: 'TradingAgent',
type: 'trading',
config: { risk_tolerance: 'medium', max_position_size: 1000 }
});
// Start the agent
await agents.startAgent(agent.id);
// Execute a task with the agent
const taskResult = await agents.executeTask(agent.id, {
action: 'analyze_market',
market: 'crypto',
timeframe: '1d'
});
console.log('Task result:', taskResult);
Creating a Swarm
import { JuliaBridge } from '@juliaos/julia-bridge';
import { Swarms } from '@juliaos/framework';
// Initialize the bridge
const bridge = new JuliaBridge({ host: 'localhost', port: 8052 });
await bridge.initialize();
// Create framework modules
const swarms = new Swarms(bridge);
// Create a swarm
const swarm = await swarms.createSwarm({
name: 'OptimizationSwarm',
algorithm: 'DE',
config: {
population_size: 50,
crossover_rate: 0.8,
mutation_factor: 0.5
}
});
// Run optimization
const result = await swarms.runOptimization(
swarm.id,
'function(x) return sum(x.^2) end',
[], // constraints
{
bounds: [[-10, 10], [-10, 10], [-10, 10]],
max_iterations: 100
}
);
console.log('Optimization result:', result);
Using the Python Wrapper
Creating an Agent
import asyncio
from juliaos import JuliaOS
from juliaos.agents import AgentType
async def main():
# Initialize JuliaOS
juliaos_client = JuliaOS(host="localhost", port=8052)
await juliaos_client.connect()
# Create an agent
agent = await juliaos_client.agents.create_agent(
name="TradingAgent",
agent_type=AgentType.TRADING,
config={
"parameters": {
"risk_tolerance": 0.5,
"max_position_size": 1000.0,
"take_profit": 0.05,
"stop_loss": 0.03
}
}
)
# Start the agent
await agent.start()
# Execute a task with the agent
task_result = await agent.execute_task({
"action": "analyze_market",
"market": "crypto",
"timeframe": "1d"
})
print("Task result:", task_result)
# Disconnect from JuliaOS
await juliaos_client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
Creating a Swarm
import asyncio
from juliaos import JuliaOS
from juliaos.swarms import SwarmType
async def main():
# Initialize JuliaOS
juliaos_client = JuliaOS(host="localhost", port=8052)
await juliaos_client.connect()
# Create a swarm
swarm = await juliaos_client.swarms.create_swarm(
name="OptimizationSwarm",
swarm_type=SwarmType.OPTIMIZATION,
algorithm="DE",
dimensions=3,
bounds=[(-10.0, 10.0)] * 3,
config={
"population_size": 50,
"max_generations": 100,
"crossover_probability": 0.8,
"differential_weight": 0.5
}
)
# Register an objective function
function_id = "sphere"
await juliaos_client.swarms.set_objective_function(
function_id=function_id,
function_code="function(x) return sum(x.^2) end",
function_type="julia"
)
# Run optimization
optimization_result = await swarm.run_optimization(
function_id=function_id,
max_iterations=100,
max_time_seconds=60,
tolerance=1e-6
)
print("Optimization result:", optimization_result)
# Disconnect from JuliaOS
await juliaos_client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
Using LangChain Integration (Python)
import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor
from langchain.chains import LLMChain
from langchain.prompts import ChatPromptTemplate
from juliaos import JuliaOS
from juliaos.agents import AgentType
from juliaos.langchain import (
JuliaOSTradingAgentAdapter,
SwarmOptimizationTool,
BlockchainQueryTool
)
async def main():
# Load environment variables
load_dotenv()
# Initialize JuliaOS
juliaos_client = JuliaOS(host="localhost", port=8052)
await juliaos_client.connect()
# Create a trading agent
agent = await juliaos_client.agents.create_agent(
name="LangChainTradingAgent",
agent_type=AgentType.TRADING,
config={
"parameters": {
"risk_tolerance": 0.5,
"max_position_size": 1000.0
}
}
)
# Start the agent
await agent.start()
# Create a LangChain adapter for the agent
llm = ChatOpenAI(temperature=0.7)
agent_adapter = JuliaOSTradingAgentAdapter(agent)
# Create tools
tools = [
SwarmOptimizationTool(bridge=juliaos_client.bridge),
BlockchainQueryTool(bridge=juliaos_client.bridge)
]
# Create a LangChain agent
langchain_agent = agent_adapter.as_langchain_agent(
llm=llm,
tools=tools,
verbose=True
)
# Run the agent
result = await langchain_agent.arun(
"Analyze the current market conditions for Ethereum and suggest a trading strategy."
)
print("LangChain agent result:", result)
# Disconnect from JuliaOS
await juliaos_client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
Next Steps
Now that you've learned the basics of JuliaOS, you can explore the following topics:
Basic Concepts - Learn about the core concepts of JuliaOS
Agents - Learn more about agents and their capabilities
Swarms - Learn more about swarms and swarm algorithms
Blockchain - Learn about blockchain integration
Wallet - Learn about wallet management
Storage - Learn about storage options