LogoLogo
  • JuliaOS Documentation Hub
  • About JuliaOS
    • Mission & Vision
    • Features and Capabilities
    • Roadmap
    • Tokenomics
  • Ecosystem
    • Overview
  • Partners
    • Heurist
    • Fetch.ai
    • Soulgraph
    • cheqd.io
    • Aethir
    • Anyone
    • TensorLabs
    • Hashpower
  • Technology
    • Overview
    • Open Source
      • Modular Framework
      • CLI Mode
    • AI Platform
      • Dashboard
      • Agent Management
      • Swarm Management
      • Marketplace
      • Mining
    • LLM
    • Launchpad
    • Robotics & IOT
      • SwarmIOT
      • Modular AI with Robotics
        • J3OS MiniLLM
          • 🔧 Use Cases
  • Technical
    • Overview
    • Developer Hub
      • Getting Started
        • Installation Guide
          • Github Guide
        • Basic Concepts
        • Quick Start Guide
          • Handling secrets
        • Examples and Use
          • Example: Using the Trading Functionality
          • Example: Using the Benchmarking Feature
          • Example: Multi-Agent Swarm Coordination
          • Example: Using the Python Wrapper for LLM Integration
          • Example: Using Cross-Chain Bridges
          • Example: Creating and Running a Swarm Optimization
          • Page 4
      • Best Practices
        • Performance Tuning
        • Agent/Swarm Design Patterns
        • Best Practices & Patterns
        • Security Best Practices
      • CLI
        • JuliaOS CLI Interface
        • Agent Management (CLI)
        • CLI Configuration
        • Cross-Chain Hub (CLI)
        • Swarm Management (CLI)
        • CLI Troubleshooting
        • Wallet Management (CLI)
      • Framework SDK
        • Modules
          • Bridge
          • Agents Module
          • Dex
          • Swarms Module
          • Wallet
        • Python Wrapper
          • LangChain Integration
          • Python Wrapper
      • Contributing Guide
      • Extending JuliaOS
      • Development Setup & Conventions
      • Testing & Debugging
      • Troubleshooting
    • Architecture
      • High Level JuliaOS
      • CLI <-> Backend Communication
      • Data Storage Architecture
      • Framework Internals
      • Architecture Deep Dive
        • Architectual Notes
    • Concepts
      • Core Features & Concepts
      • Agents
        • Agent Skills & Specializations
      • Swarms
      • Neural Networks
      • Blockchains & Chains
      • Bridges (Cross-Chain)
      • Integrations
        • Google ADK
        • LLMs
        • Price Feed
        • DEX Integration
      • Storage
      • Trading Capabilities
      • Use Cases
      • Wallets
      • Portfolio Optimization
  • Research
    • JuliaOS Research
  • API Documentation
    • API Reference
      • API Reference: Julia Backend Commands
      • API Reference: CLI Commands
      • API Reference: Node.js API
      • API Reference: Python API
      • API Reference
  • Community
    • Community & Support
  • FAQ
    • General
    • Technical
    • Community
Powered by GitBook
On this page
Export as PDF
  1. Technical
  2. Developer Hub
  3. Getting Started
  4. Examples and Use

Example: Using the Python Wrapper for LLM Integration

Example: Using the Python Wrapper for LLM Integration

import asyncio
from juliaos import JuliaOS
from juliaos.llm import OpenAIProvider, ClaudeProvider, MistralProvider
from juliaos.langchain import JuliaOSToolkit

async def use_llm_integration():
    # Initialize JuliaOS
    juliaos_client = JuliaOS(host="localhost", port=8052)
    await juliaos_client.connect()

    # Create an LLM provider (choose one)
    openai_llm = OpenAIProvider(api_key="your_openai_api_key", model="gpt-4")
    claude_llm = ClaudeProvider(api_key="your_anthropic_api_key", model="claude-3-opus-20240229")
    mistral_llm = MistralProvider(api_key="your_mistral_api_key", model="mistral-large-latest")

    # Use the OpenAI provider for this example
    llm = openai_llm

    # Create a swarm using the LLM for guidance
    swarm = await juliaos_client.swarms.create_swarm(
        name="LLM-Guided Swarm",
        algorithm="PSO",
        config={
            "llm_provider": "openai",
            "llm_guidance": True,
            "population_size": 30,
            "adaptive_parameters": True
        }
    )

    # Run an optimization with LLM guidance
    result = await juliaos_client.swarms.run_optimization(
        swarm_id=swarm["id"],
        objective_function="function(x) return sum(x.^2) end",
        parameters={
            "bounds": [(-10, 10), (-10, 10), (-10, 10)],
            "max_iterations": 100,
            "llm_feedback_frequency": 10  # Get LLM feedback every 10 iterations
        }
    )

    print(f"Best position: {result['best_position']}")
    print(f"Best fitness: {result['best_fitness']}")
    print(f"LLM guidance: {result['llm_guidance_summary']}")

    # Create a LangChain toolkit
    toolkit = JuliaOSToolkit(juliaos_client)

    # Use the toolkit with LangChain
    from langchain.agents import initialize_agent, AgentType
    agent = initialize_agent(
        tools=toolkit.get_tools(),
        llm=llm.get_llm(),
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        verbose=True
    )

    # Run the agent
    response = await agent.arun("Create a trading agent and execute a trade on Uniswap.")
    print(f"Agent response: {response}")

    await juliaos_client.disconnect()

# Run the async function
asyncio.run(use_llm_integration())

The Python wrapper provides comprehensive LLM integration capabilities:

  • Multiple LLM Providers: Support for OpenAI, Claude, Mistral, Cohere, Gemini, and local models

  • LangChain Integration: Full integration with LangChain for agent creation and tool usage

  • LLM-Guided Optimization: Use LLMs to guide swarm optimization algorithms

  • Agent Specialization: Create specialized agents with LLM-powered decision making

  • Natural Language Interfaces: Interact with JuliaOS using natural language

  • Hybrid Intelligence: Combine swarm intelligence with LLM capabilities

PreviousExample: Multi-Agent Swarm CoordinationNextExample: Using Cross-Chain Bridges

Last updated 1 month ago