Skip to content

Commit 2ec4f7f

Browse files
committed
fix: ruff format compliance
1 parent 50748fe commit 2ec4f7f

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/hawk/context_window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from .types import Message
32

43

@@ -28,7 +27,7 @@ def compact_messages(self, messages: list[Message], system_prompt: str = "") ->
2827
# Traverse backwards (keep newest context)
2928
for msg in reversed(messages):
3029
# Extract content from the message model
31-
raw = msg.content if isinstance(msg, Message) else str(msg.get('content', ''))
30+
raw = msg.content if isinstance(msg, Message) else str(msg.get("content", ""))
3231
content = raw or ""
3332
msg_tokens = self.estimate_tokens(content)
3433

src/hawk/graph_dsl.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class NodeType(str, Enum):
1414
"""Types of nodes in orchestration graphs."""
15+
1516
AGENT = "agent"
1617
TOOL = "tool"
1718
FUNCTION = "function"
@@ -23,6 +24,7 @@ class NodeType(str, Enum):
2324
@dataclass
2425
class GraphNode:
2526
"""Represents a node in the graph."""
27+
2628
id: str
2729
type: NodeType
2830
name: str
@@ -33,13 +35,14 @@ def to_dict(self) -> dict[str, Any]:
3335
"id": self.id,
3436
"type": self.type.value,
3537
"name": self.name,
36-
"properties": self.properties
38+
"properties": self.properties,
3739
}
3840

3941

4042
@dataclass
4143
class GraphEdge:
4244
"""Represents an edge in the graph."""
45+
4346
source: str
4447
target: str
4548
condition: Optional[str] = None
@@ -50,7 +53,7 @@ def to_dict(self) -> dict[str, Any]:
5053
"source": self.source,
5154
"target": self.target,
5255
"condition": self.condition,
53-
"weight": self.weight
56+
"weight": self.weight,
5457
}
5558

5659

@@ -77,7 +80,9 @@ def __init__(self) -> None:
7780
self._edges: list[GraphEdge] = []
7881
self._adj: dict[str, list[str]] = {}
7982

80-
def node(self, node_id: str, node_type: NodeType = NodeType.AGENT, name: str = "", **properties: Any) -> "GraphQuery":
83+
def node(
84+
self, node_id: str, node_type: NodeType = NodeType.AGENT, name: str = "", **properties: Any
85+
) -> "GraphQuery":
8186
"""Add a node to the graph."""
8287
if node_id in self._nodes:
8388
return self
@@ -86,7 +91,9 @@ def node(self, node_id: str, node_type: NodeType = NodeType.AGENT, name: str = "
8691
self._adj[node_id] = []
8792
return self
8893

89-
def edge(self, source: str, target: str, condition: Optional[str] = None, weight: float = 1.0) -> "GraphQuery":
94+
def edge(
95+
self, source: str, target: str, condition: Optional[str] = None, weight: float = 1.0
96+
) -> "GraphQuery":
9097
"""Add an edge between two nodes."""
9198
if source not in self._nodes or target not in self._nodes:
9299
raise ValueError(f"Node not found: {source if source not in self._nodes else target}")
@@ -221,7 +228,7 @@ def to_dict(self) -> dict[str, Any]:
221228
"""Export graph as a dictionary."""
222229
return {
223230
"nodes": [n.to_dict() for n in self._nodes.values()],
224-
"edges": [e.to_dict() for e in self._edges]
231+
"edges": [e.to_dict() for e in self._edges],
225232
}
226233

227234
def __len__(self) -> int:

src/hawk/harness.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
logger = logging.getLogger(__name__)
66

7+
78
class TestHarness:
89
"""Harness Engineering: Wraps agent executions for testing and validation."""
910

@@ -22,6 +23,7 @@ def add_mock(self, tool_name: str, return_value: Any) -> "TestHarness":
2223

2324
def wrap_async(self, func: Callable[..., Any]) -> Callable[..., Any]:
2425
"""Wraps an async function with harness validations."""
26+
2527
@functools.wraps(func)
2628
async def wrapper(*args: Any, **kwargs: Any) -> Any:
2729
logger.info(f"[Harness {self.name}] Starting execution")

tests/test_context_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44

55
def test_context_optimizer_compaction():
6-
optimizer = ContextOptimizer(max_tokens=20) # Approx 80 chars
6+
optimizer = ContextOptimizer(max_tokens=20) # Approx 80 chars
77

88
# 3 messages, ~30 chars each
99
messages = [
1010
Message(role="user", content="This is message number one."),
1111
Message(role="user", content="This is message number two."),
12-
Message(role="user", content="This is message number three.")
12+
Message(role="user", content="This is message number three."),
1313
]
1414

1515
# "Sys" = 3 chars = 0 tokens (3//4). Available = 20

tests/test_harness.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async def my_agent():
1515
result = await my_agent()
1616
assert result == 42
1717

18+
1819
@pytest.mark.asyncio
1920
async def test_harness_validator_failure():
2021
harness = TestHarness("test")

tests/test_tools.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ def test_executes_tool_and_loops(self) -> None:
175175
assert second_call_kwargs["tool_results"][0].content == "hi"
176176

177177
def test_unknown_tool_returns_error_result(self) -> None:
178-
call_resp = _chat_response(
179-
tool_calls=[{"id": "tc-1", "name": "missing", "arguments": {}}]
180-
)
178+
call_resp = _chat_response(tool_calls=[{"id": "tc-1", "name": "missing", "arguments": {}}])
181179
final_resp = _chat_response(tool_calls=None)
182180

183181
client = MagicMock()
@@ -193,9 +191,7 @@ def test_max_rounds_exceeded_raises(self) -> None:
193191
"""If the daemon keeps returning tool_calls, the loop must not spin
194192
forever — it raises HawkError after max_rounds (matches TS SDK)."""
195193
tool = Tool(name="spin", description="never stops", fn=lambda: "again")
196-
call_resp = _chat_response(
197-
tool_calls=[{"id": "tc-1", "name": "spin", "arguments": {}}]
198-
)
194+
call_resp = _chat_response(tool_calls=[{"id": "tc-1", "name": "spin", "arguments": {}}])
199195

200196
client = MagicMock()
201197
client.chat.return_value = call_resp
@@ -224,9 +220,7 @@ async def test_async_loops_and_returns_final(self) -> None:
224220
@pytest.mark.asyncio
225221
async def test_async_max_rounds_exceeded_raises(self) -> None:
226222
tool = Tool(name="spin", description="never stops", fn=lambda: "again")
227-
call_resp = _chat_response(
228-
tool_calls=[{"id": "tc-1", "name": "spin", "arguments": {}}]
229-
)
223+
call_resp = _chat_response(tool_calls=[{"id": "tc-1", "name": "spin", "arguments": {}}])
230224

231225
client = MagicMock()
232226
client.chat = AsyncMock(return_value=call_resp)

0 commit comments

Comments
 (0)