cua-agent 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cua-agent might be problematic. Click here for more details.
- cua_agent-0.1.0/PKG-INFO +44 -0
- cua_agent-0.1.0/README.md +213 -0
- cua_agent-0.1.0/agent/README.md +63 -0
- cua_agent-0.1.0/agent/__init__.py +10 -0
- cua_agent-0.1.0/agent/core/README.md +101 -0
- cua_agent-0.1.0/agent/core/__init__.py +34 -0
- cua_agent-0.1.0/agent/core/agent.py +284 -0
- cua_agent-0.1.0/agent/core/base_agent.py +164 -0
- cua_agent-0.1.0/agent/core/callbacks.py +147 -0
- cua_agent-0.1.0/agent/core/computer_agent.py +69 -0
- cua_agent-0.1.0/agent/core/experiment.py +222 -0
- cua_agent-0.1.0/agent/core/factory.py +102 -0
- cua_agent-0.1.0/agent/core/loop.py +244 -0
- cua_agent-0.1.0/agent/core/messages.py +230 -0
- cua_agent-0.1.0/agent/core/tools/__init__.py +21 -0
- cua_agent-0.1.0/agent/core/tools/base.py +74 -0
- cua_agent-0.1.0/agent/core/tools/bash.py +52 -0
- cua_agent-0.1.0/agent/core/tools/collection.py +46 -0
- cua_agent-0.1.0/agent/core/tools/computer.py +113 -0
- cua_agent-0.1.0/agent/core/tools/edit.py +67 -0
- cua_agent-0.1.0/agent/core/tools/manager.py +56 -0
- cua_agent-0.1.0/agent/providers/__init__.py +4 -0
- cua_agent-0.1.0/agent/providers/anthropic/__init__.py +6 -0
- cua_agent-0.1.0/agent/providers/anthropic/api/client.py +222 -0
- cua_agent-0.1.0/agent/providers/anthropic/api/logging.py +150 -0
- cua_agent-0.1.0/agent/providers/anthropic/callbacks/manager.py +55 -0
- cua_agent-0.1.0/agent/providers/anthropic/loop.py +521 -0
- cua_agent-0.1.0/agent/providers/anthropic/messages/manager.py +110 -0
- cua_agent-0.1.0/agent/providers/anthropic/prompts.py +20 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/__init__.py +33 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/base.py +88 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/bash.py +163 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/collection.py +34 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/computer.py +550 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/edit.py +326 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/manager.py +54 -0
- cua_agent-0.1.0/agent/providers/anthropic/tools/run.py +42 -0
- cua_agent-0.1.0/agent/providers/anthropic/types.py +16 -0
- cua_agent-0.1.0/agent/providers/omni/__init__.py +27 -0
- cua_agent-0.1.0/agent/providers/omni/callbacks.py +78 -0
- cua_agent-0.1.0/agent/providers/omni/clients/anthropic.py +99 -0
- cua_agent-0.1.0/agent/providers/omni/clients/base.py +44 -0
- cua_agent-0.1.0/agent/providers/omni/clients/groq.py +101 -0
- cua_agent-0.1.0/agent/providers/omni/clients/openai.py +159 -0
- cua_agent-0.1.0/agent/providers/omni/clients/utils.py +25 -0
- cua_agent-0.1.0/agent/providers/omni/experiment.py +273 -0
- cua_agent-0.1.0/agent/providers/omni/image_utils.py +106 -0
- cua_agent-0.1.0/agent/providers/omni/loop.py +961 -0
- cua_agent-0.1.0/agent/providers/omni/messages.py +168 -0
- cua_agent-0.1.0/agent/providers/omni/parser.py +252 -0
- cua_agent-0.1.0/agent/providers/omni/prompts.py +78 -0
- cua_agent-0.1.0/agent/providers/omni/tool_manager.py +91 -0
- cua_agent-0.1.0/agent/providers/omni/tools/__init__.py +13 -0
- cua_agent-0.1.0/agent/providers/omni/tools/bash.py +69 -0
- cua_agent-0.1.0/agent/providers/omni/tools/computer.py +216 -0
- cua_agent-0.1.0/agent/providers/omni/tools/manager.py +83 -0
- cua_agent-0.1.0/agent/providers/omni/types.py +30 -0
- cua_agent-0.1.0/agent/providers/omni/utils.py +155 -0
- cua_agent-0.1.0/agent/providers/omni/visualization.py +130 -0
- cua_agent-0.1.0/agent/types/__init__.py +26 -0
- cua_agent-0.1.0/agent/types/base.py +52 -0
- cua_agent-0.1.0/agent/types/messages.py +36 -0
- cua_agent-0.1.0/agent/types/tools.py +32 -0
- cua_agent-0.1.0/pyproject.toml +117 -0
- cua_agent-0.1.0/tests/test_agent.py +91 -0
cua_agent-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cua-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CUA (Computer Use) Agent for AI-driven computer interaction
|
|
5
|
+
Author-Email: TryCua <gh@trycua.com>
|
|
6
|
+
Requires-Python: <3.13,>=3.10
|
|
7
|
+
Requires-Dist: httpx<0.29.0,>=0.27.0
|
|
8
|
+
Requires-Dist: aiohttp<4.0.0,>=3.9.3
|
|
9
|
+
Requires-Dist: asyncio
|
|
10
|
+
Requires-Dist: anyio<5.0.0,>=4.4.1
|
|
11
|
+
Requires-Dist: typing-extensions<5.0.0,>=4.12.2
|
|
12
|
+
Requires-Dist: pydantic<3.0.0,>=2.6.4
|
|
13
|
+
Requires-Dist: rich<14.0.0,>=13.7.1
|
|
14
|
+
Requires-Dist: python-dotenv<2.0.0,>=1.0.1
|
|
15
|
+
Requires-Dist: cua-computer<0.2.0,>=0.1.0
|
|
16
|
+
Requires-Dist: certifi>=2024.2.2
|
|
17
|
+
Provides-Extra: anthropic
|
|
18
|
+
Requires-Dist: anthropic>=0.49.0; extra == "anthropic"
|
|
19
|
+
Requires-Dist: boto3<2.0.0,>=1.35.81; extra == "anthropic"
|
|
20
|
+
Provides-Extra: som
|
|
21
|
+
Requires-Dist: torch>=2.2.1; extra == "som"
|
|
22
|
+
Requires-Dist: torchvision>=0.17.1; extra == "som"
|
|
23
|
+
Requires-Dist: ultralytics>=8.0.0; extra == "som"
|
|
24
|
+
Requires-Dist: transformers>=4.38.2; extra == "som"
|
|
25
|
+
Requires-Dist: cua-som<0.2.0,>=0.1.0; extra == "som"
|
|
26
|
+
Requires-Dist: anthropic<0.47.0,>=0.46.0; extra == "som"
|
|
27
|
+
Requires-Dist: boto3<2.0.0,>=1.35.81; extra == "som"
|
|
28
|
+
Requires-Dist: openai<2.0.0,>=1.14.0; extra == "som"
|
|
29
|
+
Requires-Dist: groq<0.5.0,>=0.4.0; extra == "som"
|
|
30
|
+
Requires-Dist: dashscope<2.0.0,>=1.13.0; extra == "som"
|
|
31
|
+
Requires-Dist: requests<3.0.0,>=2.31.0; extra == "som"
|
|
32
|
+
Provides-Extra: all
|
|
33
|
+
Requires-Dist: torch>=2.2.1; extra == "all"
|
|
34
|
+
Requires-Dist: torchvision>=0.17.1; extra == "all"
|
|
35
|
+
Requires-Dist: ultralytics>=8.0.0; extra == "all"
|
|
36
|
+
Requires-Dist: transformers>=4.38.2; extra == "all"
|
|
37
|
+
Requires-Dist: cua-som<0.2.0,>=0.1.0; extra == "all"
|
|
38
|
+
Requires-Dist: anthropic<0.47.0,>=0.46.0; extra == "all"
|
|
39
|
+
Requires-Dist: boto3<2.0.0,>=1.35.81; extra == "all"
|
|
40
|
+
Requires-Dist: openai<2.0.0,>=1.14.0; extra == "all"
|
|
41
|
+
Requires-Dist: groq<0.5.0,>=0.4.0; extra == "all"
|
|
42
|
+
Requires-Dist: dashscope<2.0.0,>=1.13.0; extra == "all"
|
|
43
|
+
Requires-Dist: requests<3.0.0,>=2.31.0; extra == "all"
|
|
44
|
+
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>
|
|
3
|
+
<div class="image-wrapper" style="display: inline-block;">
|
|
4
|
+
<picture>
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" alt="logo" height="150" srcset="../../img/logo_white.png" style="display: block; margin: auto;">
|
|
6
|
+
<source media="(prefers-color-scheme: light)" alt="logo" height="150" srcset="../../img/logo_black.png" style="display: block; margin: auto;">
|
|
7
|
+
<img alt="Shows my svg">
|
|
8
|
+
</picture>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
[](#)
|
|
12
|
+
[](#)
|
|
13
|
+
[](https://discord.com/invite/mVnXXpdE85)
|
|
14
|
+
[](https://pypi.org/project/cua-computer/)
|
|
15
|
+
</h1>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
**Agent** is a Computer Use (CUA) framework for running multi-app agentic workflows targeting macOS and Linux sandbox, supporting local (Ollama) and cloud model providers (OpenAI, Anthropic, Groq, DeepSeek, Qwen). The framework integrates with Microsoft's OmniParser for enhanced UI understanding and interaction.
|
|
19
|
+
|
|
20
|
+
### Get started with Agent
|
|
21
|
+
|
|
22
|
+
There are two ways to use the agent: with OmniParser for enhanced UI understanding (recommended) or with basic computer control.
|
|
23
|
+
|
|
24
|
+
#### Option 1: With OmniParser (Recommended)
|
|
25
|
+
|
|
26
|
+
<div align="center">
|
|
27
|
+
<img src="../../img/agent.png"/>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from agent.providers.omni import OmniComputerAgent, APIProvider
|
|
32
|
+
|
|
33
|
+
# Set your API key
|
|
34
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
35
|
+
|
|
36
|
+
# Initialize agent with OmniParser for enhanced UI understanding
|
|
37
|
+
agent = OmniComputerAgent(
|
|
38
|
+
provider=APIProvider.OPENAI,
|
|
39
|
+
model="gpt-4o",
|
|
40
|
+
start_omniparser=True # Automatically starts OmniParser server
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
task = """
|
|
44
|
+
1. Search the ai-gradio repo on GitHub.
|
|
45
|
+
2. Clone it to the desktop.
|
|
46
|
+
3. Open the repo with the Cursor app.
|
|
47
|
+
4. Work with Cursor to add a new provider for Cua.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
async with agent: # Ensures proper cleanup
|
|
51
|
+
async for result in agent.run(task):
|
|
52
|
+
print(result)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Option 2: Basic Computer Control
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from agent.computer_agent import ComputerAgent
|
|
59
|
+
from agent.base.types import Provider
|
|
60
|
+
|
|
61
|
+
# Set your API key (supports any provider)
|
|
62
|
+
export OPENAI_API_KEY="your-openai-api-key" # or other provider keys
|
|
63
|
+
|
|
64
|
+
# Initialize basic agent
|
|
65
|
+
agent = ComputerAgent(
|
|
66
|
+
provider=Provider.OPENAI, # or ANTHROPIC, GROQ, etc.
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
task = """
|
|
70
|
+
1. Open Chrome and navigate to github.com
|
|
71
|
+
2. Search for 'trycua/cua'
|
|
72
|
+
3. Star the repository
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
async with agent:
|
|
76
|
+
async for result in agent.run(task):
|
|
77
|
+
print(result)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Install
|
|
81
|
+
|
|
82
|
+
### cua-agent
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Basic installation with Anthropic
|
|
86
|
+
pip install cua-agent[anthropic]
|
|
87
|
+
|
|
88
|
+
# Install with OmniParser (recommended)
|
|
89
|
+
# Includes all provider dependencies (OpenAI, Anthropic, etc.)
|
|
90
|
+
pip install cua-agent[omni]
|
|
91
|
+
|
|
92
|
+
# Install with all features and providers
|
|
93
|
+
pip install cua-agent[all]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Features
|
|
97
|
+
|
|
98
|
+
### OmniParser Integration
|
|
99
|
+
- Enhanced UI understanding with element detection
|
|
100
|
+
- Automatic bounding box detection for UI elements
|
|
101
|
+
- Improved accuracy for complex UI interactions
|
|
102
|
+
- Support for icon and text element recognition
|
|
103
|
+
|
|
104
|
+
### Basic Computer Control
|
|
105
|
+
- Direct keyboard and mouse control
|
|
106
|
+
- Window and application management
|
|
107
|
+
- Screenshot capabilities
|
|
108
|
+
- Basic UI element detection
|
|
109
|
+
|
|
110
|
+
### Provider Support
|
|
111
|
+
- OpenAI (GPT-4V) - Recommended for OmniParser integration
|
|
112
|
+
- Anthropic (Claude) - Strong general performance
|
|
113
|
+
- Groq - Fast inference with Llama models
|
|
114
|
+
- DeepSeek - Alternative model provider
|
|
115
|
+
- Qwen - Alibaba's multimodal model
|
|
116
|
+
|
|
117
|
+
## Run
|
|
118
|
+
|
|
119
|
+
Refer to these notebooks for step-by-step guides on how to use the Computer-Use Agent (CUA):
|
|
120
|
+
|
|
121
|
+
- [Getting Started with OmniParser](../../notebooks/omniparser_nb.ipynb) - Enhanced UI understanding
|
|
122
|
+
- [Basic Computer Control](../../notebooks/basic_agent_nb.ipynb) - Simple computer interactions
|
|
123
|
+
- [Advanced Usage](../../notebooks/agent_nb.ipynb) - Complete examples and workflows
|
|
124
|
+
|
|
125
|
+
# Computer Agent Library
|
|
126
|
+
|
|
127
|
+
A Python library for controlling computer interactions with AI agents.
|
|
128
|
+
|
|
129
|
+
## Introduction
|
|
130
|
+
|
|
131
|
+
This library provides a unified interface for AI-powered computer interaction agents, allowing applications to automate UI interactions through various AI providers.
|
|
132
|
+
|
|
133
|
+
## Key Features
|
|
134
|
+
|
|
135
|
+
- **Unified Agent**: Single `ComputerAgent` class with configurable loop types
|
|
136
|
+
- **Multiple AI providers**: Support for OpenAI, Anthropic, Groq, and other providers
|
|
137
|
+
- **Screen analysis**: Intelligent screen parsing and element identification
|
|
138
|
+
- **Tool execution**: Execute tools and commands to interact with the computer
|
|
139
|
+
- **Trajectory saving**: Option to save screenshots and logs for debugging and analysis
|
|
140
|
+
|
|
141
|
+
## Installation
|
|
142
|
+
|
|
143
|
+
To install the library along with its dependencies:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pip install -e .
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Usage
|
|
150
|
+
|
|
151
|
+
Here's a simple example of how to use the ComputerAgent:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import asyncio
|
|
155
|
+
from computer import Computer
|
|
156
|
+
from agent.core.agent import ComputerAgent
|
|
157
|
+
from agent.types.base import AgenticLoop
|
|
158
|
+
from agent.providers.omni.types import APIProvider
|
|
159
|
+
|
|
160
|
+
async def main():
|
|
161
|
+
# Initialize the computer interface
|
|
162
|
+
computer = Computer()
|
|
163
|
+
|
|
164
|
+
# Create a computer agent
|
|
165
|
+
agent = ComputerAgent(
|
|
166
|
+
computer=computer,
|
|
167
|
+
loop_type=AgenticLoop.OMNI, # Use OMNI loop
|
|
168
|
+
provider=APIProvider.OPENAI, # With OpenAI provider
|
|
169
|
+
model="gpt-4o", # Specify the model
|
|
170
|
+
save_trajectory=True, # Save logs and screenshots
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# Use the agent with a context manager
|
|
174
|
+
async with agent:
|
|
175
|
+
# Run a task
|
|
176
|
+
async for result in agent.run("Open Safari and navigate to github.com"):
|
|
177
|
+
# Process the result
|
|
178
|
+
title = result["metadata"].get("title", "Screen Analysis")
|
|
179
|
+
content = result["content"]
|
|
180
|
+
print(f"\n{title}")
|
|
181
|
+
print(content)
|
|
182
|
+
|
|
183
|
+
if __name__ == "__main__":
|
|
184
|
+
asyncio.run(main())
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Components
|
|
188
|
+
|
|
189
|
+
The library consists of several components:
|
|
190
|
+
|
|
191
|
+
- **Core**
|
|
192
|
+
- `ComputerAgent`: Unified agent class supporting multiple loop types
|
|
193
|
+
- `BaseComputerAgent`: Abstract base class for computer agents
|
|
194
|
+
|
|
195
|
+
- **Providers**
|
|
196
|
+
- `Anthropic`: Implementation for Anthropic Claude models
|
|
197
|
+
- `Omni`: Implementation for multiple providers (OpenAI, Groq, etc.)
|
|
198
|
+
|
|
199
|
+
- **Loops**
|
|
200
|
+
- `AnthropicLoop`: Loop implementation for Anthropic
|
|
201
|
+
- `OmniLoop`: Generic loop supporting multiple providers
|
|
202
|
+
|
|
203
|
+
## Configuration
|
|
204
|
+
|
|
205
|
+
The agent can be configured with various parameters:
|
|
206
|
+
|
|
207
|
+
- **loop_type**: The type of loop to use (ANTHROPIC or OMNI)
|
|
208
|
+
- **provider**: AI provider to use with the loop
|
|
209
|
+
- **model**: The AI model to use
|
|
210
|
+
- **save_trajectory**: Whether to save screenshots and logs
|
|
211
|
+
- **only_n_most_recent_images**: Only keep a specific number of recent images
|
|
212
|
+
|
|
213
|
+
See the [Core README](./agent/core/README.md) for more details on the unified agent.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Agent Package Structure
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The agent package provides a modular and extensible framework for AI-powered computer agents.
|
|
5
|
+
|
|
6
|
+
## Directory Structure
|
|
7
|
+
```
|
|
8
|
+
agent/
|
|
9
|
+
├── __init__.py # Package exports
|
|
10
|
+
├── core/ # Core functionality
|
|
11
|
+
│ ├── __init__.py
|
|
12
|
+
│ ├── computer_agent.py # Main entry point
|
|
13
|
+
│ └── factory.py # Provider factory
|
|
14
|
+
├── base/ # Base implementations
|
|
15
|
+
│ ├── __init__.py
|
|
16
|
+
│ ├── agent.py # Base agent class
|
|
17
|
+
│ ├── core/ # Core components
|
|
18
|
+
│ │ ├── callbacks.py
|
|
19
|
+
│ │ ├── loop.py
|
|
20
|
+
│ │ └── messages.py
|
|
21
|
+
│ └── tools/ # Tool implementations
|
|
22
|
+
├── providers/ # Provider implementations
|
|
23
|
+
│ ├── __init__.py
|
|
24
|
+
│ ├── anthropic/ # Anthropic provider
|
|
25
|
+
│ │ ├── agent.py
|
|
26
|
+
│ │ ├── loop.py
|
|
27
|
+
│ │ └── tool_manager.py
|
|
28
|
+
│ └── omni/ # Omni provider
|
|
29
|
+
│ ├── agent.py
|
|
30
|
+
│ ├── loop.py
|
|
31
|
+
│ └── tool_manager.py
|
|
32
|
+
└── types/ # Type definitions
|
|
33
|
+
├── __init__.py
|
|
34
|
+
├── base.py # Core types
|
|
35
|
+
├── messages.py # Message types
|
|
36
|
+
├── tools.py # Tool types
|
|
37
|
+
└── providers/ # Provider-specific types
|
|
38
|
+
├── anthropic.py
|
|
39
|
+
└── omni.py
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Key Components
|
|
43
|
+
|
|
44
|
+
### Core
|
|
45
|
+
- `computer_agent.py`: Main entry point for creating and using agents
|
|
46
|
+
- `factory.py`: Factory for creating provider-specific implementations
|
|
47
|
+
|
|
48
|
+
### Base
|
|
49
|
+
- `agent.py`: Base agent implementation with shared functionality
|
|
50
|
+
- `core/`: Core components used across providers
|
|
51
|
+
- `tools/`: Shared tool implementations
|
|
52
|
+
|
|
53
|
+
### Providers
|
|
54
|
+
Each provider follows the same structure:
|
|
55
|
+
- `agent.py`: Provider-specific agent implementation
|
|
56
|
+
- `loop.py`: Provider-specific message loop
|
|
57
|
+
- `tool_manager.py`: Tool management for provider
|
|
58
|
+
|
|
59
|
+
### Types
|
|
60
|
+
- `base.py`: Core type definitions
|
|
61
|
+
- `messages.py`: Message-related types
|
|
62
|
+
- `tools.py`: Tool-related types
|
|
63
|
+
- `providers/`: Provider-specific type definitions
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""CUA (Computer Use) Agent for AI-driven computer interaction."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
|
|
5
|
+
from .core.factory import AgentFactory
|
|
6
|
+
from .core.agent import ComputerAgent
|
|
7
|
+
from .types.base import Provider, AgenticLoop
|
|
8
|
+
from .providers.omni.types import APIProvider
|
|
9
|
+
|
|
10
|
+
__all__ = ["AgentFactory", "Provider", "ComputerAgent", "AgenticLoop", "APIProvider"]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Unified ComputerAgent
|
|
2
|
+
|
|
3
|
+
The `ComputerAgent` class provides a unified implementation that consolidates the previously separate agent implementations (AnthropicComputerAgent and OmniComputerAgent) into a single, configurable class.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multiple Loop Types**: Switch between different agentic loop implementations using the `loop_type` parameter (Anthropic or Omni).
|
|
8
|
+
- **Provider Support**: Use different AI providers (OpenAI, Anthropic, etc.) with the appropriate loop.
|
|
9
|
+
- **Trajectory Saving**: Control whether to save screenshots and logs with the `save_trajectory` parameter.
|
|
10
|
+
- **Consistent Interface**: Maintains a consistent interface regardless of the underlying loop implementation.
|
|
11
|
+
|
|
12
|
+
## API Key Requirements
|
|
13
|
+
|
|
14
|
+
To use the ComputerAgent, you'll need API keys for the providers you want to use:
|
|
15
|
+
|
|
16
|
+
- For **OpenAI**: Set the `OPENAI_API_KEY` environment variable or pass it directly as `api_key`.
|
|
17
|
+
- For **Anthropic**: Set the `ANTHROPIC_API_KEY` environment variable or pass it directly as `api_key`.
|
|
18
|
+
- For **Groq**: Set the `GROQ_API_KEY` environment variable or pass it directly as `api_key`.
|
|
19
|
+
|
|
20
|
+
You can set environment variables in several ways:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# In your terminal before running the code
|
|
24
|
+
export OPENAI_API_KEY=your_api_key_here
|
|
25
|
+
|
|
26
|
+
# Or in a .env file
|
|
27
|
+
OPENAI_API_KEY=your_api_key_here
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
Here's how to use the unified ComputerAgent:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from agent.core.agent import ComputerAgent
|
|
36
|
+
from agent.types.base import AgenticLoop
|
|
37
|
+
from agent.providers.omni.types import APIProvider
|
|
38
|
+
from computer import Computer
|
|
39
|
+
|
|
40
|
+
# Create a Computer instance
|
|
41
|
+
computer = Computer()
|
|
42
|
+
|
|
43
|
+
# Create an agent with the OMNI loop and OpenAI provider
|
|
44
|
+
agent = ComputerAgent(
|
|
45
|
+
computer=computer,
|
|
46
|
+
loop_type=AgenticLoop.OMNI,
|
|
47
|
+
provider=APIProvider.OPENAI,
|
|
48
|
+
model="gpt-4o",
|
|
49
|
+
api_key="your_api_key_here", # Can also use OPENAI_API_KEY environment variable
|
|
50
|
+
save_trajectory=True,
|
|
51
|
+
only_n_most_recent_images=5
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Create an agent with the ANTHROPIC loop
|
|
55
|
+
agent = ComputerAgent(
|
|
56
|
+
computer=computer,
|
|
57
|
+
loop_type=AgenticLoop.ANTHROPIC,
|
|
58
|
+
model="claude-3-7-sonnet-20250219",
|
|
59
|
+
api_key="your_api_key_here", # Can also use ANTHROPIC_API_KEY environment variable
|
|
60
|
+
save_trajectory=True,
|
|
61
|
+
only_n_most_recent_images=5
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Use the agent
|
|
65
|
+
async with agent:
|
|
66
|
+
async for result in agent.run("Your task description here"):
|
|
67
|
+
# Process the result
|
|
68
|
+
title = result["metadata"].get("title", "Screen Analysis")
|
|
69
|
+
content = result["content"]
|
|
70
|
+
print(f"\n{title}")
|
|
71
|
+
print(content)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Parameters
|
|
75
|
+
|
|
76
|
+
- `computer`: Computer instance to control
|
|
77
|
+
- `loop_type`: The type of loop to use (AgenticLoop.ANTHROPIC or AgenticLoop.OMNI)
|
|
78
|
+
- `provider`: AI provider to use (required for Omni loop)
|
|
79
|
+
- `api_key`: Optional API key (will use environment variable if not provided)
|
|
80
|
+
- `model`: Optional model name (will use provider default if not specified)
|
|
81
|
+
- `save_trajectory`: Whether to save screenshots and logs
|
|
82
|
+
- `only_n_most_recent_images`: Only keep N most recent images
|
|
83
|
+
- `max_retries`: Maximum number of retry attempts
|
|
84
|
+
|
|
85
|
+
## Directory Structure
|
|
86
|
+
|
|
87
|
+
When `save_trajectory` is enabled, the agent will create the following directory structure:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
experiments/
|
|
91
|
+
├── screenshots/ # Screenshots captured during agent execution
|
|
92
|
+
└── logs/ # API call logs and other logging information
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Extending with New Loop Types
|
|
96
|
+
|
|
97
|
+
To add a new loop type:
|
|
98
|
+
|
|
99
|
+
1. Implement a new loop class
|
|
100
|
+
2. Add a new value to the `AgenticLoop` enum
|
|
101
|
+
3. Update the `_initialize_loop` method in `ComputerAgent` to handle the new loop type
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Core agent components."""
|
|
2
|
+
|
|
3
|
+
from .base_agent import BaseComputerAgent
|
|
4
|
+
from .loop import BaseLoop
|
|
5
|
+
from .messages import (
|
|
6
|
+
create_user_message,
|
|
7
|
+
create_assistant_message,
|
|
8
|
+
create_system_message,
|
|
9
|
+
create_image_message,
|
|
10
|
+
create_screen_message,
|
|
11
|
+
BaseMessageManager,
|
|
12
|
+
ImageRetentionConfig,
|
|
13
|
+
)
|
|
14
|
+
from .callbacks import (
|
|
15
|
+
CallbackManager,
|
|
16
|
+
CallbackHandler,
|
|
17
|
+
BaseCallbackManager,
|
|
18
|
+
ContentCallback,
|
|
19
|
+
ToolCallback,
|
|
20
|
+
APICallback,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"BaseComputerAgent",
|
|
25
|
+
"BaseLoop",
|
|
26
|
+
"CallbackManager",
|
|
27
|
+
"CallbackHandler",
|
|
28
|
+
"BaseMessageManager",
|
|
29
|
+
"ImageRetentionConfig",
|
|
30
|
+
"BaseCallbackManager",
|
|
31
|
+
"ContentCallback",
|
|
32
|
+
"ToolCallback",
|
|
33
|
+
"APICallback",
|
|
34
|
+
]
|