Skip to content

Commit edaade4

Browse files
committed
fix: fix using time.sleep in async code
1 parent 9f3db28 commit edaade4

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

src/askui/agent_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def act(
136136
be used for achieving the `goal`.
137137
on_message (OnMessageCb | None, optional): Callback for new messages. If
138138
it returns `None`, stops and does not add the message.
139-
tools (list[Tool] | ToolCollection | None, optional): The tools for the agent.
140-
Defaults to default tools depending on the selected model.
139+
tools (list[Tool] | ToolCollection | None, optional): The tools for the
140+
agent. Defaults to default tools depending on the selected model.
141141
settings (AgentSettings | None, optional): The settings for the agent.
142142
Defaults to a default settings depending on the selected model.
143143

src/askui/chat/api/runs/runner/runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING, Literal, Sequence
66

7+
import anyio
78
from anyio.abc import ObjectStream
89
from asyncer import asyncify, syncify
910
from fastmcp import Client
@@ -113,7 +114,7 @@ async def _run_human_agent(self, send_stream: ObjectStream[Events]) -> None:
113114
)
114115
self._agent_os.start_listening()
115116
screenshot = self._agent_os.screenshot()
116-
time.sleep(0.1)
117+
await anyio.sleep(0.1)
117118
recorded_events: list[InputEvent] = []
118119
while True:
119120
updated_run = self._retrieve_run()
@@ -159,7 +160,7 @@ async def _run_human_agent(self, send_stream: ObjectStream[Events]) -> None:
159160
)
160161
)
161162
screenshot = self._agent_os.screenshot()
162-
time.sleep(0.1)
163+
await anyio.sleep(0.1)
163164
self._agent_os.stop_listening()
164165
if len(recorded_events) == 0:
165166
text = "Nevermind, I didn't do anything."

src/askui/chat/api/runs/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def event_generator() -> AsyncGenerator[Events, None]:
6464
# Start the runner in a background task
6565
async def run_runner() -> None:
6666
try:
67-
await runner.run(send_stream)
67+
await runner.run(send_stream) # type: ignore[arg-type]
6868
finally:
6969
await send_stream.aclose()
7070

src/askui/models/ui_tars_ep/ui_tars_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
from askui.models.shared.agent_message_param import MessageParam
2222
from askui.models.shared.agent_on_message_cb import OnMessageCb
2323
from askui.models.shared.settings import ActSettings
24-
from askui.models.shared.tools import ToolCollection
24+
from askui.models.shared.tools import Tool, ToolCollection
2525
from askui.models.types.response_schemas import ResponseSchema
2626
from askui.reporting import Reporter
27+
from askui.tools.computer import Computer20241022Tool
2728
from askui.utils.image_utils import ImageSource, image_to_base64
2829
from askui.utils.pdf_utils import PdfSource
2930
from askui.utils.source_utils import Source
@@ -228,11 +229,11 @@ def act(
228229
raise ValueError(error_msg) # noqa: TRY004
229230

230231
# Find the computer tool
231-
computer_tool = None
232+
computer_tool: Computer20241022Tool | None = None
232233
if tools:
233234
for tool in tools:
234235
if tool.name == "computer":
235-
computer_tool = tool
236+
computer_tool: Computer20241022Tool = tool
236237
break
237238

238239
if computer_tool is None:
@@ -260,7 +261,7 @@ def act(
260261
self.execute_act(self.act_history, computer_tool)
261262

262263
def add_screenshot_to_history(
263-
self, message_history: list[dict[str, Any]], computer_tool: Tool
264+
self, message_history: list[dict[str, Any]], computer_tool: Computer20241022Tool
264265
) -> None:
265266
screenshot = computer_tool(action="screenshot")
266267
message_history.append(

src/askui/tools/mcp/servers/sse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Any
2+
13
from fastmcp import FastMCP
24

3-
mcp = FastMCP("Test StdIO MCP App", port=8001)
5+
mcp: FastMCP[Any] = FastMCP("Test StdIO MCP App", port=8001)
46

57

68
@mcp.tool

src/askui/tools/mcp/servers/stdio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Any
2+
13
from fastmcp import FastMCP
24

3-
mcp = FastMCP("Test StdIO MCP App")
5+
mcp: FastMCP[Any] = FastMCP("Test StdIO MCP App")
46

57

68
@mcp.tool

tests/integration/test_custom_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from askui.models.shared.agent_message_param import MessageParam
2323
from askui.models.shared.agent_on_message_cb import OnMessageCb
2424
from askui.models.shared.settings import ActSettings
25-
from askui.models.shared.tools import Tool
25+
from askui.models.shared.tools import ToolCollection
2626
from askui.tools.toolbox import AgentToolbox
2727
from askui.utils.image_utils import ImageSource
2828
from askui.utils.source_utils import Source
@@ -41,7 +41,7 @@ def act(
4141
messages: list[MessageParam],
4242
model_choice: str,
4343
on_message: OnMessageCb | None = None,
44-
tools: list[Tool] | None = None,
44+
tools: ToolCollection | None = None,
4545
settings: ActSettings | None = None,
4646
) -> None:
4747
self.goals.append([message.model_dump(mode="json") for message in messages])
@@ -230,7 +230,7 @@ def act(
230230
messages: list[MessageParam],
231231
model_choice: str,
232232
on_message: OnMessageCb | None = None,
233-
tools: list[Tool] | None = None,
233+
tools: ToolCollection | None = None,
234234
settings: ActSettings | None = None,
235235
) -> None:
236236
pass

0 commit comments

Comments
 (0)