💡 Examples
Real-world code examples and patterns
Example Categories
🎯 Basics (0-4)
Hello world, pipelines, tables, HTTP, pattern matching
🤖 AI & Agents (5-7)
AI models, agents, URIs, multi-modal
🖥️ TUI (9-11, 20-23)
Terminal UI, multi-modal, agent swarms, chat
📚 Syntax KB (12-13)
Knowledge base, agent coordination, AgenticBinary
🔌 MCP (14-18)
Model Context Protocol integration
⚡ Advanced (19, 99)
Comprehensive showcases and tests
Basics Examples
00_hello.ae - Hello World
// Your first AetherShell program
print("Hello, AetherShell!")
// With variables
name = "World"
print("Hello, ${name}!")
Run: ae examples/00_hello.ae
01_pipelines.ae - Pipeline Operations
// Double all numbers
[1, 2, 3, 4, 5]
| map(fn(x) => x * 2)
| print // [2, 4, 6, 8, 10]
// Filter and sum
[1, 2, 3, 4, 5, 6]
| where(fn(x) => x % 2 == 0) // [2, 4, 6]
| reduce(fn(a,b) => a + b, 0) // 12
| print
// Complex pipeline
range(1, 11)
| where(fn(x) => x % 2 == 0)
| map(fn(x) => x * x)
| reduce(fn(a,b) => a + b, 0)
| print // 220
Run: ae examples/01_pipelines.ae
02_tables.ae - Working with Tables
// File listing as table
files = ls(".")
// Filter large files
large = files | where(fn(f) => f.size > 10000)
// Get names
names = large | map(fn(f) => f.name)
print(names)
// Count by type
dirs = files | where(fn(f) => f.type == "directory") | len
print("Directories: ${dirs}")
Run: ae examples/02_tables.ae
03_http.ae - HTTP Requests
// Simple GET request
response = http_get("https://api.github.com/zen")
print(response)
// Pipeline style
"https://api.github.com/repos/rust-lang/rust"
| http_get
| json_parse
| fn(data) => print("Stars: ${data.stargazers_count}")
Run: ae examples/03_http.ae
04_match.ae - Pattern Matching
// Match expression
classify = fn(x) => match x {
1 => "one",
2 => "two",
3 => "three",
_ => "many"
}
print(classify(1)) // "one"
print(classify(5)) // "many"
// Match in pipeline
[1, 2, 3, 4, 5]
| map(classify)
| print // ["one", "two", "three", "many", "many"]
Run: ae examples/04_match.ae
AI & Agent Examples
05_ai.ae - AI Model Usage
// Set AI provider
export AETHER_AI=openai
export OPENAI_API_KEY=sk-...
// Simple AI query (conceptual)
// response = ai_query("What is 2+2?")
// print(response)
Run: ae examples/05_ai.ae
06_agent.ae - Single Agent
// Deploy agent with goal
result = agent(
"Count all Rust source files in src/",
"ls,find", // Allowed tools
5 // Max iterations
)
print(result)
// Agent with data processing
analysis = agent(
"Find largest file in current directory",
"ls",
3
)
print(analysis)
Run: ae examples/06_agent.ae
07_uri_types.ae - Model URIs
// Different AI providers via URIs
openai_model = "openai:gpt-4o-mini"
ollama_model = "ollama:llama3"
compat_model = "compat:mixtral"
// Use specific model (conceptual)
// result = ai_query("Hello", openai_model)
// local_result = ai_query("Hello", ollama_model)
Run: ae examples/07_uri_types.ae
TUI Examples
09_tui_multimodal.ae - Multi-Modal TUI
// Launch TUI with multi-modal support
// Handles images, audio, video in terminal
// Run with:
// ae tui examples/09_tui_multimodal.ae
Run: ae tui examples/09_tui_multimodal.ae
10_tui_agent_swarm.ae - Agent Swarm TUI
// Interactive agent swarm visualization
// Shows multiple agents coordinating tasks
// Run with:
// ae tui examples/10_tui_agent_swarm.ae
Run: ae tui examples/10_tui_agent_swarm.ae
21_tui_chat.ae - Chat Interface
// Interactive chat with AI models
// TUI-based conversation interface
// Run with:
// ae tui examples/21_tui_chat.ae
Run: ae tui examples/21_tui_chat.ae
Syntax KB Examples
12_syntax_kb.ae - Knowledge Base Basics
// Retrieve AgenticBinary protocol
ab_spec = syntax_get("ab")
print("Protocol: ${ab_spec.name}")
print("Category: ${ab_spec.category}")
// Search for syntaxes
results = syntax_search("binary")
print("Found: ${results}")
// List all protocols
protocols = syntax_list("protocol")
print("Protocols: ${protocols}")
// Encode/decode messages
ping = ab_encode("command", "ping", "hello")
print("Encoded: ${ping}")
decoded = ab_decode(ping)
print("Message Type: ${decoded.msg_type}")
print("Opcode: ${decoded.opcode}")
print("Payload: ${decoded.payload}")
// Add custom syntax
custom = {
id: "myproto",
name: "My Custom Protocol",
category: "protocol",
specification: "Custom protocol for specific tasks",
examples: ["example1", "example2"]
}
syntax_add(custom)
// Verify
retrieved = syntax_get("myproto")
print("Added: ${retrieved.name}")
Run: ae examples/12_syntax_kb.ae
13_agent_coordination.ae - Multi-Agent Workflow
// Complete 10-phase agent coordination example
// 4 agents: Coordinator + 3 Workers
// 17 messages exchanged
// All major opcodes demonstrated
// Phase 1: Protocol Discovery
spec = syntax_get("ab")
print("=== Phase 1: Protocol Discovery ===")
print("Protocol: ${spec.name}")
// Phase 2: Workers Learn Protocol
print("\n=== Phase 2: Workers Learn ===")
learn1 = ab_encode("command", "learn", spec.specification)
learn2 = ab_encode("command", "learn", spec.specification)
learn3 = ab_encode("command", "learn", spec.specification)
// Phase 3: Workers Signal Ready
print("\n=== Phase 3: Workers Ready ===")
ready1 = ab_encode("response", "ack", "worker1:ready")
ready2 = ab_encode("response", "ack", "worker2:ready")
ready3 = ab_encode("response", "ack", "worker3:ready")
// Phase 4: Coordinator Delegates
print("\n=== Phase 4: Task Delegation ===")
task1 = ab_encode("command", "delegate", "worker1:analyze_logs")
task2 = ab_encode("command", "delegate", "worker2:process_data")
task3 = ab_encode("command", "delegate", "worker3:monitor_system")
// Phase 5: Workers Execute
print("\n=== Phase 5: Task Execution ===")
exec1 = ab_encode("command", "exec", "started:log_analysis")
exec2 = ab_encode("command", "exec", "started:data_processing")
exec3 = ab_encode("command", "exec", "started:system_monitoring")
// Phase 6: Workers Collaborate
print("\n=== Phase 6: Collaboration ===")
collab = ab_encode("command", "collaborate", "worker2:need_log_data")
share = ab_encode("response", "data", "worker1:sharing_logs")
// Phase 7: Error Handling
print("\n=== Phase 7: Error Recovery ===")
error = ab_encode("response", "error", "worker3:timeout")
retry = ab_encode("command", "delegate", "worker3:retry_monitoring")
// Phase 8: Results Reporting
print("\n=== Phase 8: Results ===")
result1 = ab_encode("response", "data", "complete:analysis.json")
result2 = ab_encode("response", "data", "complete:processed.json")
result3 = ab_encode("response", "data", "complete:monitoring.json")
// Phase 9: Coordinator Reflects
print("\n=== Phase 9: Reflection ===")
reflect = ab_encode("command", "reflect", "efficiency:95%")
// Phase 10: Summary
print("\n=== Phase 10: Summary ===")
print("Total messages: 17")
print("Agents: 4 (1 coordinator + 3 workers)")
print("Success rate: 95%")
Run: ae examples/13_agent_coordination.ae
MCP (Model Context Protocol) Examples
15_mcp_basic.ae - MCP Basics
// List available MCP servers
servers = mcp_servers()
print("Available MCP servers:")
print(servers)
// Detect MCP servers in directory
detected = mcp_detect(".")
print("\nDetected servers:")
print(detected)
// Cache management
print("\nCache status:")
status = mcp_cache_status()
print(status)
// Clear cache
mcp_cache_clear()
print("Cache cleared")
Run: ae examples/15_mcp_basic.ae
16_mcp_servers.ae - MCP Server Integration
// Discover and connect to MCP servers
servers = mcp_servers()
// Filter by capability
// filesystem_servers = servers
// | where(fn(s) => contains(s.capabilities, "filesystem"))
print("Filesystem-capable servers found")
Run: ae examples/16_mcp_servers.ae
Advanced Examples
14_typed_pipelines.ae - Type-Safe Pipelines
// Demonstrate type inference in pipelines
// Pipeline preserves types
ints = [1, 2, 3, 4, 5]
doubled = ints | map(fn(x) => x * 2)
print("Doubled: ${doubled}")
// Type-safe operations
users = [
{name: "Alice", age: 30},
{name: "Bob", age: 25},
{name: "Charlie", age: 35}
]
// Extract and process
adult_names = users
| where(fn(u) => u.age >= 30)
| map(fn(u) => u.name)
| join(", ")
print("Adults: ${adult_names}")
Run: ae examples/14_typed_pipelines.ae
18_mutable_variables.ae - Mutability Patterns
// Immutable (default)
x = 10
print("Immutable x: ${x}")
// x = 20 // ERROR: Cannot reassign
// Mutable
y := 10
print("Initial y: ${y}")
y = 20
print("Updated y: ${y}")
// Counter pattern
counter := 0
i := 1
while (i <= 5) {
counter = counter + i
i = i + 1
}
print("Counter: ${counter}") // 15
// Functional alternative (no mutation)
functional_sum = range(1, 6)
| reduce(fn(a,b) => a + b, 0)
print("Functional: ${functional_sum}") // 15
Run: ae examples/18_mutable_variables.ae
99_comprehensive_test.ae - Full Feature Test
// Comprehensive test of all features
// - Variables (immutable & mutable)
// - Pipelines
// - Functions
// - Type inference
// - File operations
// - String processing
// - Array operations
// - Records
// - AgenticBinary
// - Syntax KB
print("=== Comprehensive AetherShell Test ===")
// Run all feature tests...
// (See file for complete implementation)
Run: ae examples/99_comprehensive_test.ae
Running Examples
Basic Execution
# Run an example
ae examples/01_pipelines.ae
# Run with REPL
ae
> load("examples/02_tables.ae")
TUI Mode
# Launch TUI
ae tui
# Run specific TUI example
ae tui examples/21_tui_chat.ae
With Environment Variables
# Set AI provider
export AETHER_AI=openai
export OPENAI_API_KEY=sk-...
# Run AI example
ae examples/06_agent.ae
# Allow specific agent tools
export AGENT_ALLOW_CMDS=ls,find,grep,cat
ae examples/13_agent_coordination.ae
Example Index
| File | Topic | Difficulty |
|---|---|---|
00_hello.ae |
Hello World | Beginner |
01_pipelines.ae |
Pipeline Operations | Beginner |
02_tables.ae |
Table Processing | Beginner |
03_http.ae |
HTTP Requests | Beginner |
04_match.ae |
Pattern Matching | Beginner |
05_ai.ae |
AI Models | Intermediate |
06_agent.ae |
Single Agent | Intermediate |
07_uri_types.ae |
Model URIs | Intermediate |
09_tui_multimodal.ae |
Multi-Modal TUI | Advanced |
10_tui_agent_swarm.ae |
Agent Swarm TUI | Advanced |
12_syntax_kb.ae |
Syntax KB | Intermediate |
13_agent_coordination.ae |
Multi-Agent | Advanced |
14_typed_pipelines.ae |
Type Safety | Intermediate |
15_mcp_basic.ae |
MCP Basics | Intermediate |
18_mutable_variables.ae |
Mutability | Beginner |
21_tui_chat.ae |
Chat TUI | Intermediate |
99_comprehensive_test.ae |
Full Test | Advanced |