cua-agent 0.4.25__py3-none-any.whl → 0.4.27__py3-none-any.whl
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.
- agent/agent.py +9 -1
- agent/callbacks/__init__.py +2 -0
- agent/callbacks/prompt_instructions.py +47 -0
- agent/integrations/hud/__init__.py +12 -3
- {cua_agent-0.4.25.dist-info → cua_agent-0.4.27.dist-info}/METADATA +1 -1
- {cua_agent-0.4.25.dist-info → cua_agent-0.4.27.dist-info}/RECORD +8 -7
- {cua_agent-0.4.25.dist-info → cua_agent-0.4.27.dist-info}/WHEEL +0 -0
- {cua_agent-0.4.25.dist-info → cua_agent-0.4.27.dist-info}/entry_points.txt +0 -0
agent/agent.py
CHANGED
|
@@ -31,7 +31,8 @@ from .callbacks import (
|
|
|
31
31
|
TrajectorySaverCallback,
|
|
32
32
|
BudgetManagerCallback,
|
|
33
33
|
TelemetryCallback,
|
|
34
|
-
OperatorNormalizerCallback
|
|
34
|
+
OperatorNormalizerCallback,
|
|
35
|
+
PromptInstructionsCallback,
|
|
35
36
|
)
|
|
36
37
|
from .computers import (
|
|
37
38
|
AsyncComputerHandler,
|
|
@@ -162,6 +163,7 @@ class ComputerAgent:
|
|
|
162
163
|
custom_loop: Optional[Callable] = None,
|
|
163
164
|
only_n_most_recent_images: Optional[int] = None,
|
|
164
165
|
callbacks: Optional[List[Any]] = None,
|
|
166
|
+
instructions: Optional[str] = None,
|
|
165
167
|
verbosity: Optional[int] = None,
|
|
166
168
|
trajectory_dir: Optional[str | Path | dict] = None,
|
|
167
169
|
max_retries: Optional[int] = 3,
|
|
@@ -180,6 +182,7 @@ class ComputerAgent:
|
|
|
180
182
|
custom_loop: Custom agent loop function to use instead of auto-selection
|
|
181
183
|
only_n_most_recent_images: If set, only keep the N most recent images in message history. Adds ImageRetentionCallback automatically.
|
|
182
184
|
callbacks: List of AsyncCallbackHandler instances for preprocessing/postprocessing
|
|
185
|
+
instructions: Optional system instructions to be passed to the model
|
|
183
186
|
verbosity: Logging level (logging.DEBUG, logging.INFO, etc.). If set, adds LoggingCallback automatically
|
|
184
187
|
trajectory_dir: If set, saves trajectory data (screenshots, responses) to this directory. Adds TrajectorySaverCallback automatically.
|
|
185
188
|
max_retries: Maximum number of retries for failed API calls
|
|
@@ -198,6 +201,7 @@ class ComputerAgent:
|
|
|
198
201
|
self.custom_loop = custom_loop
|
|
199
202
|
self.only_n_most_recent_images = only_n_most_recent_images
|
|
200
203
|
self.callbacks = callbacks or []
|
|
204
|
+
self.instructions = instructions
|
|
201
205
|
self.verbosity = verbosity
|
|
202
206
|
self.trajectory_dir = trajectory_dir
|
|
203
207
|
self.max_retries = max_retries
|
|
@@ -211,6 +215,10 @@ class ComputerAgent:
|
|
|
211
215
|
# Prepend operator normalizer callback
|
|
212
216
|
self.callbacks.insert(0, OperatorNormalizerCallback())
|
|
213
217
|
|
|
218
|
+
# Add prompt instructions callback if provided
|
|
219
|
+
if self.instructions:
|
|
220
|
+
self.callbacks.append(PromptInstructionsCallback(self.instructions))
|
|
221
|
+
|
|
214
222
|
# Add telemetry callback if telemetry_enabled is set
|
|
215
223
|
if self.telemetry_enabled:
|
|
216
224
|
if isinstance(self.telemetry_enabled, bool):
|
agent/callbacks/__init__.py
CHANGED
|
@@ -9,6 +9,7 @@ from .trajectory_saver import TrajectorySaverCallback
|
|
|
9
9
|
from .budget_manager import BudgetManagerCallback
|
|
10
10
|
from .telemetry import TelemetryCallback
|
|
11
11
|
from .operator_validator import OperatorNormalizerCallback
|
|
12
|
+
from .prompt_instructions import PromptInstructionsCallback
|
|
12
13
|
|
|
13
14
|
__all__ = [
|
|
14
15
|
"AsyncCallbackHandler",
|
|
@@ -18,4 +19,5 @@ __all__ = [
|
|
|
18
19
|
"BudgetManagerCallback",
|
|
19
20
|
"TelemetryCallback",
|
|
20
21
|
"OperatorNormalizerCallback",
|
|
22
|
+
"PromptInstructionsCallback",
|
|
21
23
|
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Prompt instructions callback.
|
|
3
|
+
|
|
4
|
+
This callback allows simple prompt engineering by pre-pending a user
|
|
5
|
+
instructions message to the start of the conversation before each LLM call.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
|
|
9
|
+
from agent.callbacks import PromptInstructionsCallback
|
|
10
|
+
agent = ComputerAgent(
|
|
11
|
+
model="openai/computer-use-preview",
|
|
12
|
+
callbacks=[PromptInstructionsCallback("Follow these rules...")]
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import Any, Dict, List, Optional
|
|
18
|
+
|
|
19
|
+
from .base import AsyncCallbackHandler
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PromptInstructionsCallback(AsyncCallbackHandler):
|
|
23
|
+
"""
|
|
24
|
+
Prepend a user instructions message to the message list.
|
|
25
|
+
|
|
26
|
+
This is a minimal, non-invasive way to guide the agent's behavior without
|
|
27
|
+
modifying agent loops or tools. It works with any provider/loop since it
|
|
28
|
+
only alters the messages array before sending to the model.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, instructions: Optional[str]) -> None:
|
|
32
|
+
self.instructions = instructions
|
|
33
|
+
|
|
34
|
+
async def on_llm_start(self, messages: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
35
|
+
# Pre-pend instructions message
|
|
36
|
+
if not self.instructions:
|
|
37
|
+
return messages
|
|
38
|
+
|
|
39
|
+
# Ensure we don't duplicate if already present at the front
|
|
40
|
+
if messages and isinstance(messages[0], dict):
|
|
41
|
+
first = messages[0]
|
|
42
|
+
if first.get("role") == "user" and first.get("content") == self.instructions:
|
|
43
|
+
return messages
|
|
44
|
+
|
|
45
|
+
return [
|
|
46
|
+
{"role": "user", "content": self.instructions},
|
|
47
|
+
] + messages
|
|
@@ -20,6 +20,7 @@ from hud import trace
|
|
|
20
20
|
|
|
21
21
|
from agent.agent import ComputerAgent as BaseComputerAgent
|
|
22
22
|
from .proxy import FakeAsyncOpenAI
|
|
23
|
+
from agent.callbacks import PromptInstructionsCallback
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
# ---------------------------------------------------------------------------
|
|
@@ -47,6 +48,7 @@ class ProxyOperatorAgent(OperatorAgent):
|
|
|
47
48
|
custom_loop: Any | None = None,
|
|
48
49
|
only_n_most_recent_images: int | None = None,
|
|
49
50
|
callbacks: list[Any] | None = None,
|
|
51
|
+
instructions: str | None = None,
|
|
50
52
|
verbosity: int | None = None,
|
|
51
53
|
max_retries: int | None = 3,
|
|
52
54
|
screenshot_delay: float | int = 0.5,
|
|
@@ -68,12 +70,17 @@ class ProxyOperatorAgent(OperatorAgent):
|
|
|
68
70
|
if tools:
|
|
69
71
|
agent_tools.extend(tools)
|
|
70
72
|
|
|
73
|
+
# Build callbacks, injecting prompt instructions if provided
|
|
74
|
+
agent_callbacks = list(callbacks or [])
|
|
75
|
+
if instructions:
|
|
76
|
+
agent_callbacks.append(PromptInstructionsCallback(instructions))
|
|
77
|
+
|
|
71
78
|
computer_agent = BaseComputerAgent(
|
|
72
79
|
model=model,
|
|
73
80
|
tools=agent_tools,
|
|
74
81
|
custom_loop=custom_loop,
|
|
75
82
|
only_n_most_recent_images=only_n_most_recent_images,
|
|
76
|
-
callbacks=
|
|
83
|
+
callbacks=agent_callbacks,
|
|
77
84
|
verbosity=verbosity,
|
|
78
85
|
trajectory_dir=trajectory_dir,
|
|
79
86
|
max_retries=max_retries,
|
|
@@ -96,7 +103,6 @@ class ProxyOperatorAgent(OperatorAgent):
|
|
|
96
103
|
# Single-task runner
|
|
97
104
|
# ---------------------------------------------------------------------------
|
|
98
105
|
|
|
99
|
-
|
|
100
106
|
async def run_single_task(
|
|
101
107
|
dataset: str | Dataset | list[dict[str, Any]],
|
|
102
108
|
*,
|
|
@@ -108,6 +114,7 @@ async def run_single_task(
|
|
|
108
114
|
custom_loop: Any | None = None,
|
|
109
115
|
only_n_most_recent_images: int | None = None,
|
|
110
116
|
callbacks: list[Any] | None = None,
|
|
117
|
+
instructions: str | None = None,
|
|
111
118
|
verbosity: int | None = None,
|
|
112
119
|
trajectory_dir: str | dict | None = None,
|
|
113
120
|
max_retries: int | None = 3,
|
|
@@ -140,6 +147,7 @@ async def run_single_task(
|
|
|
140
147
|
custom_loop=custom_loop,
|
|
141
148
|
only_n_most_recent_images=only_n_most_recent_images,
|
|
142
149
|
callbacks=callbacks,
|
|
150
|
+
instructions=instructions,
|
|
143
151
|
verbosity=verbosity,
|
|
144
152
|
trajectory_dir=trajectory_dir,
|
|
145
153
|
max_retries=max_retries,
|
|
@@ -157,7 +165,6 @@ async def run_single_task(
|
|
|
157
165
|
# Full-dataset runner
|
|
158
166
|
# ---------------------------------------------------------------------------
|
|
159
167
|
|
|
160
|
-
|
|
161
168
|
async def run_full_dataset(
|
|
162
169
|
dataset: str | Dataset | list[dict[str, Any]],
|
|
163
170
|
*,
|
|
@@ -173,6 +180,7 @@ async def run_full_dataset(
|
|
|
173
180
|
custom_loop: Any | None = None,
|
|
174
181
|
only_n_most_recent_images: int | None = 5,
|
|
175
182
|
callbacks: list[Any] | None = None,
|
|
183
|
+
instructions: str | None = None,
|
|
176
184
|
verbosity: int | None = None,
|
|
177
185
|
max_retries: int | None = 3,
|
|
178
186
|
screenshot_delay: float | int = 0.5,
|
|
@@ -207,6 +215,7 @@ async def run_full_dataset(
|
|
|
207
215
|
"custom_loop": custom_loop,
|
|
208
216
|
"only_n_most_recent_images": only_n_most_recent_images,
|
|
209
217
|
"callbacks": callbacks,
|
|
218
|
+
"instructions": instructions,
|
|
210
219
|
"verbosity": verbosity,
|
|
211
220
|
"max_retries": max_retries,
|
|
212
221
|
"screenshot_delay": screenshot_delay,
|
|
@@ -4,14 +4,15 @@ agent/adapters/__init__.py,sha256=Q_OxxwXBcBIetQ_DtHS5bwZWXrvCKPX2grCg8R0UKek,30
|
|
|
4
4
|
agent/adapters/huggingfacelocal_adapter.py,sha256=Uqjtcohhzd33VFh38Ra2y4Uv_lTghMswoqS1t-KKFkw,8480
|
|
5
5
|
agent/adapters/human_adapter.py,sha256=xT4nnfNXb1z-vnGFlLmFEZN7TMcoMBGS40MtR1Zwv4o,13079
|
|
6
6
|
agent/adapters/mlxvlm_adapter.py,sha256=4VhhKDZfLLKL5joL1v4PPFvYw-R8spoDsat3vOAGnpE,14864
|
|
7
|
-
agent/agent.py,sha256=
|
|
8
|
-
agent/callbacks/__init__.py,sha256=
|
|
7
|
+
agent/agent.py,sha256=F_nPTRv-FCo3oKaEFCugun-sj6_iD_iw2RQxcaTMVmM,30192
|
|
8
|
+
agent/callbacks/__init__.py,sha256=VqYHFt_wk1mc3hKudMZk2Qakrh-bn2rVKh_4xebF0tI,725
|
|
9
9
|
agent/callbacks/base.py,sha256=UnnnYlh6XCm6HKZZsAPaT_Eyo9LUYLyjyNwF-QRm6Ns,4691
|
|
10
10
|
agent/callbacks/budget_manager.py,sha256=RyKM-7iXQcDotYvrw3eURzeEHEXvQjID-NobtvQWE7k,1832
|
|
11
11
|
agent/callbacks/image_retention.py,sha256=8MeLo5-Y7cACpsNk2p_bvnZIYKpW6XgyukmdYGX23rE,3588
|
|
12
12
|
agent/callbacks/logging.py,sha256=OOxU97EzrxlnUAtiEnvy9FB7SwCUK90-rdpDFA2Ae4E,10921
|
|
13
13
|
agent/callbacks/operator_validator.py,sha256=T5tp62pkShkcdHu2rgREUGdk8fryL_ziJsItXsfgYUQ,6494
|
|
14
14
|
agent/callbacks/pii_anonymization.py,sha256=NEkUTUjQBi82nqus7kT-1E4RaeQ2hQrY7YCnKndLhP8,3272
|
|
15
|
+
agent/callbacks/prompt_instructions.py,sha256=RUqsJhiNiXqaOM_P2AfyBinWUDdgDku46BExLMUJHn4,1517
|
|
15
16
|
agent/callbacks/telemetry.py,sha256=RbUDhE41mTi8g9hNre0EpltK_NUZkLj8buJLWBzs0Ek,7363
|
|
16
17
|
agent/callbacks/trajectory_saver.py,sha256=rslgg4Ak7JHSNmmJgANRQ5TsUYWGuUJDZ6amureaz_o,15963
|
|
17
18
|
agent/cli.py,sha256=AgaXwywHd3nGQWuqMRj6SbPyFaCPjfo5980Y1ApQOTQ,12413
|
|
@@ -24,7 +25,7 @@ agent/human_tool/__init__.py,sha256=3m5_g-Fo_0yX5vi7eg-A92oTqO0N3aY929Ajp78HKsE,
|
|
|
24
25
|
agent/human_tool/__main__.py,sha256=VsW2BAghlonOuqZbP_xuCsaec9bemA1I_ibnDcED9D4,1068
|
|
25
26
|
agent/human_tool/server.py,sha256=ceuL5kw_RjgAi8fueLU3nTjyzOLE25Shv1oTJnSHsoQ,7964
|
|
26
27
|
agent/human_tool/ui.py,sha256=wu9eZorhxCkyPTlBSZjYaVzutoHMlucAz8UGNpAT4bM,30644
|
|
27
|
-
agent/integrations/hud/__init__.py,sha256=
|
|
28
|
+
agent/integrations/hud/__init__.py,sha256=TuASvsA5im3RTWZF6CBOLhQ5L_OpOQ8tmcplhjwBuXE,8835
|
|
28
29
|
agent/integrations/hud/proxy.py,sha256=yA7C2jeXnrpI5HS0VgCvn0BflVbAORZynIfyE27rvBg,7782
|
|
29
30
|
agent/loops/__init__.py,sha256=Ef8aj07l3osibwDk-DTo80PrpL4_GdKRTP1ikl_b-BQ,328
|
|
30
31
|
agent/loops/anthropic.py,sha256=q7lr1PjI6VPtlozoweluY2c3hCGqa_2s-whzxa37iKE,70250
|
|
@@ -45,7 +46,7 @@ agent/ui/__main__.py,sha256=vudWXYvGM0aNT5aZ94HPtGW8YXOZ4cLXepHyhUM_k1g,73
|
|
|
45
46
|
agent/ui/gradio/__init__.py,sha256=yv4Mrfo-Sj2U5sVn_UJHAuwYCezo-5O4ItR2C9jzNko,145
|
|
46
47
|
agent/ui/gradio/app.py,sha256=Ol97YEbwREZZQ9_PMjVHlfOcu9BGsawxgAGAm79hT80,9117
|
|
47
48
|
agent/ui/gradio/ui_components.py,sha256=dJUvKDmc1oSejtoR_gU_oWWYwxaOOQyPloSYRGMrUCQ,36068
|
|
48
|
-
cua_agent-0.4.
|
|
49
|
-
cua_agent-0.4.
|
|
50
|
-
cua_agent-0.4.
|
|
51
|
-
cua_agent-0.4.
|
|
49
|
+
cua_agent-0.4.27.dist-info/METADATA,sha256=L8bBLfo4X9vIz1q4wRc2ikHAZgsZ9obQM05WXSmUEcE,5624
|
|
50
|
+
cua_agent-0.4.27.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
51
|
+
cua_agent-0.4.27.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
52
|
+
cua_agent-0.4.27.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|