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.
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.
- 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
- 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
- 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
- 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
- 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
- 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
// 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
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)
// 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}")
// 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"
)
// 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")
)
// 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")
// 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)
}
)
@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"]
)
}
}
Agents are the core units of work in Spice. They receive messages, process them, and send responses.
Structured communication between agents with typed content and metadata.
Reusable functions that agents can use to perform specific tasks.
Intelligent message routing based on agent capabilities, content analysis, and load balancing.
Personality and communication styles that can be applied to agents.
# 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
@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
}
}
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?"
)
)
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"
))
val supportAgent = OpenAIAgent("support", ...)
.withPersona(PersonaLibrary.PROFESSIONAL_ASSISTANT)
// The agent will now respond with a professional, helpful tone
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ 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 โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
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())
}
}
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 |
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
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
MIT License. Use freely. Share wildly. Build something spicy. ๐ถ๏ธ
- ๐ 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
- 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
- Function calling and tool integration
- RAG workflow templates
- Advanced routing policies
- Performance benchmarking suite
- Documentation and examples
- Visual flow builder for agent workflows
- Distributed agent execution
- Advanced monitoring dashboard
- Agent marketplace and sharing
- WebAssembly agent runtime
Built by No AI Labs with โค๏ธ and lots of โ
The Spice must flow.