StateSet Computer Use Agent - Architecture Overview
Executive Summary
StateSet Computer Use Agent is a production-grade AI automation platform powered by Claude Opus 4.5. The system deploys multiple specialized AI agents that can see, understand, and interact with desktop environments to complete complex, long-running tasks autonomously. Built with Python using async/await patterns throughout, the platform implements Anthropic’s context engineering research achieving 95% cost savings compared to naive approaches. Key Metrics:- Average tokens/task: 7,500 (95% reduction from 150k baseline)
- Average cost/task: 2.25 baseline)
- Average task duration: 30 seconds (33% faster with parallel execution)
- Parallel speedup: 30-50% on multi-tool tasks
System Architecture Diagram
Core Components
1. Main Orchestrator (main.py)
The entry point for all agent execution, responsible for:
Environment Validation:
2. Agent Loop (agent/loop.py)
The core conversation engine with Claude API:
Sampling Loop:
| Provider | Model ID | Use Case |
|---|---|---|
| ANTHROPIC | claude-opus-4-5-20251101 | Direct API access |
| BEDROCK | anthropic.claude-opus-4-5-20251101-v1:0 | AWS infrastructure |
| VERTEX | claude-opus-4-5-20251101 | Google Cloud |
prompt-caching-2024-07-31- 90% cost reduction on cached tokensadvanced-tool-use-2025-11-20- Tool search (regex/bm25)effort-2025-11-24- Effort parameter (low/medium/high)computer-use-2025-11-24- Latest tool version with zoom action
3. Tool System (agent/tools/)
Tool Hierarchy:
| Version | Release | Features |
|---|---|---|
| computer_use_20251124 | Current | Zoom action, deferred tool loading |
| computer_use_20250124 | Previous | Stable production version |
| computer_use_20241022 | Legacy | Backward compatibility |
Advanced Capabilities
4. Subagent System (agent/subagent.py)
Implements Anthropic’s sub-agent compression pattern for 95% context savings:
Subagent Types:
| Type | Model | Max Tokens | Use Case |
|---|---|---|---|
| EXPLORE | Haiku | 4096 | Fast codebase exploration |
| ANALYZE | Sonnet | 8192 | Deep analysis with thinking |
| EXECUTE | Sonnet | 4096 | Task execution with verification |
| RESEARCH | Haiku | 4096 | Web search and synthesis |
| CODE | Sonnet | 8192 | Code generation/modification |
5. MCP Client Integration (agent/mcp_client.py)
Connect to external Model Context Protocol servers:
Supported Transports:
- STDIO (subprocess)
- SSE (Server-Sent Events)
- HTTP (direct HTTP)
6. Structured Output (agent/structured_output.py)
Force Claude to return valid JSON matching specified schemas:
Pre-defined Schemas:
TICKET_ANALYSIS_SCHEMA- Support ticket analysisTASK_RESULT_SCHEMA- Task completion resultsCODE_ANALYSIS_SCHEMA- Code review findingsENTITY_EXTRACTION_SCHEMA- Entity extraction
Optimization Systems
7. Parallel Executor (agent/parallel_executor.py)
Automatic parallel execution for independent tool calls:
Dependency Analysis:
8. Context Optimizer (agent/context_optimizer.py)
Implements 5 Anthropic context engineering patterns:
Pattern 1: Just-in-Time Retrieval
9. Tool Execution Guard (agent/tool_guard.py)
Safety and verification layer:
Features:
- Pre-execution Validation: Safety checks before tool execution
- Visual Verification: Confirms actions took effect (optional)
- Stuck Detection: Monitors for infinite loops
- Result Caching: 120-second TTL for cacheable operations
10. Stuck Detection (agent/stuck_detection.py)
Prevents infinite loops and stuck patterns:
Detection Methods:
- Repeating same action consecutively
- Cycling between 2-3 actions
- No visual progress (identical screenshots)
- Slow progress (too few actions per time)
Observability System
11. Unified Observability (agent/observability/)
Single interface for all observability concerns:
Configuration:
| Component | Purpose | Backend |
|---|---|---|
| Structured Logging | JSON logs with context | Python logging |
| Distributed Tracing | Request correlation | OpenTelemetry |
| Metrics | Performance tracking | Prometheus |
| Event Streaming | Real-time updates | SSE/WebSocket |
| Health Monitoring | System health | Circuit breakers |
Infrastructure
12. Configuration Management (agent/config.py)
Centralized configuration with documented rationale:
Configuration Classes:
13. Exception Hierarchy (agent/exceptions.py)
Comprehensive error handling:
14. Health Monitoring (agent/health.py)
Production health checks:
HEALTHY- All checks passingDEGRADED- Some checks failing, system operationalUNHEALTHY- Critical failures
Dashboard Architecture
15. Backend (dashboard/backend/)
FastAPI REST API with async operations:
- FastAPI with CORS
- SQLAlchemy async ORM
- PostgreSQL database
- Celery task queue
- Server-Sent Events (SSE)
- S3-compatible artifact storage (boto3)
16. Frontend (dashboard/frontend/)
Next.js 14 application:
- Next.js 14 with app router
- React Query for data fetching
- Tailwind CSS styling
- EventSource for real-time updates
Execution Flow
Complete Request Flow
Agent Types
Supported Agents
| Agent Type | Keywords | Purpose |
|---|---|---|
| AUTO_CLOSE | ”auto-close”, “ticket” | Close resolved support tickets |
| SOCIAL_MEDIA | ”social media”, “moderate” | Content moderation |
| LINKEDIN_MESSENGER | ”linkedin”, “outreach” | LinkedIn automation |
| SLACK_SUPPORT | ”slack”, “support” | Slack support automation |
| SHOPIFY | ”shopify”, “e-commerce” | E-commerce management |
| ONBOARDING | ”onboarding”, “setup” | User onboarding |
| STATESET_AGENTIC | ”stateset”, “custom” | Custom tasks |
Agent Configuration
Security Architecture
API Key Management
- All keys via environment variables
- Validation on startup
- No key transmission to external services
Tool Safety
- Directory traversal prevention in EditTool
- Prompt injection protection in MemoryTool
- Pre-execution validation via ToolExecutionGuard
- Agent memory isolation (per agent_id)
Sandbox Execution
- Tools run in controlled environment
- File system access limited by permissions
- Network access controlled by system
Performance Characteristics
Benchmarks
| Metric | Value | Notes |
|---|---|---|
| Tokens/task | 7,500 | 95% reduction from 150k |
| Cost/task | $0.11 | 95% savings from $2.25 |
| Task duration | 30s | 33% faster with parallel |
| Parallel speedup | 30-50% | On multi-tool tasks |
| Typing speed | 8ms/char | Optimized from 50ms |
| Bash timeout | 60s | Optimized from 120s |
Cost Breakdown
| Operation | Price |
|---|---|
| Input tokens | $3.00/1M |
| Output tokens | $15.00/1M |
| Cached input | $0.30/1M (90% savings) |
File Organization
Extension Points
Adding New Agents
- Define AgentConfig in
AGENT_CONFIGS - Add keyword detection in
get_active_agents() - Create completion indicators in
analyze_task_completion()
Adding New Tools
- Inherit from
BaseAnthropicTool - Implement
__call__returningToolResult - Add to version groups in
agent/tools/groups.py - Update tool traits if cacheable/read-only
Adding MCP Servers
Quick Reference
Environment Variables
Common Commands
This architecture provides a scalable, maintainable foundation for computer use automation with AI agents, implementing production-grade patterns for reliability, observability, and cost optimization.