Skip to content

Commit f2229af

Browse files
committed
Merge branch 'master' into feat/outlook-toolkit
2 parents c430bde + 5daac34 commit f2229af

File tree

16 files changed

+8612
-11478
lines changed

16 files changed

+8612
-11478
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body:
2626
attributes:
2727
label: What version of camel are you using?
2828
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
29-
placeholder: E.g., 0.2.81a0
29+
placeholder: E.g., 0.2.82
3030
validations:
3131
required: true
3232

.github/dependabot.yml

Lines changed: 0 additions & 86 deletions
This file was deleted.

camel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from camel.logger import disable_logging, enable_logging, set_log_level
1616

17-
__version__ = '0.2.81a0'
17+
__version__ = '0.2.82'
1818

1919
__all__ = [
2020
'__version__',

camel/agents/chat_agent.py

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
)
106106
from camel.utils.commons import dependencies_required
107107
from camel.utils.context_utils import ContextUtility
108+
from camel.utils.tool_result import ToolResult
108109

109110
TOKEN_LIMIT_ERROR_MARKERS = (
110111
"context_length_exceeded",
@@ -3356,9 +3357,11 @@ def _update_token_usage_tracker(
33563357
tracker (Dict[str, int]): The token usage tracker to update.
33573358
usage_dict (Dict[str, int]): The usage dictionary with new values.
33583359
"""
3359-
tracker["prompt_tokens"] += usage_dict.get("prompt_tokens", 0)
3360-
tracker["completion_tokens"] += usage_dict.get("completion_tokens", 0)
3361-
tracker["total_tokens"] += usage_dict.get("total_tokens", 0)
3360+
tracker["prompt_tokens"] += usage_dict.get("prompt_tokens") or 0
3361+
tracker["completion_tokens"] += (
3362+
usage_dict.get("completion_tokens") or 0
3363+
)
3364+
tracker["total_tokens"] += usage_dict.get("total_tokens") or 0
33623365

33633366
def _convert_to_chatagent_response(
33643367
self,
@@ -4036,6 +4039,65 @@ def _record_tool_calling(
40364039
cast(List[MemoryRecord], func_records),
40374040
)
40384041

4042+
if isinstance(result, ToolResult) and result.images:
4043+
try:
4044+
import base64
4045+
import io
4046+
4047+
try:
4048+
from PIL import Image
4049+
except ImportError:
4050+
logger.warning(
4051+
f"Tool '{func_name}' returned images but PIL "
4052+
"is not installed. Install with: pip install "
4053+
"Pillow. Skipping visual context injection."
4054+
)
4055+
# Continue without injecting images
4056+
result = (
4057+
result.text if hasattr(result, 'text') else str(result)
4058+
)
4059+
else:
4060+
logger.info(
4061+
f"Tool '{func_name}' returned ToolResult with "
4062+
f"{len(result.images)} image(s), injecting into "
4063+
"context"
4064+
)
4065+
4066+
# Convert base64 images to PIL Image objects
4067+
pil_images: List[Union[Image.Image, str]] = []
4068+
for img_data in result.images:
4069+
if img_data.startswith('data:image/'):
4070+
# Extract base64 data
4071+
base64_str = img_data.split(',', 1)[1]
4072+
img_bytes = base64.b64decode(base64_str)
4073+
pil_img = Image.open(io.BytesIO(img_bytes))
4074+
pil_images.append(pil_img)
4075+
4076+
if pil_images:
4077+
# Create a user message with the image(s)
4078+
visual_msg = BaseMessage.make_user_message(
4079+
role_name="Tool",
4080+
content=f"[Visual output from {func_name}]",
4081+
image_list=pil_images,
4082+
)
4083+
4084+
# Inject into conversation context with slight
4085+
# timestamp increment
4086+
self.update_memory(
4087+
visual_msg,
4088+
OpenAIBackendRole.USER,
4089+
timestamp=base_timestamp + 2e-6,
4090+
return_records=False,
4091+
)
4092+
logger.info(
4093+
f"Successfully injected {len(pil_images)} "
4094+
"image(s) into agent context"
4095+
)
4096+
except Exception as e:
4097+
logger.error(
4098+
f"Failed to inject visual content from {func_name}: {e}"
4099+
)
4100+
40394101
# Record information about this tool call
40404102
tool_record = ToolCallingRecord(
40414103
tool_name=func_name,

camel/toolkits/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
from .vertex_ai_veo_toolkit import VertexAIVeoToolkit
9898
from .minimax_mcp_toolkit import MinimaxMCPToolkit
9999
from .microsoft_outlook_mail_toolkit import OutlookMailToolkit
100+
from .earth_science_toolkit import EarthScienceToolkit
100101

101102
__all__ = [
102103
'BaseToolkit',
@@ -184,4 +185,5 @@
184185
'VertexAIVeoToolkit',
185186
'MinimaxMCPToolkit',
186187
"OutlookMailToolkit",
188+
'EarthScienceToolkit',
187189
]

0 commit comments

Comments
 (0)