Introduction
The Computer Abstraction Layer is a modern agent design pattern (2026) that implements a hierarchical action space. Instead of loading many tool definitions into the context window, agents use a small set of atomic tools that provide access to the operating system layer—bash, filesystem, and code execution.
This approach, inspired by production systems like Claude Code and Manus, reduces context window usage by 30-50% while providing more flexibility for complex tasks.
Key Concepts
Hierarchical Action Space
┌─────────────────┐
│ LLM Context │
│ (Agent) │
└────────┬────────┘
│
┌────────▼────────┐
│ Atomic Tools │
│ • bash │ ← Only 4 tools in context
│ • read_file │
│ • write_file │
│ • execute_r │
└────────┬────────┘
│
┌────────▼────────┐
│ Computer Layer │
│ • Scripts │ ← Unlimited actions via
│ • CLIs │ bash/filesystem
│ • Utilities │
└─────────────────┘
Basic Usage
Using Genesis with Computer Tools
The simplest way to use the computer abstraction is through the
genesis() function:
Genesis V2 with Computer Tools
For complex tasks requiring quality assurance:
result <- genesis_v2(
"Build a complete data analysis pipeline with visualizations",
use_computer_tools = TRUE,
max_iterations = 5,
quality_threshold = 85,
verbose = TRUE
)Advanced Usage
Sandbox Modes
The computer abstraction supports three sandbox modes:
| Mode | Description |
|---|---|
"none" |
No restrictions (use with caution) |
"permissive" |
Basic safety checks (default) |
"strict" |
Blocks dangerous commands |
Computer Methods
Bash Execution
Execute shell commands, CLIs, or scripts:
# Simple command
result <- comp$bash("ls -la")
# Pipe commands
result <- comp$bash("cat data.csv | head -n 5")
# Run CLI tools
result <- comp$bash("Rscript analysis.R")File Operations
Read and write files:
# Read a file
result <- comp$read_file("config.yaml")
# Write a file
result <- comp$write_file("output.txt", "Hello, World!")
# Create nested directories
result <- comp$write_file("results/analysis/plot.png", plot_data)R Code Execution
Execute R code in an isolated process:
# Simple computation
result <- comp$execute_r_code("mean(1:10)")
# Data analysis
result <- comp$execute_r_code("
data <- read.csv('data.csv')
summary(data)
")
# Create plots
result <- comp$execute_r_code("
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
theme_minimal()
")Using Computer Tools in Agents
Create agents with computer tools:
# Create computer tools
computer_tools <- create_computer_tools(
working_dir = getwd(),
sandbox_mode = "permissive"
)
# Create agent with computer tools
agent <- create_agent(
name = "DataAnalyst",
description = "Analyzes data using bash and R",
tools = computer_tools
)
# Run agent
result <- agent$run(
task = "Load mtcars and create a scatter plot of mpg vs wt",
model = "anthropic:claude-3-5-sonnet-20241022"
)Accessing Skills via Computer Tools
When using use_computer_tools = TRUE, skills are
accessed through the filesystem rather than direct tool calls:
# With computer tools, skills live in inst/skills/
# Agent reads SKILL.md to understand the skill
# Then executes scripts via bash
# Example workflow:
# 1. Read skill documentation
# result <- comp$read_file("inst/skills/greeting/SKILL.md")
#
# 2. Execute skill script
# result <- comp$bash("Rscript inst/skills/greeting/scripts/greet.R")
#
# 3. Read skill references if needed
# result <- comp$read_file("inst/skills/greeting/references/examples.md")Genesis Computer Prompt
When use_computer_tools = TRUE, Genesis uses a
specialized prompt that instructs the agent on how to access skills:
## Skills
Skills are available in the inst/skills/ directory. Each skill has:
- SKILL.md: Instructions and documentation
- scripts/: Executable R scripts
- references/: Reference materials
To use a skill:
1. Read inst/skills/<skill_name>/SKILL.md to understand it
2. Execute scripts via: bash('Rscript inst/skills/<skill_name>/scripts/<script>.R')
3. Read references if needed: read_file('inst/skills/<skill_name>/references/<file>')
Execution Logging
The Computer class maintains an execution log for observability:
# Execute some commands
comp$bash("echo 'hello'")
comp$read_file("data.txt")
comp$execute_r_code("summary(mtcars)")
# Get execution log
log <- comp$get_log()
print(log)
# Clear log
comp$clear_log()Best Practices
1. Choose the Right Mode
Use traditional mode (use_computer_tools = FALSE) when:
- You need simple, straightforward tasks - Working with a small number
of well-defined tools - Backward compatibility is important
Use computer tools mode (use_computer_tools = TRUE)
when: - Tasks involve complex data analysis pipelines - You need to run
custom scripts or CLIs - Context window usage is a concern - Tasks
require flexible, dynamic actions
3. Structure Your Skills
For computer tools mode, organize skills with clear SKILL.md files:
# inst/skills/data_analysis/SKILL.md
---
name: data_analysis
description: Statistical analysis and visualization for datasets
---
# Data Analysis Skill
This skill provides tools for analyzing datasets.
## Quick Start
Execute: `bash('Rscript inst/skills/data_analysis/scripts/analyze.R')`
## Parameters
Pass parameters via environment variables or modify the script.Comparison: Traditional vs. Computer Tools
| Feature | Traditional Mode | Computer Tools Mode |
|---|---|---|
| Tool Definitions | Loaded into context | 4 atomic tools only |
| Context Usage | Higher | 30-50% lower |
| Skill Access | Direct tool calls | Via bash/filesystem |
| Flexibility | Limited by tool set | Unlimited (bash) |
| Best For | Simple tasks | Complex workflows |
| Learning Curve | Lower | Higher |
Performance Tips
-
Cache Expensive Operations: Use the
cacheparameter ingenesis() - Optimize Scripts: Keep skill scripts focused and efficient
-
Use Appropriate Timeouts: Set
timeout_msbased on expected execution time -
Monitor Context Usage: Enable
verbose = TRUEto track token usage
Troubleshooting
Command Not Found
# Use full paths or ensure CLI is installed
result <- comp$bash("/usr/local/bin/python3 script.py")