Skip to content

Commit d7dbfb5

Browse files
committed
Update
2 parents aa50ade + 8068e01 commit d7dbfb5

File tree

12 files changed

+65
-88
lines changed

12 files changed

+65
-88
lines changed

libs/agno/agno/knowledge/agent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def load(
123123

124124
# Upsert documents if upsert is True and vector db supports upsert
125125
if upsert and self.vector_db.upsert_available():
126-
self.vector_db.upsert(documents=document_list, filters=doc.meta_data)
126+
for doc in document_list:
127+
self.vector_db.upsert(documents=[doc], filters=doc.meta_data)
127128
# Insert documents
128129
else:
129130
# Filter out documents which already exist in the vector db
@@ -132,7 +133,8 @@ def load(
132133
documents_to_load = self.filter_existing_documents(document_list)
133134

134135
if documents_to_load:
135-
self.vector_db.insert(documents=documents_to_load, filters=doc.meta_data)
136+
for doc in documents_to_load:
137+
self.vector_db.insert(documents=[doc], filters=doc.meta_data)
136138

137139
num_documents += len(documents_to_load)
138140
log_info(f"Added {len(documents_to_load)} documents to knowledge base")
@@ -174,7 +176,8 @@ async def aload(
174176

175177
# Upsert documents if upsert is True and vector db supports upsert
176178
if upsert and self.vector_db.upsert_available():
177-
await self.vector_db.async_upsert(documents=document_list, filters=doc.meta_data)
179+
for doc in document_list:
180+
await self.vector_db.async_upsert(documents=[doc], filters=doc.meta_data)
178181
# Insert documents
179182
else:
180183
# Filter out documents which already exist in the vector db
@@ -183,7 +186,8 @@ async def aload(
183186
documents_to_load = self.filter_existing_documents(document_list)
184187

185188
if documents_to_load:
186-
await self.vector_db.async_insert(documents=documents_to_load, filters=doc.meta_data)
189+
for doc in documents_to_load:
190+
await self.vector_db.async_insert(documents=[doc], filters=doc.meta_data)
187191

188192
num_documents += len(documents_to_load)
189193
log_info(f"Added {len(documents_to_load)} documents to knowledge base")

libs/agno/agno/models/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ def _add_usage_metrics_to_assistant_message(assistant_message: Message, response
104104
)
105105

106106
# If you didn't capture any total tokens
107-
if (assistant_message.metrics.input_tokens or assistant_message.metrics.output_tokens) and not assistant_message.metrics.total_tokens:
108-
assistant_message.metrics.total_tokens = assistant_message.metrics.input_tokens + assistant_message.metrics.output_tokens
107+
if (
108+
assistant_message.metrics.input_tokens or assistant_message.metrics.output_tokens
109+
) and not assistant_message.metrics.total_tokens:
110+
assistant_message.metrics.total_tokens = (
111+
assistant_message.metrics.input_tokens + assistant_message.metrics.output_tokens
112+
)
109113

110114
# Additional metrics (e.g., from Groq, Ollama)
111115
if isinstance(response_usage, dict) and "additional_metrics" in response_usage:

libs/agno/agno/tools/apify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def actor_function(**kwargs) -> str:
156156
actor_function.__doc__ = docstring
157157

158158
# Register the function with the toolkit
159-
self.register(actor_function, sanitize_arguments=False)
159+
self.register(actor_function)
160160
# Fix params schema
161161
self.functions[tool_name].parameters = props_to_json_schema(properties, required)
162162
log_info(f"Registered Apify Actor '{actor_id}' as function '{tool_name}'")

libs/agno/agno/tools/decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def tool(*args, **kwargs) -> Union[Function, Callable[[F], Function]]:
4848
name: Optional[str] - Override for the function name
4949
description: Optional[str] - Override for the function description
5050
strict: Optional[bool] - Flag for strict parameter checking
51-
sanitize_arguments: Optional[bool] - If True, arguments are sanitized before passing to function
51+
sanitize_arguments: Optional[bool] - If True, arguments are sanitized before passing to function (Deprecated)
5252
instructions: Optional[str] - Instructions for using the tool
5353
add_instructions: bool - If True, add instructions to the system message
5454
show_result: Optional[bool] - If True, shows the result after function call

libs/agno/agno/tools/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Function(BaseModel):
8383
entrypoint: Optional[Callable] = None
8484
# If True, the entrypoint processing is skipped and the Function is used as is.
8585
skip_entrypoint_processing: bool = False
86-
# If True, the arguments are sanitized before being passed to the function.
87-
sanitize_arguments: bool = True
86+
# If True, the arguments are sanitized before being passed to the function. (Deprecated)
87+
sanitize_arguments: bool = False
8888
# If True, the function call will show the result along with sending it to the model.
8989
show_result: bool = False
9090
# If True, the agent will stop after the function call.

libs/agno/agno/tools/toolkit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ def _register_tools(self) -> None:
105105
for tool in self.tools:
106106
self.register(tool)
107107

108-
def register(self, function: Callable[..., Any], sanitize_arguments: bool = True, name: Optional[str] = None):
108+
def register(self, function: Callable[..., Any], name: Optional[str] = None):
109109
"""Register a function with the toolkit.
110110
111111
Args:
112112
function: The callable to register
113-
sanitize_arguments: Whether to sanitize arguments before passing to the function
114113
name: Optional custom name for the function
115114
116115
Returns:
@@ -126,7 +125,6 @@ def register(self, function: Callable[..., Any], sanitize_arguments: bool = True
126125
f = Function(
127126
name=tool_name,
128127
entrypoint=function,
129-
sanitize_arguments=sanitize_arguments,
130128
cache_results=self.cache_results,
131129
cache_dir=self.cache_dir,
132130
cache_ttl=self.cache_ttl,

libs/agno/agno/utils/functions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ def get_function_call(
2828
function_call.call_id = call_id
2929
if arguments is not None and arguments != "":
3030
try:
31-
if function_to_call.sanitize_arguments:
32-
if "None" in arguments:
33-
arguments = arguments.replace("None", "null")
34-
if "True" in arguments:
35-
arguments = arguments.replace("True", "true")
36-
if "False" in arguments:
37-
arguments = arguments.replace("False", "false")
38-
_arguments = json.loads(arguments)
31+
try:
32+
_arguments = json.loads(arguments)
33+
except Exception:
34+
import ast
35+
36+
_arguments = ast.literal_eval(arguments)
3937
except Exception as e:
4038
log_error(f"Unable to decode function arguments:\n{arguments}\nError: {e}")
4139
function_call.error = (

libs/agno/agno/utils/models/aws_claude.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def format_messages(messages: List[Message]) -> Tuple[List[Dict[str, str]], str]
151151
elif message.role == "assistant":
152152
content = []
153153

154-
if isinstance(message.content, str) and message.content:
154+
if isinstance(message.content, str) and message.content and len(message.content.strip()) > 0:
155155
content.append(TextBlock(text=message.content, type="text"))
156156

157157
if message.tool_calls:

libs/agno/agno/utils/models/claude.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def format_messages(messages: List[Message]) -> Tuple[List[Dict[str, str]], str]
245245

246246
content.append(RedactedThinkingBlock(data=message.redacted_thinking, type="redacted_thinking"))
247247

248-
if isinstance(message.content, str) and message.content:
248+
if isinstance(message.content, str) and message.content and len(message.content.strip()) > 0:
249249
content.append(TextBlock(text=message.content, type="text"))
250250

251251
if message.tool_calls:

libs/agno/tests/unit/tools/test_functions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ def test_tool_decorator_with_config():
533533
strict=True,
534534
instructions="Custom instructions",
535535
add_instructions=False,
536-
sanitize_arguments=False,
537536
show_result=True,
538537
stop_after_tool_call=True,
539538
requires_confirmation=True,
@@ -551,7 +550,6 @@ def configured_func() -> str:
551550
assert configured_func.strict is True
552551
assert configured_func.instructions == "Custom instructions"
553552
assert configured_func.add_instructions is False
554-
assert configured_func.sanitize_arguments is False
555553
assert configured_func.show_result is True
556554
assert configured_func.stop_after_tool_call is True
557555
assert configured_func.requires_confirmation is True

0 commit comments

Comments
 (0)