Skip to content

Commit 9cf357d

Browse files
committed
fix bug related to copilot cannot see image
1 parent f530bd3 commit 9cf357d

File tree

10 files changed

+83
-48
lines changed

10 files changed

+83
-48
lines changed

AgentCrew/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.6.2"
1+
__version__ = "0.6.3"

AgentCrew/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ def cli():
3636

3737

3838
def cli_prod():
39+
from AgentCrew.modules import FileLogIO
40+
41+
sys.stderr = FileLogIO()
42+
43+
os.environ["AGENTCREW_LOG_PATH"] = os.path.expanduser("~/.AgentCrew/logs")
3944
os.environ["MEMORYDB_PATH"] = os.path.expanduser("~/.AgentCrew/memorydb")
4045
os.environ["MCP_CONFIG_PATH"] = os.path.expanduser("~/.AgentCrew/mcp_servers.json")
4146
os.environ["SW_AGENTS_CONFIG"] = os.path.expanduser("~/.AgentCrew/agents.toml")
4247
os.environ["PERSISTENCE_DIR"] = os.path.expanduser("~/.AgentCrew/persistents")
4348
os.environ["AGENTCREW_CONFIG_PATH"] = os.path.expanduser("~/.AgentCrew/config.json")
49+
4450
check_and_update()
4551
cli() # Delegate to main CLI function
4652

AgentCrew/modules/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import logging
22
import sys
3+
import tempfile
4+
from datetime import datetime
5+
import os
6+
7+
from typing import TextIO, AnyStr
38

49
LOG_LEVEL = logging.ERROR
510
# Create a logger
@@ -22,3 +27,38 @@
2227

2328
# Optional: Prevent duplicate logging if this module is imported multiple times
2429
logger.propagate = False
30+
31+
32+
class FileLogIO(TextIO):
33+
"""File-like object compatible with sys.stderr for MCP logging."""
34+
35+
def __init__(self, file_format: str = "agentcrew"):
36+
log_dir_path = os.getenv("AGENTCREW_LOG_PATH", tempfile.gettempdir())
37+
os.makedirs(log_dir_path, exist_ok=True)
38+
self.log_path = (
39+
log_dir_path + f"/{file_format}_{datetime.now().timestamp()}.log"
40+
)
41+
self.file = open(self.log_path, "w+")
42+
43+
def write(self, data: AnyStr) -> int:
44+
"""Write data to the log file."""
45+
if isinstance(data, bytes):
46+
# Convert bytes to string for writing
47+
str_data = data.decode("utf-8", errors="replace")
48+
else:
49+
str_data = str(data)
50+
self.file.write(str_data)
51+
self.file.flush() # Ensure data is written immediately
52+
return 0
53+
54+
def flush(self):
55+
"""Flush the file buffer."""
56+
self.file.flush()
57+
58+
def close(self):
59+
"""Close the file."""
60+
self.file.close()
61+
62+
def fileno(self):
63+
"""Return the file descriptor."""
64+
return self.file.fileno()

AgentCrew/modules/chat/console_ui.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,16 @@ def _(event):
11031103
else:
11041104
self._last_ctrl_c_time = current_time
11051105
if self.live:
1106-
self.message_handler.stop_streaming = True
1106+
if self.message_handler.stream_generator:
1107+
try:
1108+
asyncio.run(self.message_handler.stream_generator.aclose())
1109+
except RuntimeError as e:
1110+
logger.warning(f"Error closing stream generator: {e}")
1111+
except Exception as e:
1112+
logger.warning(f"Exception closing stream generator: {e}")
1113+
finally:
1114+
self.message_handler.stop_streaming = True
1115+
self.message_handler.stream_generator = None
11071116

11081117
self.console.print(
11091118
Text(

AgentCrew/modules/chat/message/command_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Optional, Tuple, List, Dict, Any, Union
2+
from typing import Optional, Tuple, List, Dict
33
import os
44

55
from AgentCrew.modules.agents.local_agent import LocalAgent

AgentCrew/modules/custom_llm/github_copilot_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def format_tool_result(
9797
parsed_tool_result = []
9898
for res in tool_result:
9999
if res.get("type", "text") == "image_url":
100-
if "vision" in ModelRegistry.get_model_capabilities(self.model):
100+
if "vision" in ModelRegistry.get_model_capabilities(
101+
f"{self._provider_name}/{self.model}"
102+
):
101103
parsed_tool_result.append(res)
102104
else:
103105
parsed_tool_result.append(res)
@@ -170,7 +172,9 @@ async def stream_assistant_response(self, messages):
170172
)
171173
> 0
172174
):
173-
if "vision" in ModelRegistry.get_model_capabilities(self.model):
175+
if "vision" in ModelRegistry.get_model_capabilities(
176+
f"{self._provider_name}/{self.model}"
177+
):
174178
self.extra_headers["Copilot-Vision-Request"] = "true"
175179

176180
# if self._interaction_id:

AgentCrew/modules/llm/service_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ def get_service(self, provider: str) -> BaseLLMService:
138138
.endswith(".githubcopilot.com")
139139
):
140140
# Special case for OpenAI compatible custom providers
141-
return GithubCopilotService(api_key=api_key, provider_name=provider)
141+
service_instance = GithubCopilotService(
142+
api_key=api_key, provider_name=provider
143+
)
142144
else:
143-
return CustomLLMService(
145+
service_instance = CustomLLMService(
144146
base_url=details["api_base_url"],
145147
api_key=api_key,
146148
provider_name=provider,

AgentCrew/modules/mcpclient/service.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from AgentCrew.modules import logger
2-
from typing import Dict, Any, List, Optional, Callable, TextIO, AnyStr
2+
from typing import Dict, Any, List, Optional, Callable
33
from mcp import ClientSession, StdioServerParameters
44
from mcp.types import Prompt, ContentBlock, TextContent, ImageContent
55
from mcp.client.stdio import stdio_client
@@ -8,46 +8,10 @@
88
from .config import MCPServerConfig
99
import asyncio
1010
import threading
11-
import tempfile
12-
from datetime import datetime
13-
14-
15-
class MCPLogIO(TextIO):
16-
"""File-like object compatible with sys.stderr for MCP logging."""
17-
18-
def __init__(self):
19-
self.log_path = (
20-
tempfile.gettempdir() + f"/mcp_agentcrew_{datetime.now().timestamp()}.log"
21-
)
22-
print(f"Routing MCP logs to {self.log_path}")
23-
self.file = open(self.log_path, "w+")
24-
25-
def write(self, data: AnyStr) -> int:
26-
"""Write data to the log file."""
27-
if isinstance(data, bytes):
28-
# Convert bytes to string for writing
29-
str_data = data.decode("utf-8", errors="replace")
30-
else:
31-
str_data = str(data)
32-
self.file.write(str_data)
33-
self.file.flush() # Ensure data is written immediately
34-
return 0
35-
36-
def flush(self):
37-
"""Flush the file buffer."""
38-
self.file.flush()
39-
40-
def close(self):
41-
"""Close the file."""
42-
self.file.close()
43-
44-
def fileno(self):
45-
"""Return the file descriptor."""
46-
return self.file.fileno()
47-
11+
from AgentCrew.modules import FileLogIO
4812

4913
# Initialize the logger
50-
mcp_log_io = MCPLogIO()
14+
mcp_log_io = FileLogIO("mcpclient_agentcrew")
5115

5216

5317
class MCPService:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "agentcrew-ai"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
requires-python = ">=3.12"
55
classifiers = [
66
"Programming Language :: Python :: 3",

uv.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)