helios-engine 0.5.5

A powerful and flexible Rust framework for building LLM-powered agents with tool support, both locally and online
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# 🔥 Helios Engine - LLM Agent Framework

<p align="center">
  <img src="src/Helios_Engine_Logo.png" alt="Helios Engine Logo" width="350"/>
</p>

<p align="center">
  <a href="https://crates.io/crates/helios-engine"><img src="https://img.shields.io/crates/v/helios-engine.svg" alt="Crates.io"></a>
  <a href="https://docs.rs/helios-engine"><img src="https://img.shields.io/badge/docs-latest-blue.svg" alt="Documentation"></a>
  <a href="https://helios-engine.vercel.app/"><img src="https://img.shields.io/badge/book-online-brightgreen.svg" alt="Online Book"></a>
  <a href="https://github.com/Ammar-Alnagar/helios-engine/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
</p>

**Helios Engine** is a powerful and flexible Rust framework for building LLM-powered agents with tool support, streaming chat capabilities, and easy configuration management. Create intelligent agents that can interact with users, call tools, and maintain conversation context - with both online and offline local model support.

## 📚 Documentation

- **[Official Documentation & Book]https://helios-engine.vercel.app/** - Complete guide with tutorials and examples
- **[API Reference]https://docs.rs/helios-engine** - Detailed API documentation on docs.rs
- **[Examples]https://github.com/Ammar-Alnagar/helios-engine/tree/main/examples** - Hands-on code examples

## 🚀 Key Features

### Core Capabilities
- **🤖 Agent System**: Create multiple agents with different personalities, system prompts, and specialized capabilities
- **🔧 Tool Registry**: Extensible tool system for adding custom functionality to your agents
- **💬 Streaming Support**: True real-time response streaming for both remote and local models with immediate token delivery
- **🌐 HTTP Server & API**: Expose fully OpenAI-compatible API endpoints with streaming, temperature control, and all standard parameters
- **🎯 Dual Mode Support**: Auto, online (remote API), and offline (local) modes for maximum flexibility

### Advanced Features
- **🌲 Forest of Agents**: Multi-agent collaboration system where agents can communicate, delegate tasks, and share context
  - Coordinator-based planning for complex task decomposition
  - Agent-to-agent communication
  - Shared context and memory between agents
  
- **🧰 Tool Builder**: Simplified tool creation with builder pattern - wrap any function as a tool without manual trait implementation

- **📚 RAG System (Retrieval-Augmented Generation)**: Built-in support for semantic search and document retrieval
  - Vector stores: InMemory and Qdrant
  - OpenAI embeddings integration
  - Easy document storage and retrieval

- **🛠️ Extensive Tool Suite**: 16+ built-in tools including:
  - **File Management**: Read, write, edit, and search files
  - **Web Tools**: Web scraping, HTTP requests
  - **System Tools**: Shell commands, system information
  - **Data Processing**: JSON parsing, text manipulation, timestamps
  - **Utilities**: Calculator, echo, in-memory database

- **🧩 Feature Flags**: Optional `local` feature for offline model support - build only what you need!
  - Standard installation for lightweight deployments
  - Local model support with llama.cpp integration

- **📦 CLI & Library**: Use as both a command-line tool and a Rust library crate

## 📦 Installation

### Version 0.4.4

#### As a CLI Tool

**Standard Installation** (recommended for most users):
```bash
cargo install helios-engine
```

**With Local Model Support** (includes llama.cpp for offline models):
```bash
cargo install helios-engine --features local
```

#### As a Library

Add to your `Cargo.toml`:

```toml
[dependencies]
helios-engine = "0.4.4"
tokio = { version = "1.35", features = ["full"] }
```

For local model support:
```toml
[dependencies]
helios-engine = { version = "0.4.4", features = ["local"] }
tokio = { version = "1.35", features = ["full"] }
```

## 🚦 Quick Start

### Basic Agent Example

```rust
use helios_engine::{Agent, Config};

#[tokio::main]
async fn main() -> helios_engine::Result<()> {
    let config = Config::from_file("config.toml")?;
    
    let mut agent = Agent::builder("MyAssistant")
        .config(config)
        .system_prompt("You are a helpful AI assistant.")
        .build()
        .await?;
    
    let response = agent.chat("Hello! How are you?").await?;
    println!("{}", response);
    
    Ok(())
}
```

### Agent with Tools

```rust
use helios_engine::{Agent, Config, CalculatorTool, FileReadTool, WebScraperTool};

#[tokio::main]
async fn main() -> helios_engine::Result<()> {
    let config = Config::from_file("config.toml")?;
    
    let mut agent = Agent::builder("ToolAgent")
        .config(config)
        .system_prompt("You are a helpful assistant with access to various tools.")
        .tools(vec![
            Box::new(CalculatorTool),
            Box::new(FileReadTool),
            Box::new(WebScraperTool),
        ])
        .max_iterations(5)
        .build()
        .await?;
    
    let response = agent.chat("What is 15 * 7 + 23?").await?;
    println!("{}", response);
    
    Ok(())
}
```

### Forest of Agents (Multi-Agent System)

```rust
use helios_engine::{Agent, Config, ForestBuilder};

#[tokio::main]
async fn main() -> helios_engine::Result<()> {
    let config = Config::from_file("config.toml")?;
    
    let mut forest = ForestBuilder::new()
        .config(config)
        .agents(vec![
            ("researcher".to_string(), Agent::builder("researcher")
                .system_prompt("You research and gather information.")),
            ("analyst".to_string(), Agent::builder("analyst")
                .system_prompt("You analyze data and identify patterns.")),
            ("writer".to_string(), Agent::builder("writer")
                .system_prompt("You write clear, concise reports.")),
        ])
        .max_iterations(15)
        .build()
        .await?;
    
    let result = forest.execute("Research AI trends and write a summary").await?;
    println!("{}", result);
    
    Ok(())
}
```

### RAG (Retrieval-Augmented Generation)

```rust
use helios_engine::{Agent, Config, RAGTool};

#[tokio::main]
async fn main() -> helios_engine::Result<()> {
    let config = Config::from_file("config.toml")?;
    
    let rag_tool = RAGTool::new_in_memory(
        "https://api.openai.com/v1/embeddings",
        std::env::var("OPENAI_API_KEY").unwrap()
    );
    
    let mut agent = Agent::builder("KnowledgeAgent")
        .config(config)
        .tool(Box::new(rag_tool))
        .build()
        .await?;
    
    // Store documents
    agent.chat("Store this: Rust is a systems programming language focused on safety and performance.").await?;
    
    // Query knowledge base
    let response = agent.chat("What do you know about Rust?").await?;
    println!("{}", response);
    
    Ok(())
}
```

### HTTP API Server

```rust
use helios_engine::{Agent, Config, CalculatorTool, serve};

#[tokio::main]
async fn main() -> helios_engine::Result<()> {
    let config = Config::from_file("config.toml")?;
    
    let agent = Agent::builder("API Agent")
        .config(config)
        .system_prompt("You are a helpful AI assistant with calculator capabilities.")
        .tool(Box::new(CalculatorTool))
        .max_iterations(5)
        .build()
        .await?;
    
    println!("Starting server on http://127.0.0.1:8000");
    serve::start_server_with_agent(agent, "gpt-4".to_string(), "127.0.0.1:8000").await?;
    
    Ok(())
}
```

Test with curl:
```bash
curl http://127.0.0.1:8000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-4",
    "messages": [{"role": "user", "content": "What is 15 * 7?"}],
    "stream": true
  }'
```

## 🔧 Configuration

Create a `config.toml` file:

```toml
# Online mode (using remote API)
[llm]
mode = "online"
provider = "openai"
model = "gpt-4"
api_url = "https://api.openai.com/v1/chat/completions"
api_key = "your-api-key-here"

# Optional parameters
temperature = 0.7
max_tokens = 2000
streaming = true
```

For local models:
```toml
[llm]
mode = "offline"
model_path = "/path/to/model.gguf"
```

Or use auto mode to let Helios decide:
```toml
[llm]
mode = "auto"
provider = "openai"
model = "gpt-4"
```

## 📖 Built-in Tools

Helios Engine includes 16+ production-ready tools:

### File Management
- **FileReadTool** - Read file contents with line range support
- **FileWriteTool** - Write content to files
- **FileEditTool** - Find and replace in files
- **FileSearchTool** - Search files by name or content

### Web & API
- **WebScraperTool** - Fetch and extract web content
- **HttpRequestTool** - Make HTTP requests (GET, POST, PUT, DELETE, etc.)

### System & Utilities
- **ShellCommandTool** - Execute shell commands with safety restrictions
- **SystemInfoTool** - Get system information (OS, CPU, memory, disk, network)
- **CalculatorTool** - Perform mathematical calculations
- **TimestampTool** - Work with timestamps and dates

### Data Processing
- **JsonParseTool** - Parse and manipulate JSON data
- **TextProcessingTool** - Text manipulation and analysis
- **InMemoryDbTool** - Simple key-value database in memory

### Agent Communication
- **SendMessageTool** - Enable agent-to-agent communication in Forest mode

### RAG & Knowledge
- **RAGTool** - Retrieval-augmented generation with vector stores

## 🎯 Use Cases

- **Chatbots & Virtual Assistants**: Build conversational AI with tool access
- **Multi-Agent Systems**: Coordinate multiple specialized agents for complex workflows
- **Data Analysis**: Agents that can read files, process data, and generate reports
- **Web Automation**: Scrape websites, make API calls, and process responses
- **Knowledge Management**: Build RAG systems for semantic search and Q&A
- **API Services**: Expose your agents via OpenAI-compatible HTTP endpoints
- **Local AI**: Run models completely offline for privacy and security

## 🌟 Advanced Features

### Streaming Responses
```rust
use futures::StreamExt;

let mut stream = agent.chat_stream("Tell me a story").await?;
while let Some(chunk) = stream.next().await {
    print!("{}", chunk?);
}
```

### Custom Tools
```rust
use helios_engine::{Tool, ToolBuilder};
use async_trait::async_trait;
use serde_json::{json, Value};

// Using Tool Builder (recommended)
let custom_tool = ToolBuilder::new("my_tool")
    .description("Does something custom")
    .parameter("input", "string", "Input parameter", true)
    .build(|params| async move {
        let input = params.get("input").and_then(|v| v.as_str()).unwrap_or("");
        Ok(json!({"result": format!("Processed: {}", input)}))
    });

// Or implement the Tool trait manually
struct MyCustomTool;

#[async_trait]
impl Tool for MyCustomTool {
    fn name(&self) -> String {
        "my_custom_tool".to_string()
    }
    
    fn description(&self) -> String {
        "My custom tool description".to_string()
    }
    
    fn parameters(&self) -> Value {
        json!({
            "type": "object",
            "properties": {
                "input": {"type": "string", "description": "Input parameter"}
            },
            "required": ["input"]
        })
    }
    
    async fn execute(&self, params: Value) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
        // Your custom logic here
        Ok(json!({"result": "success"}))
    }
}
```

### Coordinator-Based Planning
```rust
let mut forest = ForestBuilder::new()
    .config(config)
    .coordinator("coordinator".to_string(), 
        Agent::builder("coordinator")
            .system_prompt("You plan and coordinate tasks."))
    .agents(vec![
        ("worker1".to_string(), Agent::builder("worker1")),
        ("worker2".to_string(), Agent::builder("worker2")),
    ])
    .max_iterations(20)
    .build()
    .await?;
```

## 📊 Examples

The repository includes extensive examples demonstrating all features:

```bash
# List all examples
cargo run --example --list

# Run specific examples
cargo run --example basic_chat
cargo run --example agent_with_tools
cargo run --example forest_of_agents
cargo run --example agent_with_rag
cargo run --example streaming_chat
cargo run --example serve_agent
```

Check out the [examples directory](https://github.com/Ammar-Alnagar/helios-engine/tree/main/examples) and the [online documentation](https://helios-engine.vercel.app/examples/overview.html) for more.

## 🤝 Contributing

Contributions are welcome! Please see our [Contributing Guide](https://helios-engine.vercel.app/contributing/how_to_contribute.html) for details.

## 📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

## 🔗 Links

- **[Official Website & Documentation]https://helios-engine.vercel.app/**
- **[Crates.io]https://crates.io/crates/helios-engine**
- **[API Documentation]https://docs.rs/helios-engine**
- **[GitHub Repository]https://github.com/Ammar-Alnagar/helios-engine**

## 🎉 Getting Help

- Check out the [online book]https://helios-engine.vercel.app/ for comprehensive guides
- Browse the [examples]https://github.com/Ammar-Alnagar/helios-engine/tree/main/examples for code samples
- Open an issue on [GitHub]https://github.com/Ammar-Alnagar/helios-engine/issues for bugs or feature requests

---

<p align="center">
  Made with ❤️ by <a href="https://github.com/Ammar-Alnagar">Ammar Alnagar</a>
</p>