Skip to content

Commit 1af02b9

Browse files
committed
fix:: lint-errors
1 parent 57fbc6b commit 1af02b9

3 files changed

Lines changed: 57 additions & 20 deletions

File tree

src/gaia/agents/base/agent.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,12 +1004,14 @@ def _parse_llm_response(self, response: str) -> Dict[str, Any]:
10041004
f"str or dict, got {type(arguments_raw).__name__}"
10051005
)
10061006

1007-
parsed_calls.append({
1008-
"thought": "",
1009-
"goal": "",
1010-
"tool": name,
1011-
"tool_args": tool_args,
1012-
})
1007+
parsed_calls.append(
1008+
{
1009+
"thought": "",
1010+
"goal": "",
1011+
"tool": name,
1012+
"tool_args": tool_args,
1013+
}
1014+
)
10131015
logger.debug(
10141016
"[PARSE] Native tool_calls: returning %d parsed calls",
10151017
len(parsed_calls),
@@ -2573,7 +2575,7 @@ def process_query(
25732575
"This agent prefers either a single tool call per response, "
25742576
"or a structured JSON 'plan' containing an ordered array of steps. "
25752577
"Please either: (A) output a single tool call JSON object, "
2576-
"or (B) output a JSON plan in the format: {\"plan\": [{\"tool\": \"name\", \"tool_args\": {...}}]}. "
2578+
'or (B) output a JSON plan in the format: {"plan": [{"tool": "name", "tool_args": {...}}]}. '
25772579
"If you don't need to call a tool, answer in plain text."
25782580
),
25792581
}
@@ -2601,7 +2603,9 @@ def process_query(
26012603
# sequentially in this same LLM turn (one LLM turn -> N tool turns).
26022604
if isinstance(parsed, list):
26032605
# Record assistant turn containing multiple tool_calls
2604-
conversation.append({"role": "assistant", "content": {"tool_calls": parsed}})
2606+
conversation.append(
2607+
{"role": "assistant", "content": {"tool_calls": parsed}}
2608+
)
26052609
# Preserve raw assistant response for history
26062610
messages.append({"role": "assistant", "content": response})
26072611

@@ -2611,7 +2615,9 @@ def process_query(
26112615

26122616
tool_name = call["tool"]
26132617
tool_args = call["tool_args"]
2614-
logger.debug(f"Sequential native tool call: {tool_name} {tool_args}")
2618+
logger.debug(
2619+
f"Sequential native tool call: {tool_name} {tool_args}"
2620+
)
26152621

26162622
# Display the tool call in real-time
26172623
self.console.print_tool_usage(tool_name)
@@ -2658,11 +2664,19 @@ def process_query(
26582664
self.console.pretty_print_json(tool_result, "Result")
26592665
self.console.print_tool_complete()
26602666

2661-
previous_outputs.append({"tool": tool_name, "args": tool_args, "result": truncated_result})
2667+
previous_outputs.append(
2668+
{
2669+
"tool": tool_name,
2670+
"args": tool_args,
2671+
"result": truncated_result,
2672+
}
2673+
)
26622674
step_results.append(tool_result)
26632675

26642676
# Share tool output with subsequent LLM calls
2665-
messages.append(self._create_tool_message(tool_name, truncated_result))
2677+
messages.append(
2678+
self._create_tool_message(tool_name, truncated_result)
2679+
)
26662680

26672681
# Error handling
26682682
is_error = isinstance(tool_result, dict) and (
@@ -2681,7 +2695,9 @@ def process_query(
26812695
or tool_result.get("suggested_fix")
26822696
or f"Command failed with return code {tool_result.get('return_code')}"
26832697
)
2684-
logger.warning(f"Tool execution error in sequential calls (count: {error_count}): {last_error}")
2698+
logger.warning(
2699+
f"Tool execution error in sequential calls (count: {error_count}): {last_error}"
2700+
)
26852701
if not tool_result.get("error_displayed"):
26862702
self.console.print_error(last_error)
26872703
self.execution_state = self.STATE_ERROR_RECOVERY

tests/unit/test_agent_parallel_tool_calls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import pytest
32

43
from gaia.agents.base.agent import Agent
54
from gaia.agents.base.tools import _TOOL_REGISTRY
@@ -53,6 +52,8 @@ def _register_tools(self):
5352
result = agent.process_query("execute both tools", max_steps=6)
5453

5554
# Verify both tool results were appended to conversation
56-
tool_names = [m.get("name") for m in result["conversation"] if m.get("role") == "tool"]
55+
tool_names = [
56+
m.get("name") for m in result["conversation"] if m.get("role") == "tool"
57+
]
5758
assert "tool_one" in tool_names
5859
assert "tool_two" in tool_names

tests/unit/test_agent_parallel_tool_calls_extra.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import pytest
32

43
from gaia.agents.base.agent import Agent
54
from gaia.agents.base.tools import _TOOL_REGISTRY
@@ -43,7 +42,11 @@ def t_ok2(z=""):
4342
# make send_messages return envelope
4443
responses = [type("R", (), {"text": json.dumps(envelope), "stats": {}})()]
4544

46-
monkeypatch.setattr(agent.chat, "send_messages", lambda messages, system_prompt, tools: responses.pop(0))
45+
monkeypatch.setattr(
46+
agent.chat,
47+
"send_messages",
48+
lambda messages, system_prompt, tools: responses.pop(0),
49+
)
4750

4851
result = agent.process_query("run three tools", max_steps=10)
4952

@@ -55,7 +58,10 @@ def t_ok2(z=""):
5558
# Find the errtool result and ensure it's an error
5659
err_entry = next((t for t in tool_entries if t.get("name") == "errtool"), None)
5760
assert err_entry is not None
58-
assert isinstance(err_entry.get("content"), dict) and err_entry["content"].get("status") == "error"
61+
assert (
62+
isinstance(err_entry.get("content"), dict)
63+
and err_entry["content"].get("status") == "error"
64+
)
5965

6066

6167
def test_plan_then_native_tool_calls(monkeypatch):
@@ -100,13 +106,27 @@ def test_notimplementederror_recovery_message(monkeypatch):
100106
agent = _make_agent(monkeypatch)
101107

102108
# Make the parser raise NotImplementedError
103-
monkeypatch.setattr(agent, "_parse_llm_response", lambda r: (_ for _ in ()).throw(NotImplementedError("multiple")))
109+
monkeypatch.setattr(
110+
agent,
111+
"_parse_llm_response",
112+
lambda r: (_ for _ in ()).throw(NotImplementedError("multiple")),
113+
)
104114

105115
# Make send_messages return something (will be ignored by parser)
106-
monkeypatch.setattr(agent.chat, "send_messages", lambda messages, system_prompt, tools: type("R", (), {"text": "{\"bad\":1}", "stats": {}})())
116+
monkeypatch.setattr(
117+
agent.chat,
118+
"send_messages",
119+
lambda messages, system_prompt, tools: type(
120+
"R", (), {"text": '{"bad":1}', "stats": {}}
121+
)(),
122+
)
107123

108124
result = agent.process_query("trigger parse error", max_steps=3)
109125

110126
# Last user message in conversation should instruct about multiple tool calls
111127
user_msgs = [m for m in result["conversation"] if m.get("role") == "user"]
112-
assert any("MULTIPLE tool calls" in str(m.get("content")) or "single tool call" in str(m.get("content")) for m in user_msgs)
128+
assert any(
129+
"MULTIPLE tool calls" in str(m.get("content"))
130+
or "single tool call" in str(m.get("content"))
131+
for m in user_msgs
132+
)

0 commit comments

Comments
 (0)