Overview

AetherShell integrates AI capabilities at the language level, enabling:

AI Model URIs

Supported Providers

Provider URI Scheme Example
OpenAI openai: openai:gpt-4o-mini
Ollama (Local) ollama: ollama:llama3
Compatibility compat: compat:mixtral

Environment Setup

# Set default AI provider
export AETHER_AI=openai

# OpenAI API key
export OPENAI_API_KEY=sk-...

# Ollama (local models)
ollama pull llama3

Single Agent Execution

Basic Agent

// Deploy agent with goal and allowed tools
result = agent(
    "Count all Rust source files in src/",
    "ls,find",    // Whitelisted commands
    5             // Max iterations
)
print(result)

Agent with Tool Restrictions

// Whitelist specific tools for security
export AGENT_ALLOW_CMDS=ls,cat,grep,find

// Agent can only use allowed tools
analysis = agent(
    "Find all TODO comments in the codebase",
    "grep,find",
    10
)

Agent Workflow

1. Goal Understanding

Agent parses natural language goal

2. Planning

Determines required tools and steps

3. Execution

Iteratively executes tools and processes results

4. Result

Returns final answer or artifact

AgenticBinary Protocol

Protocol Overview

A compact binary protocol designed for efficient agent-to-agent communication. 3-5x more compact than JSON.

Format: 8-bit header + varint-encoded payload
Header: 0bVVTTCCCC (Version 2 bits + MsgType 2 bits + Opcode 4 bits)

Message Types

Type Code Usage
command 0b00 Execute actions, delegate tasks
query 0b01 Request information, status
response 0b10 Return results, acknowledgments
event 0b11 Notifications, state changes

Semantic Opcodes (16 total)

Opcode Name Description
0 PING Health check, connection test
1 ACK Acknowledgment of receipt
2 QUERY Information request
3 EXEC Execute command/task
4 DATA Data payload transfer
5 ERROR Error notification
6 SYNC State synchronization
7 AUTH Authentication/authorization
8 DELEGATE Task delegation
9 COLLABORATE Request collaboration
10 LEARN Knowledge sharing
11 REASON Reasoning/inference
12 PLAN Planning activity
13 OBSERVE Observation/monitoring
14 REFLECT Self-reflection
15 EXTEND Extension/customization

Encoding Messages

// Encode a PING command
ping = ab_encode("command", "ping", "hello")
// Returns: [0, 5, 104, 101, 108, 108, 111]
//   Header: 0 (version=0, type=command, opcode=PING)
//   Payload: varint(5) + "hello"

// Encode ACK response
ack = ab_encode("response", "ack", "received")

// Encode DELEGATE command
task = ab_encode("command", "delegate", "analyze_data")

// Encode DATA response
result = ab_encode("response", "data", "complete")

Decoding Messages

// Receive binary message
bytes = [0, 5, 104, 101, 108, 108, 111]

// Decode to structured format
msg = ab_decode(bytes)

print(msg.msg_type)  // "Command"
print(msg.opcode)    // "PING"
print(msg.payload)   // "hello"

Multi-Agent Coordination

Agent Roles

🎯 Coordinator

Manages workflow, delegates tasks, collects results

⚙️ Worker

Executes specific tasks, reports progress

📚 Specialist

Domain expert for specific operations

🔍 Observer

Monitors system, detects issues

Coordination Example

// Phase 1: Workers learn protocol
spec = syntax_get("ab")
worker1_msg = ab_encode("command", "learn", spec.specification)
worker2_msg = ab_encode("command", "learn", spec.specification)

// Phase 2: Workers signal ready
worker1_ready = ab_encode("response", "ack", "worker1:ready")
worker2_ready = ab_encode("response", "ack", "worker2:ready")

// Phase 3: Coordinator delegates tasks
task1 = ab_encode("command", "delegate", "worker1:analyze_logs")
task2 = ab_encode("command", "delegate", "worker2:process_data")

// Phase 4: Workers execute
exec1 = ab_encode("command", "exec", "started:log_analysis")
exec2 = ab_encode("command", "exec", "started:data_processing")

// Phase 5: Workers collaborate (if needed)
collab = ab_encode("command", "collaborate", "worker2:need_log_data")

// Phase 6: Workers report results
result1 = ab_encode("response", "data", "complete:analysis.json")
result2 = ab_encode("response", "data", "complete:processed.json")

// Phase 7: Coordinator reflects
reflection = ab_encode("command", "reflect", "efficiency:95%")

Communication Patterns

Pattern Opcodes Use Case
Task Delegation DELEGATE → ACK → EXEC → DATA Coordinator assigns work to workers
Collaboration COLLABORATE → ACK → DATA Agents request help from peers
Knowledge Sharing LEARN → ACK → SYNC Distribute new information across swarm
Error Handling ERROR → DELEGATE (retry) Recover from failures, reassign tasks

Multi-Modal AI

Supported Modalities

📝 Text

Natural language processing, generation, understanding

🖼️ Images

Image analysis, generation, object detection

🎵 Audio

Speech recognition, audio transcription

🎬 Video

Video analysis, frame extraction

Multi-Modal Examples (Future API)

// Analyze image
// image_data = cat("photo.jpg")
// result = ai_analyze(image_data, "Describe this image")

// Transcribe audio
// audio = cat("recording.mp3")
// transcript = ai_transcribe(audio)

// Generate image from text
// image = ai_generate("A futuristic cityscape at sunset")
// save(image, "output.png")

Model Context Protocol (MCP)

MCP Integration

AetherShell supports the Model Context Protocol for standardized AI tool integration.

MCP Functions

// List available MCP servers
servers = mcp_servers()
print(servers)

// Detect MCP servers in directory
detected = mcp_detect("./tools")

// Cache management
mcp_cache_clear()
status = mcp_cache_status()

MCP Server Discovery

// Scan workspace for MCP tools
tools = mcp_detect(".")

// Connect to specific server
// connection = mcp_connect("filesystem-server")

// Call tool through MCP
// result = mcp_call(connection, "read_file", {path: "data.txt"})

Best Practices

Security

Tool Whitelisting: Always specify allowed commands when deploying agents
API Keys: Store API keys in environment variables, never hardcode
Validation: Validate agent outputs before executing actions

Performance

Error Handling

// Check agent result status
result = agent("Task description", "ls,find", 5)

if type_of(result) == "Record" && result.status == "error" {
    print("Agent failed: ${result.message}")
    // Retry or fallback logic
} else {
    print("Success: ${result}")
}

Complete Multi-Agent Example

See examples/13_agent_coordination.ae for a full 10-phase workflow with:

# Run the example
ae examples/13_agent_coordination.ae
Next: Learn about Syntax Knowledge Base or see Code Examples.