UFO Client Overview

November 11, 2025 ยท View on GitHub

The UFO Client runs on target devices and serves as the execution layer of UFO's distributed agent system. It manages MCP (Model Context Protocol) servers, executes commands deterministically, and communicates with the Agent Server through the Agent Interaction Protocol (AIP).

Quick Start: Jump to the Quick Start Guide to connect your device. Make sure the Agent Server is running first.


๐ŸŽฏ What is the UFO Client?

graph LR
    subgraph "Agent Server (Brain)"
        Reasoning[High-Level Reasoning]
        Planning[Task Planning]
        Strategy[Strategy Selection]
    end
    
    subgraph "Agent Client (Hands)"
        Execution[Command Execution]
        Tools[Tool Management]
        Reporting[Status Reporting]
    end
    
    subgraph "Device Environment"
        Apps[Applications]
        Files[File System]
        UI[User Interface]
    end
    
    Reasoning -->|Directives| Execution
    Planning -->|Commands| Execution
    Strategy -->|Tasks| Execution
    
    Execution --> Tools
    Tools --> Apps
    Tools --> Files
    Tools --> UI
    
    Reporting -->|Results| Reasoning
    
    style Reasoning fill:#bbdefb
    style Execution fill:#c8e6c9
    style Tools fill:#fff9c4

The UFO Client is a stateless execution agent that:

CapabilityDescriptionBenefit
๐Ÿ”ง Executes CommandsTranslates server directives into concrete actionsDeterministic, reliable execution
๐Ÿ› ๏ธ Manages MCP ServersOrchestrates local and remote tool interfacesExtensible tool ecosystem
๐Ÿ“Š Reports Device InfoProvides hardware and software profile to serverIntelligent task assignment
๐Ÿ“ก Communicates via AIPMaintains persistent WebSocket connectionReal-time bidirectional communication
๐Ÿšซ Remains StatelessExecutes directives without high-level reasoningIndependent updates, simple architecture

Stateless Design Philosophy: The client focuses purely on execution. All reasoning and decision-making happens on the server, allowing independent updates to server logic and client tools, simple client architecture, intelligent orchestration of multiple clients, and resource-efficient operation.

Architecture: The UFO Client is part of UFO's distributed server-client architecture, where it handles command execution and resource access while the Agent Server handles orchestration and decision-making. See Server-Client Architecture for the complete design rationale, communication protocols, and deployment patterns.


๐Ÿ—๏ธ Architecture

The client implements a layered architecture separating communication, execution, and tool management for maximum flexibility and maintainability.

graph TB
    subgraph "Communication"
        WSC[WebSocket Client<br/>AIP Protocol]
    end
    
    subgraph "Orchestration"
        UFC[UFO Client]
        CM[Computer Manager]
    end
    
    subgraph "Execution"
        COMP[Computer]
        MCPM[MCP Manager]
    end
    
    subgraph "Tools"
        LOCAL[Local MCP Servers]
        REMOTE[Remote MCP Servers]
    end
    
    WSC --> UFC
    UFC --> CM
    CM --> COMP
    COMP --> MCPM
    MCPM --> LOCAL
    MCPM --> REMOTE
    
    style WSC fill:#bbdefb
    style UFC fill:#c8e6c9
    style COMP fill:#fff9c4
    style MCPM fill:#ffcdd2

Core Components

ComponentResponsibilityKey FeaturesDocumentation
WebSocket ClientAIP communicationโ€ข Connection management
โ€ข Registration
โ€ข Heartbeat monitoring
โ€ข Message routing
Details โ†’
UFO ClientExecution orchestrationโ€ข Command execution
โ€ข Result aggregation
โ€ข Error handling
โ€ข Session management
Details โ†’
Computer ManagerMulti-computer abstractionโ€ข Computer instance management
โ€ข Namespace routing
โ€ข Resource isolation
Details โ†’
ComputerTool managementโ€ข MCP server registration
โ€ข Tool registry
โ€ข Execution isolation
โ€ข Thread pool management
Details โ†’
MCP Server ManagerMCP lifecycleโ€ข Server creation
โ€ข Configuration loading
โ€ข Connection pooling
โ€ข Health monitoring
MCP Documentation โ†’
Device Info ProviderSystem profilingโ€ข Hardware detection
โ€ข Capability reporting
โ€ข Platform identification
โ€ข Feature enumeration
Details โ†’

For detailed component documentation:


๐Ÿš€ Key Capabilities

1. Deterministic Command Execution

The client executes commands exactly as specified without interpretation or reasoning, ensuring predictable behavior.

sequenceDiagram
    participant Server
    participant Client as UFO Client
    participant Computer
    participant Tool as MCP Tool
    
    Server->>Client: COMMAND (AIP)
    Client->>Computer: Execute Command
    Computer->>Computer: Lookup Tool
    Computer->>Tool: Execute with Timeout
    Tool-->>Computer: Result
    Computer-->>Client: Aggregated Result
    Client-->>Server: COMMAND_RESULTS (AIP)

Execution Flow:

StepActionPurpose
1๏ธโƒฃ ReceiveGet structured command from server via AIPEnsure well-formed input
2๏ธโƒฃ RouteDispatch to appropriate computer instanceSupport multi-namespace execution
3๏ธโƒฃ LookupFind tool in MCP registryDynamic tool resolution
4๏ธโƒฃ ExecuteRun tool in isolated thread poolFault isolation and timeout protection
5๏ธโƒฃ AggregateCombine results from multiple toolsStructured response format
6๏ธโƒฃ ReturnSend results back to server via AIPComplete the execution loop

Execution Guarantees:

  • Isolation: Each tool runs in separate thread pool
  • Timeouts: Configurable timeout (default: 6000 seconds/100 minutes)
  • Fault Tolerance: One failed tool doesn't crash entire client
  • Thread Safety: Concurrent tool execution supported
  • Error Reporting: Structured errors returned to server

2. MCP Server Management

The client manages a collection of MCP (Model Context Protocol) servers to provide diverse tool access for automation tasks. The client is responsible for registering, managing, and executing these tools, while the Agent Server handles command orchestration. See Server-Client Architecture for how MCP integration fits into the overall architecture.

MCP Server Categories:

Data Collection Servers gather information from the device:

Server TypeTools ProvidedUse Cases
System InfoCPU, memory, disk statsResource monitoring
Application StateRunning apps, windowsContext awareness
ScreenshotScreen captureVisual verification
UI Element DetectionControl trees, accessibilityUI automation

Example Tools: get_system_info(), list_running_apps(), capture_screenshot(), get_ui_tree()

Action Servers perform actions on the device:

Server TypeTools ProvidedUse Cases
GUI AutomationKeyboard, mouse, clicksUI interaction
Application ControlLaunch, close, focusApp management
File SystemRead, write, deleteFile operations
Command ExecutionShell commandsSystem automation

Example Tools: click_button(label), type_text(text), open_application(name), execute_command(cmd)

Server Types:

TypeDeploymentProsCons
Local MCP ServersRun in same process via FastMCPFast, no network overheadLimited to local capabilities
Remote MCP ServersConnect via HTTP/SSEScalable, shared servicesNetwork latency, external dependency

Example MCP Server Configuration:

mcp_servers:
  data_collection:
    - name: "system_info"
      type: "local"
      class: "SystemInfoServer"
    - name: "ui_detector"
      type: "local"
      class: "UIDetectionServer"
  
  action:
    - name: "gui_automation"
      type: "local"
      class: "GUIAutomationServer"
    - name: "file_ops"
      type: "remote"
      url: "http://localhost:8080/mcp"

See MCP Integration for comprehensive MCP server documentation.

3. Device Profiling

The client automatically collects and reports device information to enable the server to make intelligent task routing decisions.

Device Profile Structure:

{
  "device_id": "device_windows_001",
  "platform": "windows",
  "platform_type": "computer",
  "os_version": "10.0.22631",
  "system_info": {
    "cpu_count": 8,
    "memory_total_gb": 16.0,
    "disk_total_gb": 512.0,
    "hostname": "DESKTOP-ABC123",
    "ip_address": "192.168.1.100"
  },
  "supported_features": [
    "gui_automation",
    "cli_execution",
    "browser_control",
    "office_integration",
    "windows_apps"
  ],
  "installed_applications": [
    "Chrome",
    "Excel",
    "PowerPoint",
    "VSCode"
  ],
  "screen_resolution": "1920x1080",
  "connected_at": "2025-11-05T10:30:00Z"
}

Profile Usage on Server:

graph LR
    Client[Client Detects<br/>Device Info]
    Server[Server Stores<br/>Profile]
    Route[Server Routes<br/>Tasks]
    
    Client -->|Report Profile| Server
    Server -->|Match Requirements| Route
    Route -->|Dispatch Task| Client
    
    style Client fill:#bbdefb
    style Server fill:#c8e6c9
    style Route fill:#fff9c4

Server Uses Profile For:

Use CaseExample Logic
Platform MatchingRoute Excel task to Windows device
Capability FilteringOnly send browser tasks to devices with Chrome
Load BalancingDistribute tasks based on CPU/memory
Failure RecoveryReassign task if device disconnects

See Device Info Provider for detailed profiling documentation.

4. Resilient Communication

Robust, fault-tolerant communication with the server using strongly-typed AIP messages.

Connection Lifecycle:

stateDiagram-v2
    [*] --> Disconnected
    Disconnected --> Connecting: Initiate Connection
    Connecting --> Registering: WebSocket Established
    Registering --> Connected: Registration Success
    Connecting --> Disconnected: Connection Failed
    Registering --> Disconnected: Registration Failed
    
    Connected --> Heartbeating: Start Heartbeat Loop
    Heartbeating --> Heartbeating: Send/Receive Heartbeat
    Heartbeating --> Disconnected: Heartbeat Timeout
    Heartbeating --> Disconnected: WebSocket Closed
    
    Disconnected --> Connecting: Retry (Exponential Backoff)
    
    note right of Connected
        โ€ข Receive commands
        โ€ข Execute tasks
        โ€ข Report results
    end note
    
    note right of Heartbeating
        Default interval: 30s
        Timeout: 60s
    end note

Connection Features:

FeatureDescriptionConfiguration
Auto RegistrationRegisters with server on connectDevice ID, platform, capabilities
Exponential BackoffSmart retry on connection failureMax retries: 5 (default)
Heartbeat MonitoringKeep-alive mechanismInterval: 30s (configurable)
Graceful ReconnectionResume operation after disconnectAuto-reconnect on network recovery

Message Types:

MessageDirectionPurpose
REGISTRATIONClient โ†’ ServerRegister device with capabilities
REGISTRATION_ACKServer โ†’ ClientConfirm registration
HEARTBEATClient โ†” ServerKeep connection alive
COMMANDServer โ†’ ClientExecute task command
COMMAND_RESULTSClient โ†’ ServerReturn execution results
ERRORClient โ†’ ServerReport execution errors

See WebSocket Client and AIP Protocol for protocol details.


๐Ÿ“‹ Workflow Examples

Client Initialization & Registration

sequenceDiagram
    participant Main as Client Main
    participant MCP as MCP Manager
    participant WSC as WebSocket Client
    participant Server
    
    Main->>MCP: Initialize MCP Servers
    MCP-->>Main: Server Registry Ready
    
    Main->>WSC: Create Client & Connect
    WSC->>Server: WebSocket Connect
    Server-->>WSC: Connection Established
    
    WSC->>WSC: Collect Device Info
    WSC->>Server: REGISTRATION
    Server-->>WSC: REGISTRATION_ACK
    
    WSC->>WSC: Start Heartbeat Loop
    
    loop Every 30 seconds
        WSC->>Server: HEARTBEAT
        Server-->>WSC: HEARTBEAT_ACK
    end
    
    Note over WSC,Server: Ready to Execute Commands

Initialization Steps:

StepActionDetails
1๏ธโƒฃ Parse ArgsProcess command-line arguments--client-id, --ws-server, --platform
2๏ธโƒฃ Load ConfigLoad UFO configurationMCP servers, tools, settings
3๏ธโƒฃ Init MCPInitialize MCP server managerCreate local/remote servers
4๏ธโƒฃ Create ManagersCreate computer managerRegister MCP servers with computers
5๏ธโƒฃ ConnectEstablish WebSocket connectionConnect to server
6๏ธโƒฃ RegisterSend device profilePlatform, capabilities, system info
7๏ธโƒฃ HeartbeatStart keep-alive loopDefault: 30s interval
8๏ธโƒฃ ListenWait for commandsReady for task execution

Command Execution Flow

sequenceDiagram
    participant Server
    participant Client as UFO Client
    participant Comp as Computer
    participant Tool as MCP Tool
    
    Server->>Client: COMMAND<br/>{type: "click_button", args: {...}}
    Client->>Comp: execute_command()
    Comp->>Comp: find_tool("click_button")
    
    alt Tool Found
        Comp->>Tool: execute(args)
        Note over Tool: Thread Pool Execution<br/>6000s timeout
        Tool-->>Comp: Success
        Comp-->>Client: Result
        Client-->>Server: COMMAND_RESULTS<br/>{status: "completed"}
    else Tool Not Found
        Comp-->>Client: Error
        Client-->>Server: ERROR<br/>{error: "Tool not found"}
    end

๐Ÿ–ฅ๏ธ Platform Support

The client supports multiple platforms with platform-specific tool implementations.

PlatformStatusFeaturesNative Tools
Windowsโœ… Full Supportโ€ข UI Automation (UIAutomation API)
โ€ข COM API integration
โ€ข Office automation
โ€ข Windows-specific apps
PowerShell, Registry, WMI, Win32 API
Linuxโœ… Full Supportโ€ข Bash automation
โ€ข X11/Wayland GUI tools
โ€ข Package managers
โ€ข Linux applications
bash, apt/yum, systemd, xdotool
macOS๐Ÿšง In Developmentโ€ข macOS applications
โ€ข Automator integration
โ€ข AppleScript support
osascript, Automator, launchctl
Mobile๐Ÿ”ฎ Plannedโ€ข Touch interface
โ€ข Mobile apps
โ€ข Gesture control
ADB (Android), XCTest (iOS)

Platform Detection:

  • Automatic: Detected via platform.system() on startup
  • Override: Use --platform flag to specify manually
  • Validation: Server validates platform matches task requirements

Platform-Specific Example:

Windows:

# Windows-specific tools
tools = [
    "open_windows_app(name='Excel')",
    "execute_powershell(script='Get-Process')",
    "read_registry(key='HKLM\\Software')"
]

Linux:

# Linux-specific tools
tools = [
    "execute_bash(command='ls -la')",
    "install_package(name='vim')",
    "control_systemd(service='nginx', action='restart')"
]

โš™๏ธ Configuration

Command-Line Arguments

Start the UFO client with:

python -m ufo.client.client [OPTIONS]

Available Options:

OptionTypeDefaultDescriptionExample
--client-idstrclient_001Unique client identifier--client-id device_win_001
--ws-serverstrws://localhost:5000/wsWebSocket server URL--ws-server ws://192.168.1.10:5000/ws
--wsflagFalseEnable WebSocket mode (required)--ws
--max-retriesint5Connection retry limit--max-retries 10
--platformstrAuto-detectPlatform override--platform windows
--log-levelstrWARNINGLogging verbosity--log-level DEBUG

Quick Start Command:

# Minimal command (default server)
python -m ufo.client.client --ws --client-id my_device

# Production command (custom server)
python -m ufo.client.client \
  --ws \
  --client-id device_production_01 \
  --ws-server ws://ufo-server.company.com:5000/ws \
  --max-retries 10 \
  --log-level INFO

UFO Configuration

The client inherits settings from config_dev.yaml:

Key Configuration Sections:

SectionPurposeExample
MCP ServersDefine data collection and action serversmcp_servers.data_collection, mcp_servers.action
Tool SettingsTool-specific parametersTimeouts, retries, API keys
LoggingLog levels, formats, destinationsFile logging, console output
Platform SettingsOS-specific configurationsWindows UI automation settings

Sample Configuration:

client:
  heartbeat_interval: 30  # seconds
  command_timeout: 6000   # seconds (100 minutes)
  max_concurrent_tools: 10

mcp_servers:
  data_collection:
    - name: system_info
      type: local
      enabled: true
  action:
    - name: gui_automation
      type: local
      enabled: true
      settings:
        click_delay: 0.5
        typing_speed: 100  # chars per minute

logging:
  level: INFO
  format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
  file: "logs/client.log"

See Configuration Guide for comprehensive documentation.


โš ๏ธ Error Handling

The client is designed to handle various failure scenarios gracefully without crashing.

Connection Failures

stateDiagram-v2
    [*] --> Attempting
    Attempting --> Connected: Success
    Attempting --> Failed: Error
    
    Failed --> Waiting: Exponential Backoff
    Waiting --> Attempting: Retry (2^n seconds)
    
    Failed --> [*]: Max Retries Exceeded
    
    note right of Waiting
        Retry Delays:
        1st: 2s
        2nd: 4s
        3rd: 8s
        4th: 16s
        5th: 32s
    end note

Connection Error Handling:

ScenarioClient BehaviorConfiguration
Initial Connection FailedExponential backoff retry--max-retries (default: 5)
Connection LostAttempt reconnectionAutomatic
Max Retries ExceededExit with error codeLog error, exit
Server UnreachableLog error, retryBackoff between retries

Tool Execution Failures

Protection Mechanisms:

MechanismPurposeDefault Value
Thread Pool IsolationPrevent one tool from blocking othersEnabled
Execution TimeoutKill hung tools6000 seconds (100 minutes)
Exception CatchingGraceful error handlingAll tools wrapped
Error ReportingNotify server of failuresStructured error messages

Error Handling Example:

# Client automatically handles tool errors
try:
    result = tool.execute(args)
    return {"status": "success", "result": result}
except TimeoutError:
    return {"status": "error", "error": "Tool execution timeout"}
except Exception as e:
    return {"status": "error", "error": str(e)}

Server Disconnection

Graceful Shutdown Process:

  1. Detect Disconnection - WebSocket connection lost
  2. Stop Heartbeat - Terminate keep-alive loop
  3. Cancel Pending Tasks - Abort in-progress commands
  4. Attempt Reconnection - Use exponential backoff
  5. Clean Shutdown - If max retries exceeded

โœ… Best Practices

Development Best Practices

1. Use Unique Client IDs

# Bad: Generic ID
--client-id client_001

# Good: Descriptive ID
--client-id device_win_dev_john_laptop

2. Start with INFO Logging

# Development: WARNING for normal operation (default)
--log-level WARNING

# Debugging: DEBUG for troubleshooting
--log-level DEBUG

3. Test MCP Connectivity First

# Verify MCP servers are accessible before running client
from ufo.client.mcp.mcp_server_manager import MCPServerManager

manager = MCPServerManager()
# Test server creation from configuration

Production Best Practices

1. Use Descriptive Client IDs

# Include environment, location, purpose
--client-id device_windows_production_office_01
--client-id device_linux_staging_lab_02

2. Configure Automatic Restart

systemd (Linux):

[Unit]
Description=UFO Agent Client
After=network.target
    
[Service]
Type=simple
User=ufo
WorkingDirectory=/opt/ufo
ExecStart=/usr/bin/python3 -m ufo.client.client \
  --ws \
  --client-id device_linux_prod_01 \
  --ws-server ws://ufo-server.internal:5000/ws \
  --log-level INFO
Restart=always
RestartSec=10
    
[Install]
WantedBy=multi-user.target

PM2 (Cross-platform):

{
  "apps": [{
    "name": "ufo-client",
    "script": "python",
    "args": [
      "-m", "ufo.client.client",
      "--ws",
      "--client-id", "device_win_prod_01",
      "--ws-server", "ws://ufo-server.internal:5000/ws",
      "--log-level", "INFO"
    ],
    "cwd": "C:\\ufo",
    "restart_delay": 5000,
    "max_restarts": 10
  }]
}

3. Monitor Connection Health

# Check logs for connection status
tail -f logs/client.log | grep -E "Connected|Disconnected|ERROR"

Security Best Practices

!!! warning "Security Considerations"

| Practice | Description | Implementation |
|----------|-------------|----------------|
| **Use WSS** | Encrypt WebSocket communication | `wss://server:5000/ws` instead of `ws://` |
| **Validate Server** | Verify server certificate | Configure SSL/TLS verification |
| **Restrict Tools** | Limit MCP server access | Only enable necessary tools |
| **Least Privilege** | Run with minimum permissions | Create dedicated user account |
| **Network Isolation** | Use firewalls and VPNs | Restrict server access to internal network |

๐ŸŽ“ Documentation Map

Getting Started

DocumentPurposeWhen to Read
Quick StartConnect your device quicklyFirst time setup
Server Quick StartUnderstand server-side setupBefore running client

Component Details

DocumentComponentTopics Covered
WebSocket ClientCommunication layerAIP protocol, connection management
UFO ClientOrchestrationSession tracking, command execution
Computer ManagerMulti-computer abstractionNamespace management, routing
ComputerTool managementMCP registry, execution
Device InfoSystem profilingHardware detection, capabilities
MCP IntegrationMCP serversServer types, configuration
DocumentTopicRelevance
Server OverviewServer architectureUnderstand the other half
AIP ProtocolCommunication protocolDeep dive into messaging
ConfigurationUFO configurationCustomize behavior

๐Ÿ”„ Client vs. Server

Understanding the clear division between client and server responsibilities is crucial for effective system design.

Responsibility Matrix:

AspectClient (Execution)Server (Orchestration)
Primary RoleExecute directives deterministicallyReason about tasks, plan actions
State ManagementStateless (no session memory)Stateful (maintains sessions)
ReasoningNone (pure execution)Full (high-level decision-making)
ToolsMCP servers (local/remote)Agent strategies, prompts, LLMs
CommunicationDevice โ†” Server (AIP)Multi-client coordination
UpdatesTool implementation changesStrategy and logic updates
ComplexityLow (simple execution loop)High (complex orchestration)
DependenciesMCP servers, system APIsLLMs, databases, client registry

Workflow Comparison:

graph TB
    subgraph "Server Workflow"
        S1[Receive User Request]
        S2[Reason About Task]
        S3[Plan Execution Steps]
        S4[Select Target Device]
        S5[Send Commands]
    end
    
    subgraph "Client Workflow"
        C1[Receive Command]
        C2[Lookup Tool]
        C3[Execute Tool]
        C4[Return Result]
    end
    
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> S5
    S5 -.->|AIP| C1
    C1 --> C2
    C2 --> C3
    C3 --> C4
    C4 -.->|AIP| S5
    
    style S1 fill:#bbdefb
    style S2 fill:#bbdefb
    style S3 fill:#bbdefb
    style C1 fill:#c8e6c9
    style C2 fill:#c8e6c9
    style C3 fill:#c8e6c9

Decoupled Architecture Benefits:

  • Independent Updates: Modify server logic without touching clients
  • Flexible Deployment: Run clients on any platform
  • Scalability: Add more clients without server changes
  • Maintainability: Simpler client code, easier debugging
  • Testability: Test client and server independently

๐Ÿš€ Next Steps

1. Run Your First Client

# Follow the quick start guide
python -m ufo.client.client \
  --ws \
  --client-id my_first_device \
  --ws-server ws://localhost:5000/ws

๐Ÿ‘‰ Quick Start Guide

2. Understand Registration Process

Learn how clients register with the server, device profile structure, and registration acknowledgment.

๐Ÿ‘‰ Server Quick Start - Start server and connect clients

3. Explore MCP Integration

Learn about MCP servers, configure custom tools, and create your own MCP servers.

๐Ÿ‘‰ MCP Integration

4. Configure for Your Environment

Customize MCP servers, adjust timeouts and retries, and configure platform-specific settings.

๐Ÿ‘‰ Configuration Guide

5. Master the Protocol

Deep dive into AIP messages, understand message flow, and error handling patterns.

๐Ÿ‘‰ AIP Protocol