Skip to content

Commit 3d88daf

Browse files
committed
format
1 parent b8e5c3a commit 3d88daf

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

src/agentlab/actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class FunctionSpec(BaseModel):
2727
parameters: dict
2828

2929

30-
3130
class ToolCall(BaseModel):
3231
id: str = Field(default_factory=lambda: uuid4().hex)
3332
name: str
@@ -106,7 +105,9 @@ def parse_action(cls, llm_output: str) -> ToolCall:
106105
if "<action>" in llm_output:
107106
content_dict, valid, retry_message = parse_html_tags_raise(llm_output, keys=["action"])
108107
if not valid or "action" not in content_dict:
109-
raise ValueError(f"Invalid action: llm_output: {llm_output}, retry_message: {retry_message}")
108+
raise ValueError(
109+
f"Invalid action: llm_output: {llm_output}, retry_message: {retry_message}"
110+
)
110111
action_str = content_dict["action"]
111112
else:
112113
action_str = llm_output

src/agentlab/agents/react_toolcall_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def get_action(self, obs: dict) -> tuple[ToolCall, dict]:
138138
action = self.action_from_message(message)
139139
return action, {"think": thoughts}
140140

141-
def thoughts_from_message(self, message) -> str:
141+
def thoughts_from_message(self, message: Message) -> str:
142142
thoughts = []
143143
if reasoning := message.get("reasoning_content"):
144144
logger.info(colored(f"LLM reasoning:\n{reasoning}", "yellow"))
@@ -153,7 +153,7 @@ def thoughts_from_message(self, message) -> str:
153153
thoughts.append(message.content)
154154
return "\n\n".join(thoughts)
155155

156-
def action_from_message(self, message) -> ToolCall:
156+
def action_from_message(self, message: Message) -> ToolCall:
157157
if message.tool_calls:
158158
if len(message.tool_calls) > 1:
159159
logger.warning("Multiple tool calls found in LLM response, using the first one.")
@@ -162,7 +162,7 @@ def action_from_message(self, message) -> ToolCall:
162162
args = json.loads(tool_call.function.arguments)
163163
action = ToolCall(id=tool_call.id, name=name, arguments=args)
164164
self.last_tool_call_id = action.id
165-
logger.info(f"Parsed tool call action: {action}")
165+
logger.info(colored(f"Parsed tool call: {action}", "magenta"))
166166
else:
167167
raise ValueError(f"No tool call found in LLM response: {message}")
168168
return action

src/agentlab/backends/browser/env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def final_step():
1717
"""
1818
pass
1919

20+
2021
class BrowserEnv(AbstractEnv):
2122
def __init__(
2223
self, task_name: str, task: AbstractWebTask, backend: BrowserBackend, seed: int = 0

src/agentlab/backends/browser/mcp_playwright.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def step(self, action: ToolCall) -> dict:
4444
}
4545

4646
def page_html(self) -> str:
47-
contents = self.call_tool("browser_evaluate", {"function": "document.documentElement.outerHTML"})
47+
contents = self.call_tool(
48+
"browser_evaluate", {"function": "document.documentElement.outerHTML"}
49+
)
4850
raw_response = "\n".join([c.text for c in contents if c.type == "text"])
4951
try:
5052
_, half_response = raw_response.split("### Result", maxsplit=1)

src/agentlab/experiments/loop.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ def run(self):
412412
logger.debug(f"Starting step {step_info.step}.")
413413
step_info.profiling.agent_start = time.time()
414414
action, step_info.agent_info = agent.get_action(step_info.obs.copy())
415-
step_info.action = action.model_dump_json(indent=2) if isinstance(action, BaseModel) else str(action)
415+
step_info.action = (
416+
action.model_dump_json(indent=2)
417+
if isinstance(action, BaseModel)
418+
else str(action)
419+
)
416420
step_info.profiling.agent_stop = time.time()
417421
if step_info.agent_info.get("think", None):
418422
logger.info(f"Agent thought: {step_info.agent_info['think']}")

0 commit comments

Comments
 (0)