This page details the programmatic API provided by the JuliaOS Python wrapper (pip install juliaos).
(Note: This is based on the wrapper's README. Exact method signatures, parameters, and return types should be confirmed by inspecting the wrapper's source code in /packages/python-wrapper/juliaos/ and potentially using type hints or help())
JuliaOS Client
The main entry point for interacting with the JuliaOS backend.
from juliaos import JuliaOSimport asyncioasyncdefmain():# Using async context manager (recommended)asyncwithJuliaOS(host='localhost', port=8052)as client:print("Connected to JuliaOS backend!")# Use other methods... agents =await client.list_agents()print(f"Found {len(agents)} agents.")# Connection is automatically closed when exiting the context# Or using manual connection managementasyncdefalternative(): client =JuliaOS(host='localhost', port=8052)await client.connect()print("Connected to JuliaOS backend!")# Use other methods... agents =await client.list_agents()print(f"Found {len(agents)} agents.")await client.disconnect()# asyncio.run(main())
Key Methods:
__init__(host: str = 'localhost', port: int = 8052, api_key: Optional[str] = None, auto_connect: bool = False): Initializes the client.
connect(): Establishes connection to the backend.
disconnect(): Closes the connection.
__aenter__(), __aexit__(): Async context manager support for cleaner code.
create_agent(name: str, agent_type: str, config: dict) -> Agent: Creates a new agent.
# Assuming 'agent' is an instance obtained from client.get_agent() or client.create_agent()
await agent.start()
status = await agent.get_status()
result = await agent.execute_task("specific_task_name", data={...})
await agent.stop()
# Assuming 'swarm' is an instance obtained from client.get_swarm() or client.create_swarm()
await swarm.start()
status = await swarm.get_status()
await swarm.add_agent(agent_id)
# For optimization swarms:
def objective_func(x):
return sum(xi**2 for xi in x)
opt_result = await swarm.optimize(
objective=objective_func,
iterations=100,
minimize=True
)
print(opt_result.best_solution, opt_result.best_fitness)
await swarm.stop()
from juliaos import JuliaOS
from juliaos.swarms import (
DifferentialEvolution, ParticleSwarmOptimization,
GreyWolfOptimizer, AntColonyOptimization,
GeneticAlgorithm, WhaleOptimizationAlgorithm,
HybridDEPSO
)
async def main():
async with JuliaOS() as juliaos:
# Create algorithm instance
de = DifferentialEvolution(juliaos.bridge)
# Define objective function
def sphere(x):
return sum(xi**2 for xi in x)
# Define bounds
bounds = [(-5.0, 5.0), (-5.0, 5.0)]
# Run optimization
result = await de.optimize(
objective_function=sphere,
bounds=bounds,
config={
"population_size": 30,
"max_generations": 100
}
)
print(f"Best fitness: {result['best_fitness']}")
print(f"Best position: {result['best_position']}")
import numpy as np
from juliaos import JuliaOS
from juliaos.swarms import DifferentialEvolution
# Define objective function using NumPy
def rastrigin(x: np.ndarray) -> float:
return 10 * len(x) + np.sum(x**2 - 10 * np.cos(2 * np.pi * x))
async def main():
async with JuliaOS() as juliaos:
# Create algorithm instance
de = DifferentialEvolution(juliaos.bridge)
# Define bounds as NumPy array
bounds = np.array([[-5.12, 5.12]] * 5) # 5-dimensional problem
# Run optimization
result = await de.optimize(
objective_function=rastrigin,
bounds=bounds,
config={
"population_size": 30,
"max_generations": 100
}
)
# Access result with NumPy arrays
best_position = result['best_position_np'] # NumPy array
best_fitness = result['best_fitness']
print(f"Best position: {best_position}")
print(f"Best fitness: {best_fitness}")
# Assuming 'wallet' is an instance from client.connect_wallet()
balance = await wallet.get_balance()
tx_receipt = await wallet.send_transaction(to='0x...', amount='0.1', token='ETH')
signature = await wallet.sign_message("Hello JuliaOS")