File size: 1,991 Bytes
f0f6e5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from functools import cached_property
from typing import Literal

from pydantic import Field

from proxy_lite.history import MessageHistory, MessageLabel, SystemMessage, Text
from proxy_lite.tools import Tool

from .agent_base import Agents, BaseAgent, BaseAgentConfig

MODEL_SYSTEM_PROMPT = """You are Proxy-Lite, an AI assistant that can perform actions on a computer screen.
You were developed by Convergence AI.
The user will instuct you to perform a task.
You will be shown a screen as well as relevant interactable elements highlighted by mark_ids and you will be given a set of tools to use to perform the task.
You should make observations about the screen, putting them in <observation></observation> tags.
You should then reason about what needs to be done to complete the task, putting your thoughts in <thinking></thinking> tags.
You should then use the tools to perform the task, putting the tool calls in <tool_call></tool_call> tags.
"""  # noqa: E501

MAX_MESSAGES_FOR_CONTEXT_WINDOW = {
    MessageLabel.SCREENSHOT: 1,
}


@Agents.register_agent_config("proxy_lite")
class ProxyLiteAgentConfig(BaseAgentConfig):
    name: Literal["proxy_lite"] = "proxy_lite"
    history_messages_limit: dict[MessageLabel, int] = Field(
        default_factory=lambda: MAX_MESSAGES_FOR_CONTEXT_WINDOW,
    )


@Agents.register_agent("proxy_lite")
class ProxyLiteAgent(BaseAgent):
    config: ProxyLiteAgentConfig
    message_label: MessageLabel = MessageLabel.AGENT_MODEL_RESPONSE

    def __init__(self, **data):
        super().__init__(**data)

    @property
    def system_prompt(self) -> str:
        return MODEL_SYSTEM_PROMPT

    @cached_property
    def tools(self) -> list[Tool]:
        return self.env_tools

    async def get_history_view(self) -> MessageHistory:
        return MessageHistory(
            messages=[SystemMessage(content=[Text(text=self.system_prompt)])],
        ) + self.history.history_view(
            limits=self.config.history_messages_limit,
        )