Skip to content

Commit 1321d5b

Browse files
committed
chore: clean library import
1 parent e4005e4 commit 1321d5b

File tree

21 files changed

+245
-124
lines changed

21 files changed

+245
-124
lines changed

AgentCrew/modules/a2a/common/client/client.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1+
from __future__ import annotations
2+
13
import json
24

35
from collections.abc import AsyncGenerator
4-
from typing import Any, Optional, Dict
6+
from typing import TYPE_CHECKING
57
from uuid import uuid4
68

79
import httpx
810

9-
from httpx._types import TimeoutTypes
1011
from httpx_sse import aconnect_sse
1112

1213
from a2a.types import (
1314
A2ARequest,
14-
AgentCard,
15-
CancelTaskRequest,
1615
CancelTaskResponse,
17-
GetTaskPushNotificationConfigRequest,
1816
GetTaskPushNotificationConfigResponse,
19-
GetTaskRequest,
2017
GetTaskResponse,
21-
TaskQueryParams,
22-
SendMessageRequest,
2318
SendMessageResponse,
24-
SendStreamingMessageRequest,
2519
TaskPushNotificationConfig,
2620
SendStreamingMessageResponse,
27-
SetTaskPushNotificationConfigRequest,
2821
SetTaskPushNotificationConfigResponse,
29-
TaskIdParams,
30-
MessageSendParams,
3122
)
3223

24+
if TYPE_CHECKING:
25+
from typing import Any, Dict, Optional
26+
from httpx._types import TimeoutTypes
27+
from a2a.types import (
28+
AgentCard,
29+
CancelTaskRequest,
30+
GetTaskPushNotificationConfigRequest,
31+
GetTaskRequest,
32+
MessageSendParams,
33+
SendMessageRequest,
34+
SendStreamingMessageRequest,
35+
SetTaskPushNotificationConfigRequest,
36+
TaskIdParams,
37+
TaskQueryParams,
38+
)
39+
3340

3441
class A2AClient:
3542
def __init__(

AgentCrew/modules/a2a/common/server/task_manager.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
from __future__ import annotations
2+
13
import asyncio
24

35
from abc import ABC, abstractmethod
46
from collections.abc import AsyncIterable
7+
from typing import TYPE_CHECKING
58

69
from .utils import new_not_implemented_error
710
from a2a.types import (
8-
Artifact,
9-
CancelTaskRequest,
1011
CancelTaskResponse,
11-
GetTaskPushNotificationConfigRequest,
1212
GetTaskPushNotificationConfigResponse,
13-
GetTaskRequest,
1413
GetTaskResponse,
1514
SetTaskPushNotificationConfigSuccessResponse,
1615
GetTaskPushNotificationConfigSuccessResponse,
@@ -20,21 +19,13 @@
2019
GetTaskSuccessResponse,
2120
JSONRPCErrorResponse,
2221
JSONRPCResponse,
23-
PushNotificationConfig,
24-
SendMessageRequest,
2522
SendMessageResponse,
26-
SendStreamingMessageRequest,
2723
SendStreamingMessageResponse,
28-
SetTaskPushNotificationConfigRequest,
2924
SetTaskPushNotificationConfigResponse,
3025
Task,
31-
TaskIdParams,
3226
TaskNotCancelableError,
3327
TaskNotFoundError,
3428
TaskPushNotificationConfig,
35-
TaskQueryParams,
36-
TaskResubscriptionRequest,
37-
MessageSendParams,
3829
TaskState,
3930
TaskStatus,
4031
TaskStatusUpdateEvent,
@@ -43,6 +34,22 @@
4334

4435
from loguru import logger
4536

37+
if TYPE_CHECKING:
38+
from a2a.types import (
39+
Artifact,
40+
CancelTaskRequest,
41+
GetTaskPushNotificationConfigRequest,
42+
GetTaskRequest,
43+
MessageSendParams,
44+
PushNotificationConfig,
45+
SendMessageRequest,
46+
SendStreamingMessageRequest,
47+
SetTaskPushNotificationConfigRequest,
48+
TaskIdParams,
49+
TaskQueryParams,
50+
TaskResubscriptionRequest,
51+
)
52+
4653

4754
class TaskManager(ABC):
4855
@abstractmethod

AgentCrew/modules/a2a/registry.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
"""
2-
Registry for managing A2A agents and their capabilities.
3-
"""
1+
from __future__ import annotations
42

5-
from typing import Dict, List, Optional, Any
3+
from typing import TYPE_CHECKING
64
from pydantic import BaseModel
7-
from AgentCrew.modules.agents import AgentManager, LocalAgent
8-
from a2a.types import AgentCard
95
from .agent_cards import create_agent_card
6+
from AgentCrew.modules.agents import LocalAgent
7+
8+
9+
if TYPE_CHECKING:
10+
from typing import Any, Dict, List, Optional
11+
from AgentCrew.modules.agents import AgentManager
12+
from a2a.types import AgentCard
1013

1114

1215
class AgentInfo(BaseModel):

AgentCrew/modules/a2a/task_manager.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
1-
"""
2-
Task management for A2A protocol implementation.
3-
"""
1+
from __future__ import annotations
42

53
import asyncio
64
from datetime import datetime
7-
from typing import Dict, AsyncIterable, Optional, Any, Union
8-
from AgentCrew.modules.agents import AgentManager, LocalAgent
5+
from typing import TYPE_CHECKING
96
from AgentCrew.modules.agents.base import MessageType
107
from loguru import logger
118
import tempfile
129
import os
1310

1411
from a2a.types import (
1512
CancelTaskResponse,
13+
JSONRPCError,
1614
GetTaskResponse,
1715
GetTaskSuccessResponse,
18-
JSONRPCError,
1916
JSONRPCErrorResponse,
2017
SendMessageResponse,
21-
SendStreamingMessageRequest,
2218
SendStreamingMessageResponse,
2319
SendStreamingMessageSuccessResponse,
2420
CancelTaskSuccessResponse,
25-
SetTaskPushNotificationConfigRequest,
2621
SetTaskPushNotificationConfigResponse,
27-
GetTaskPushNotificationConfigRequest,
2822
GetTaskPushNotificationConfigResponse,
2923
SendMessageSuccessResponse,
30-
TaskResubscriptionRequest,
3124
Task,
3225
TaskStatus,
3326
TaskState,
34-
SendMessageRequest,
35-
GetTaskRequest,
36-
CancelTaskRequest,
37-
JSONRPCResponse,
3827
TaskStatusUpdateEvent,
3928
TaskArtifactUpdateEvent,
4029
TaskNotFoundError,
4130
TaskNotCancelableError,
4231
)
32+
33+
from AgentCrew.modules.agents import LocalAgent
4334
from .adapters import (
4435
convert_a2a_message_to_agent,
4536
convert_agent_response_to_a2a_artifact,
4637
convert_agent_message_to_a2a,
4738
)
4839
from .common.server.task_manager import TaskManager
4940

41+
if TYPE_CHECKING:
42+
from typing import Any, AsyncIterable, Dict, Optional, Union
43+
from AgentCrew.modules.agents import AgentManager
44+
from a2a.types import (
45+
CancelTaskRequest,
46+
GetTaskPushNotificationConfigRequest,
47+
GetTaskRequest,
48+
SendMessageRequest,
49+
SendStreamingMessageRequest,
50+
SetTaskPushNotificationConfigRequest,
51+
TaskResubscriptionRequest,
52+
JSONRPCResponse,
53+
)
54+
5055

5156
class AgentTaskManager(TaskManager):
5257
"""Manages tasks for a specific agent"""
@@ -126,8 +131,6 @@ async def on_send_message(
126131
f.write(part["file_data"])
127132
file_part = self.file_handler.process_file(temp_file)
128133
if not file_part:
129-
from AgentCrew.modules.agents.base import MessageType
130-
131134
file_part = self.agent.format_message(
132135
MessageType.FileContent, {"file_uri": temp_file}
133136
)

AgentCrew/modules/agents/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
2-
from typing import AsyncGenerator, Tuple, Dict, List, Optional, Any, Callable, Union
4+
from typing import TYPE_CHECKING
35
from enum import Enum
46

7+
if TYPE_CHECKING:
8+
from typing import AsyncGenerator, Tuple, Dict, List, Optional, Any, Callable, Union
9+
510

611
class MessageType(Enum):
712
Assistant = 0

AgentCrew/modules/agents/local_agent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24
import os
35
import time
46
import copy
5-
from typing import Dict, Any, List, Optional, Callable, Literal, Union
7+
from typing import List, TYPE_CHECKING
68
from AgentCrew.modules.llm import BaseLLMService
79

810
from .base import BaseAgent, MessageType
911
from loguru import logger
1012

13+
if TYPE_CHECKING:
14+
from typing import Dict, Any, Optional, Callable, Literal, Union
15+
1116
SHRINK_CONTEXT_THRESHOLD = 90_000
1217
SHRINK_LENGTH_THRESHOLD = 15
1318

AgentCrew/modules/agents/remote_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from typing import Callable, Dict, Any, List, Optional, Tuple, Union
1+
from __future__ import annotations
2+
3+
from typing import Dict, TYPE_CHECKING
24
from uuid import uuid4
35

46
from pydantic import ValidationError
57
from AgentCrew.modules.a2a.adapters import (
68
convert_agent_message_to_a2a,
79
)
810

9-
# from AgentCrew.modules.llm.message import MessageTransformer
1011
from .base import BaseAgent, MessageType
1112
from AgentCrew.modules.a2a.common.client import A2ACardResolver, A2AClient
1213
from a2a.types import (
@@ -17,6 +18,9 @@
1718
TextPart,
1819
)
1920

21+
if TYPE_CHECKING:
22+
from typing import Callable, Any, List, Optional, Tuple, Union
23+
2024

2125
class RemoteAgent(BaseAgent):
2226
def __init__(

AgentCrew/modules/browser_automation/tool.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
"""
2-
Browser automation tool definitions and handlers.
3-
4-
Provides eight tools for browser automation:
5-
- browser_navigate: Navigate to URLs
6-
- browser_click: Click elements using UUID selectors
7-
- browser_scroll: Scroll page content
8-
- browser_get_content: Extract page content and interactive elements as markdown
9-
- browser_input: Input data into form fields using UUID selectors
10-
- browser_get_elements_by_text: Find elements by text content
11-
- browser_capture_screenshot: Capture page screenshots
12-
- browser_send_key: send keyboard events (arrow keys, function keys, etc.)
13-
"""
14-
15-
from typing import Dict, Any, Callable, Union, List
16-
from .service import BrowserAutomationService
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
174
import difflib
185
import time
196

7+
if TYPE_CHECKING:
8+
from .service import BrowserAutomationService
9+
from typing import Dict, Any, Callable, Union, List
10+
2011

2112
def get_browser_navigate_tool_definition(provider="claude") -> Dict[str, Any]:
2213
"""Get tool definition for browser navigation."""

AgentCrew/modules/console/display_handlers.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
RICH_STYLE_YELLOW,
1717
RICH_STYLE_BLUE,
1818
RICH_STYLE_RED,
19+
RICH_STYLE_GREEN,
1920
RICH_STYLE_GRAY,
2021
RICH_STYLE_YELLOW_BOLD,
2122
RICH_STYLE_GREEN_BOLD,
22-
RICH_STYLE_BLUE_BOLD,
2323
RICH_STYLE_FILE_ACCENT_BOLD,
2424
RICH_STYLE_WHITE,
2525
CODE_THEME,
@@ -64,6 +64,32 @@ def display_message(self, message: Text):
6464
"""Display a generic message."""
6565
self.console.print(message)
6666

67+
def display_user_message(self, message: str):
68+
header = Text(
69+
"👤 YOU:",
70+
style=RICH_STYLE_GREEN_BOLD,
71+
)
72+
user_panel = Panel(
73+
Text(message),
74+
title=header,
75+
title_align="left",
76+
border_style=RICH_STYLE_BLUE,
77+
)
78+
self.console.print(user_panel)
79+
80+
def display_assistant_message(self, agent_name: str, message: str):
81+
header = Text(
82+
f"🤖 {agent_name.upper()}:",
83+
style=RICH_STYLE_GREEN_BOLD,
84+
)
85+
assistant_panel = Panel(
86+
Markdown(message, code_theme=CODE_THEME),
87+
title=header,
88+
title_align="left",
89+
border_style=RICH_STYLE_GREEN,
90+
)
91+
self.console.print(assistant_panel)
92+
6793
def display_divider(self):
6894
"""Display a divider line."""
6995
pass
@@ -163,19 +189,13 @@ def display_loaded_conversation(self, messages, message_handler):
163189
for msg in messages[last_consolidated_idx:]:
164190
role = msg.get("role")
165191
if role == "user":
166-
self.console.print(Text("\n👤 YOU:", style=RICH_STYLE_BLUE_BOLD))
167192
content = self._extract_message_content(msg)
168-
self.console.print(content)
169-
self.display_divider()
193+
self.display_user_message(content)
170194
elif role == "assistant":
171-
agent_name = message_handler.agent.name
172-
self.console.print(
173-
Text(f"\n🤖 {agent_name.upper()}:", style=RICH_STYLE_GREEN_BOLD)
174-
)
195+
agent_name = msg.get("agent") or message_handler.agent.name
175196
content = self._extract_message_content(msg)
176197
# Format as markdown for better display
177-
self.console.print(Markdown(content, code_theme=CODE_THEME))
178-
self.display_divider()
198+
self.display_assistant_message(agent_name, content)
179199
if "tool_calls" in msg:
180200
from .tool_display import ToolDisplayHandlers
181201

0 commit comments

Comments
 (0)