Skip to content

no-ai-labs/spice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒถ๏ธ Spice

Production-Ready Multi-Agent Framework for the JVM.
Intelligent agent swarms, dynamic flow strategies, and enterprise-grade LLM orchestration โ€” built for Kotlin, designed for scale.


โœจ What is Spice?

Spice is a production-ready multi-agent orchestration framework for the JVM, enabling intelligent, collaborative agent workflows across local and cloud-hosted LLMs.

From simple agent interactions to complex swarm intelligence, Spice provides the building blocks for scalable, maintainable agent systems that integrate seamlessly with modern JVM ecosystems.

๐Ÿค– Think CrewAI, but type-safe and JVM-native.
โšก Think AutoGen, but with Kotlin coroutines.
๐ŸŽฏ Think intelligent routing, dynamic strategies, and production reliability.


๐ŸŒŒ Key Features

๐Ÿค– Intelligent Agent Swarms

  • SwarmAgent โ€” Coordinate multiple agents with dynamic strategy selection
  • Flow Strategies โ€” SEQUENTIAL, PARALLEL, COMPETITION, PIPELINE execution modes
  • Capability Matching โ€” Automatic agent selection based on task requirements
  • Fallback & Retry โ€” Production-grade error handling and resilience

๐Ÿ”„ Advanced Flow Control

  • MultiAgentFlow โ€” High-performance agent orchestration with strategy optimization
  • Message Routing โ€” Context-aware routing with comprehensive metadata
  • Dynamic Strategy Resolution โ€” Runtime strategy selection based on message content
  • Thread-Safe Execution โ€” Concurrent processing with CopyOnWriteArrayList pools

๐ŸŽฏ Enterprise LLM Integration

  • OpenAI GPT-4/3.5 โ€” Full API support with function calling and vision
  • Anthropic Claude โ€” Claude-3.5-Sonnet with tool use and 200K context
  • Google Vertex AI โ€” Gemini Pro with multimodal capabilities
  • vLLM High-Performance โ€” Local deployment with batch optimization
  • OpenRouter Multi-Provider โ€” Single API key for 50+ models from multiple providers
  • Unified Interface โ€” Switch providers without changing code

๐Ÿง™โ€โ™‚๏ธ Intelligent Agent Patterns

  • WizardAgent โ€” One-shot intelligence upgrade for complex tasks
  • Dynamic Model Switching โ€” Runtime model selection based on task complexity
  • Cost Optimization โ€” Automatic model selection for optimal price/performance
  • Context Preservation โ€” Seamless intelligence scaling without losing conversation state

๐Ÿ” Vector & RAG Support

  • VectorStore Interface โ€” Qdrant, Pinecone, Weaviate support
  • Smart Filtering โ€” Advanced metadata filtering with DSL
  • Embedding Integration โ€” Automatic text-to-vector conversion
  • RAG Workflows โ€” Retrieval-augmented generation patterns

โš™๏ธ Production Features

  • Spring Boot Starter โ€” Zero-config integration with autoconfiguration
  • Comprehensive Testing โ€” 90%+ test coverage with MockK integration
  • Observability โ€” Rich metadata and execution tracking
  • Type Safety โ€” Full Kotlin type system with coroutine support

๐Ÿš€ Quick Start

1. Add Dependencies

// build.gradle.kts
implementation("io.github.spice:spice-core:0.1.0-SNAPSHOT")
implementation("io.github.spice:spice-springboot:0.1.0-SNAPSHOT") // For Spring Boot

2. Create Your First Agent

import io.github.spice.*

// Create an OpenAI agent
val summarizer = OpenAIAgent(
    id = "summarizer",
    name = "Document Summarizer", 
    apiKey = "your-openai-key",
    model = "gpt-4",
    maxTokens = 1000
)

// Process a message
val response = summarizer.processMessage(
    Message(
        content = "Summarize this article about Kotlin coroutines...",
        sender = "user"
    )
)

println(response.content)

3. OpenRouterAgent for Multi-Provider Access

// Single API key for multiple LLM providers
val multiModelAgent = OpenRouterAgent(
    id = "multi-agent",
    name = "Multi-Provider Agent",
    apiKey = "your-openrouter-key",
    model = "anthropic/claude-3.5-sonnet", // or "openai/gpt-4", "google/gemini-pro", etc.
    maxTokens = 1000
)

// Process with any supported model
val response = multiModelAgent.processMessage(
    Message(
        content = "Analyze this code for security issues",
        sender = "user"
    )
)

// Dynamic model switching
val gptAgent = multiModelAgent.withModel("openai/gpt-4")
val claudeAgent = multiModelAgent.withModel("anthropic/claude-3.5-sonnet")

// Get available models
val availableModels = multiModelAgent.getAvailableModels()
println("Available models: ${availableModels.size}")

4. WizardAgent for One-Shot Intelligence Upgrade

// Create normal and wizard agents
val normalAgent = OpenRouterAgent(
    apiKey = "your-openrouter-key",
    model = "google/bison-001" // Fast, cost-effective
)

val wizardAgent = OpenRouterAgent(
    apiKey = "your-openrouter-key", 
    model = "anthropic/claude-3.5-sonnet" // High-intelligence
)

// Create WizardAgent that upgrades when needed
val wizard = WizardAgent(
    id = "shape-shifter",
    name = "Shape-Shifting Agent",
    normalAgent = normalAgent,
    wizardAgent = wizardAgent
)

// Simple question - uses normal mode
val simpleResponse = wizard.processMessage(
    Message(content = "What's the weather like?", sender = "user")
)
require(simpleResponse.metadata["wizard_mode"] == "false")

// Complex request - automatically upgrades to wizard mode!
val complexResponse = wizard.processMessage(
    Message(content = "Create a detailed system architecture diagram for a microservices platform", sender = "user")
)
require(complexResponse.metadata["wizard_mode"] == "true")

// Factory method for easy creation
val easyWizard = WizardAgentFactory.createOpenRouterWizard(
    apiKey = "your-openrouter-key",
    normalModel = "google/bison-001",
    wizardModel = "anthropic/claude-3.5-sonnet"
)

5. SwarmAgent for Team Coordination

// Create specialized agents
val researcher = OpenAIAgent("researcher", "Research Agent", apiKey, "gpt-4")
val writer = OpenAIAgent("writer", "Content Writer", apiKey, "gpt-4") 
val reviewer = AnthropicAgent("reviewer", "Content Reviewer", claudeKey, "claude-3-5-sonnet")

// Create a coordinated swarm
val contentTeam = SwarmAgent(
    id = "content-team",
    name = "Content Creation Team",
    description = "Collaborative content creation swarm"
).apply {
    addToPool(researcher)
    addToPool(writer)
    addToPool(reviewer)
    
    // Dynamic strategy based on content
    setStrategyResolver { message, agents ->
        when {
            message.content.contains("research") -> FlowStrategy.PIPELINE
            message.content.contains("quick") -> FlowStrategy.COMPETITION
            else -> FlowStrategy.SEQUENTIAL
        }
    }
}

// Execute with team coordination
val result = contentTeam.processMessage(
    Message(content = "Create a technical blog post about Kotlin coroutines")
)

4. MultiAgentFlow for Advanced Orchestration

// High-performance multi-agent execution
val flow = MultiAgentFlow(FlowStrategy.PARALLEL).apply {
    addAgent(OpenAIAgent("gpt4", "GPT-4 Agent", apiKey))
    addAgent(AnthropicAgent("claude", "Claude Agent", claudeKey))
    addAgent(VertexAgent("gemini", "Gemini Agent", projectId, location, token))
}

// Process with parallel execution
val message = Message(content = "Analyze this code for performance issues")
val result = flow.process(message)

// Rich metadata available
println("Winner: ${result.metadata["winnerId"]}")
println("Strategy: ${result.metadata["strategy"]}")
println("Execution time: ${result.metadata["executionTimeMs"]}ms")

5. Vector Store Integration

// Create a vector store for RAG
val vectorStore = VectorStoreFactory.createQdrant(
    host = "localhost",
    port = 6333
)

// Create collection
vectorStore.createCollection(
    collectionName = "documents",
    vectorSize = 384,
    distance = DistanceMetric.COSINE
)

// Store vectors with metadata
val documents = listOf(
    VectorDocument(
        id = "doc1",
        vector = embeddings, // Your embedding vector
        metadata = mapOf(
            "title" to JsonPrimitive("Kotlin Guide"),
            "category" to JsonPrimitive("programming")
        )
    )
)

vectorStore.upsert("documents", documents)

// Search with filtering
val results = vectorStore.search(
    collectionName = "documents",
    queryVector = queryEmbedding,
    topK = 5,
    filter = buildFilter {
        equals("category", "programming")
        range("score", min = 0.8f)
    }
)

6. Spring Boot Integration

@SpringBootApplication
@EnableSpice
class SpiceApplication

@RestController
class AgentController(private val contentTeam: SwarmAgent) {
    
    @PostMapping("/generate")
    suspend fun generateContent(@RequestBody request: ContentRequest): ContentResponse {
        val message = Message(content = request.prompt, sender = "api")
        val result = contentTeam.processMessage(message)
        
        return ContentResponse(
            content = result.content,
            agent = result.metadata["processedBy"] ?: "unknown",
            executionTime = result.metadata["executionTimeMs"]
        )
    }
}

๐Ÿ“– Core Concepts

Agents

Agents are the core units of work in Spice. They receive messages, process them, and send responses.

Messages

Structured communication between agents with typed content and metadata.

Tools

Reusable functions that agents can use to perform specific tasks.

Routing

Intelligent message routing based on agent capabilities, content analysis, and load balancing.

Personas

Personality and communication styles that can be applied to agents.


๏ฟฝ๏ฟฝ Configuration

Spring Boot Integration

# application.yml
spice:
  agents:
    openai:
      api-key: ${OPENAI_API_KEY}
      model: gpt-4
    anthropic:
      api-key: ${ANTHROPIC_API_KEY}
      model: claude-3-sonnet
  routing:
    default-strategy: confidence
    load-balancing: enabled

Programmatic Configuration

@Configuration
class SpiceConfig {
    
    @Bean
    fun agentEngine(): AgentEngine {
        val engine = AgentEngine()
        
        // Register agents
        engine.registerAgent(OpenAIAgent("gpt-agent", ...))
        engine.registerAgent(AnthropicAgent("claude-agent", ...))
        
        return engine
    }
    
    @Bean
    fun pluginManager(engine: AgentEngine): PluginManager {
        val manager = createPluginManager(engine)
        
        // Load plugins
        manager.loadPlugin(WebhookPlugin())
        manager.loadPlugin(LoggingPlugin())
        manager.activateAllPlugins()
        
        return manager
    }
}

๐Ÿ“š Examples

Simple Q&A Agent

val qaAgent = OpenAIAgent("qa-bot",
    name = "Q&A Assistant",
    description = "Answers questions about documentation"
)

val response = engine.receive(
    Message(
        sender = "user",
        receiver = "qa-bot",
        content = "How do I create a new agent?"
    )
)

Multi-Step Workflow

val workflow = buildToolChain("document-processing", "Process documents end-to-end") {
    step("pdf-extractor") {
        mapParameter("file_path", "input_file")
        mapOutput("extracted_text", "raw_text")
    }
    step("text-cleaner") {
        mapParameter("text", "raw_text")
        mapOutput("cleaned_text", "processed_text")
    }
    step("summarizer") {
        mapParameter("content", "processed_text")
    }
}

val result = toolRunner.executeChain(workflow, mapOf(
    "input_file" to "/path/to/document.pdf"
))

Agent with Custom Persona

val supportAgent = OpenAIAgent("support", ...)
    .withPersona(PersonaLibrary.PROFESSIONAL_ASSISTANT)

// The agent will now respond with a professional, helpful tone

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Agent Engine  โ”‚โ”€โ”€โ”€โ”€โ”‚  Message Router โ”‚โ”€โ”€โ”€โ”€โ”‚  Plugin Manager โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ–ผ                       โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Agents      โ”‚    โ”‚   Routing Rules โ”‚    โ”‚    Plugins      โ”‚
โ”‚  - OpenAI       โ”‚    โ”‚  - Keyword      โ”‚    โ”‚  - Webhook      โ”‚
โ”‚  - Anthropic    โ”‚    โ”‚  - Confidence   โ”‚    โ”‚  - Logging      โ”‚
โ”‚  - Custom       โ”‚    โ”‚  - Load Balance โ”‚    โ”‚  - Custom       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ–ผ                       โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Tools       โ”‚    โ”‚    Personas     โ”‚    โ”‚   Tool Chains   โ”‚
โ”‚  - File I/O     โ”‚    โ”‚  - Friendly     โ”‚    โ”‚  - Validation   โ”‚
โ”‚  - Web Search   โ”‚    โ”‚  - Professional โ”‚    โ”‚  - Processing   โ”‚
โ”‚  - Custom       โ”‚    โ”‚  - Sarcastic    โ”‚    โ”‚  - Analysis     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿงช Testing

class SpiceTest {
    @Test
    fun testAgentCommunication() {
        val engine = AgentEngine()
        val agent = MockAgent("test-agent")
        engine.registerAgent(agent)
        
        val result = engine.receive(
            Message(sender = "test", receiver = "test-agent", content = "Hello")
        )
        
        assert(result.success)
        assert(result.response.content.isNotEmpty())
    }
}

๐Ÿ“ฆ Modules

Module Description Status
spice-core Multi-agent orchestration, SwarmAgent, VectorStore โœ… Production Ready
spice-springboot AutoConfiguration, Spring Boot starter integration โœ… Production Ready
spice-runtime Extended LLM providers, custom agent types ๐Ÿšง Planned
spice-tools Tool interface, function calling, RAG tools ๐Ÿšง Planned
spice-examples Production demos, tutorials, best practices ๐Ÿšง Planned

๐Ÿ—๏ธ Core Architecture

spice-core/
โ”œโ”€โ”€ Agent.kt               # Base agent interface
โ”œโ”€โ”€ AgentEngine.kt         # Agent orchestration engine
โ”œโ”€โ”€ SwarmAgent.kt          # Multi-agent coordination
โ”œโ”€โ”€ MultiAgentFlow.kt      # High-performance flow execution
โ”œโ”€โ”€ Message.kt             # Type-safe message model
โ”œโ”€โ”€ VectorStore.kt         # Vector database integration
โ”œโ”€โ”€ agents/                # LLM provider implementations
โ”‚   โ”œโ”€โ”€ OpenAIAgent.kt     # GPT-4, GPT-3.5 support
โ”‚   โ”œโ”€โ”€ AnthropicAgent.kt  # Claude-3.5-Sonnet support
โ”‚   โ”œโ”€โ”€ VertexAgent.kt     # Google Gemini support
โ”‚   โ””โ”€โ”€ VLLMAgent.kt       # vLLM local deployment
โ””โ”€โ”€ Tool.kt                # Function calling interface

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.


๐Ÿ“œ License

MIT License. Use freely. Share wildly. Build something spicy. ๐ŸŒถ๏ธ


๐Ÿ†˜ Support

  • ๐Ÿ“– Documentation: Coming soon to the wiki
  • ๐Ÿ› Bug Reports: Open an issue on GitHub
  • ๐Ÿ’ฌ Questions: Start a discussion on GitHub
  • ๐Ÿš€ Feature Requests: Open an issue with the enhancement label

๐ŸŽฏ Roadmap

โœ… Completed (v0.1.0)

  • Multi-agent orchestration with SwarmAgent
  • Production-ready MultiAgentFlow with 4 strategies
  • OpenAI, Anthropic, Vertex AI, vLLM agent implementations
  • Vector store integration with Qdrant
  • Spring Boot starter with autoconfiguration
  • Comprehensive test coverage (90%+)
  • Thread-safe concurrent execution
  • Rich metadata and observability

๐Ÿšง In Progress (v0.2.0)

  • Function calling and tool integration
  • RAG workflow templates
  • Advanced routing policies
  • Performance benchmarking suite
  • Documentation and examples

๐Ÿ”ฎ Future Releases

  • Visual flow builder for agent workflows
  • Distributed agent execution
  • Advanced monitoring dashboard
  • Agent marketplace and sharing
  • WebAssembly agent runtime

๐Ÿ’ฌ Authors

Built by No AI Labs with โค๏ธ and lots of โ˜•


The Spice must flow.