File size: 8,294 Bytes
5402d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2db37fe
5402d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2db37fe
5402d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8146dee
5402d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# OrKa API Reference

Complete API documentation for OrKa's core components, including classes, methods, and configuration options.

## Table of Contents

1. [Core Components](#core-components)
   - [Orchestrator](#orchestrator)
   - [Memory System](#memory-system)
   - [Nodes](#nodes)
   - [Agents](#agents)
2. [Configuration](#configuration)
   - [YAML Schema](#yaml-schema)
   - [Environment Variables](#environment-variables)
3. [Memory Backend](#memory-backend)
   - [RedisStack](#redisstack)
4. [CLI Reference](#cli-reference)

## Core Components

### Orchestrator

The orchestrator is the central component that manages workflow execution, agent coordination, and memory operations.

#### OrchestratorBase

Base class providing core infrastructure and configuration management.

```python
class OrchestratorBase:
    """
    Base orchestrator class that handles initialization and configuration.

    Attributes:
        loader (YAMLLoader): Configuration file loader and validator
        orchestrator_cfg (dict): Orchestrator-specific configuration
        agent_cfgs (list): List of agent configuration objects
        memory: Memory backend instance
        fork_manager: Fork group manager for parallel execution
        queue (list): Current agent execution queue
        run_id (str): Unique identifier for this run
        step_index (int): Current step counter
        error_telemetry (dict): Error tracking and metrics
    """

    def __init__(self, config_path: str) -> None:
        """Initialize with YAML config file."""

    def enqueue_fork(self, agent_ids: list[str], fork_group_id: str) -> None:
        """Enqueue a fork group for parallel execution."""
```

### Memory System

OrKa's memory system provides intelligent storage and retrieval with 100x faster vector search.

#### RedisStackMemoryLogger

Enterprise-grade memory management with HNSW indexing.

```python
class RedisStackMemoryLogger(BaseMemoryLogger):
    """
    Enhanced memory logger using RedisStack with HNSW indexing.

    Features:
        - 100x faster vector search with HNSW
        - Intelligent memory classification
        - Automatic index optimization
        - Comprehensive metadata management
    """

    def write(
        self,
        namespace: str,
        content: str,
        vector: bool = True,
        metadata: dict = None
    ) -> str:
        """
        Store information with vector embeddings.

        Args:
            namespace: Memory namespace
            content: Content to store
            vector: Enable vector embeddings
            metadata: Additional metadata

        Returns:
            str: Memory entry ID
        """

    def search(
        self,
        namespace: str,
        query: str,
        limit: int = 5,
        similarity_threshold: float = 0.8
    ) -> list[dict]:
        """
        Perform semantic search with HNSW indexing.

        Args:
            namespace: Memory namespace to search
            query: Search query
            limit: Maximum results
            similarity_threshold: Minimum similarity

        Returns:
            list[dict]: Matching memories with scores
        """
```

### Nodes

Specialized components for workflow operations.

#### LoopNode

Enables iterative improvement workflows.

```python
class LoopNode(BaseNode):
    """
    Executes an internal workflow repeatedly until conditions are met.

    Features:
        - Iterative execution with thresholds
        - Cognitive insight extraction
        - Learning from past iterations
        - Automatic termination
    """

    def run(self, input_data: dict) -> dict:
        """
        Execute the loop workflow.

        Args:
            input_data: Input for the workflow

        Returns:
            dict: Final results with learning insights
        """
```

#### MemoryWriterNode

Stores information with intelligent classification.

```python
class MemoryWriterNode(BaseNode):
    """
    Stores information in OrKa's memory system.

    Features:
        - Automatic memory classification
        - Vector embeddings for search
        - Configurable metadata
        - Intelligent decay
    """

    def run(self, input_data: dict) -> dict:
        """
        Store information in memory.

        Args:
            input_data: Content and metadata to store

        Returns:
            dict: Storage results and metadata
        """
```

#### MemoryReaderNode

Retrieves information using semantic search.

```python
class MemoryReaderNode(BaseNode):
    """
    Retrieves information using semantic search.

    Features:
        - 100x faster semantic search
        - Context-aware retrieval
        - Temporal ranking
        - Configurable thresholds
    """

    def run(self, input_data: dict) -> dict:
        """
        Search memory with vector similarity.

        Args:
            input_data: Search query and parameters

        Returns:
            dict: Search results with metadata
        """
```

### Agents

AI agents that perform specific tasks in workflows.

#### OpenAIAgent

Interacts with OpenAI's API for various tasks.

```python
class OpenAIAgent(BaseAgent):
    """
    OpenAI-powered agent for various tasks.

    Features:
        - Multiple task types (classification, Q&A, etc.)
        - Context management
        - Error handling
        - Rate limiting
    """

    def run(self, input_data: dict) -> dict:
        """
        Execute the agent's task.

        Args:
            input_data: Task input and parameters

        Returns:
            dict: Task results
        """
```

## Configuration

### YAML Schema

OrKa workflows are defined in YAML with the following structure:

```yaml
meta:
  version: "1.0"
  description: "Workflow description"

orchestrator:
  id: workflow-name
  strategy: sequential
  memory_config:
    decay:
      enabled: true
      default_short_term_hours: 2
      default_long_term_hours: 168

agents:
  - id: agent-name
    type: agent-type
    params:
      key: value
    prompt: "Agent prompt template"
```

### Environment Variables

Key environment variables for configuration:

| Variable | Description | Default |
|----------|-------------|---------|
| OPENAI_API_KEY | OpenAI API key | Required |
| REDIS_URL | Redis connection URL | redis://localhost:6380/0 |
| ORKA_MEMORY_BACKEND | Memory backend type | redisstack |
| ORKA_MEMORY_DECAY_ENABLED | Enable memory decay | false |
| ORKA_MEMORY_DECAY_SHORT_TERM_HOURS | Short-term retention | 2 |
| ORKA_MEMORY_DECAY_LONG_TERM_HOURS | Long-term retention | 168 |
| ORKA_MAX_CONCURRENT_REQUESTS | Max concurrent operations | 100 |
| ORKA_TIMEOUT_SECONDS | Operation timeout | 300 |

## Memory Backend

### RedisStack

Primary memory backend with HNSW vector search.

Configuration:
```yaml
memory_config:
  backend: redisstack
  redis_url: redis://localhost:6380/0
  enable_hnsw: true
  vector_params:
    M: 16
    ef_construction: 200
    ef_runtime: 10
```

Performance:
- Vector Search: 0.5-5ms
- Memory Usage: 40% of basic Redis
- Concurrent Searches: 1000+
- Index Updates: Automatic

```

Features:
- Streaming memory operations
- Schema validation
- High availability
- Scalable throughput

## CLI Reference

### Core Commands

```bash
# Run a workflow
orka run workflow.yml "input text"

# Monitor memory performance
orka memory watch
orka memory stats

# Clean up expired memories
orka memory cleanup

# Start OrKa services
orka-start      # Development (Redis)
orka-start      # Production (RedisStack)

# Check system health
orka system status
```

### Memory Management

```bash
# View memory configuration
orka memory configure

# Search memories
orka memory search "query"

# Export memories
orka memory export namespace

# Import memories
orka memory import namespace file.json
```

### Workflow Management

```bash
# Validate workflow
orka validate workflow.yml

# List running workflows
orka list workflows

# Stop workflow
orka stop workflow-id

# Show workflow status
orka status workflow-id
```

For more detailed information about specific components or features, check the following guides:
- [Memory System Guide](./MEMORY_SYSTEM_GUIDE.md)
- [Agent Development Guide](./agents.md)
- [Production Deployment Guide](./runtime-modes.md)
- [Security Guide](./security.md)