-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.py
More file actions
65 lines (49 loc) · 1.87 KB
/
Copy pathcustom.py
File metadata and controls
65 lines (49 loc) · 1.87 KB
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
56
57
58
59
60
61
62
63
64
65
# Custom agent: minimal scaffolding to build your own agent on.
# It doesn't do anything right now! If you use this, you're starting from scratch!
import dataclasses
from typing import Dict, Tuple, Optional
from agisdk import REAL
class MyCustomAgent(REAL.Agent):
def __init__(self) -> None:
super().__init__()
self.steps = 0
def get_agent_action(self, obs) -> Tuple[Optional[str], Optional[str]]:
"""
Core agent logic - analyze observation and decide on action.
Returns:
Tuple of (action, final_message)
- If action is None, episode ends with final_message
- If action is not None, the agent takes the action and continues
"""
self.steps += 1
# Example of simple decision making based on URL
current_url = obs.get("url", "")
def get_action(self, obs: dict) -> Tuple[str, Dict]:
"""
Convert agent's high-level action to browsergym action.
This method is required by the browsergym interface.
"""
agent_action, final_message = self.get_agent_action(obs)
if final_message:
# End the episode with a message
return f"send_msg_to_user(\"{final_message}\")", {}
else:
# Continue with the specified action
return agent_action, {}
@dataclasses.dataclass
class MyCustomAgentArgs(REAL.AbstractAgentArgs):
agent_name: str = "MyCustomAgent"
def make_agent(self):
return MyCustomAgent()
# Example creating and using a custom agent
def run_custom_agent():
# Create harness with custom agent
harness = REAL.harness(
agentargs=MyCustomAgentArgs(),
headless=False,
)
# Run the task
results = harness.run()
return results
if __name__ == "__main__":
results = run_custom_agent()