agno 2.2.2__py3-none-any.whl → 2.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
agno/agent/agent.py CHANGED
@@ -220,7 +220,9 @@ class Agent:
220
220
  # add_history_to_context=true adds messages from the chat history to the messages list sent to the Model.
221
221
  add_history_to_context: bool = False
222
222
  # Number of historical runs to include in the messages
223
- num_history_runs: int = 3
223
+ num_history_runs: Optional[int] = None
224
+ # Number of historical messages to include in the messages list sent to the Model.
225
+ num_history_messages: Optional[int] = None
224
226
  # Maximum number of tool calls to include from history (None = no limit)
225
227
  max_tool_calls_from_history: Optional[int] = None
226
228
 
@@ -438,7 +440,8 @@ class Agent:
438
440
  add_session_summary_to_context: Optional[bool] = None,
439
441
  session_summary_manager: Optional[SessionSummaryManager] = None,
440
442
  add_history_to_context: bool = False,
441
- num_history_runs: int = 3,
443
+ num_history_runs: Optional[int] = None,
444
+ num_history_messages: Optional[int] = None,
442
445
  max_tool_calls_from_history: Optional[int] = None,
443
446
  store_media: bool = True,
444
447
  store_tool_messages: bool = True,
@@ -541,6 +544,15 @@ class Agent:
541
544
 
542
545
  self.add_history_to_context = add_history_to_context
543
546
  self.num_history_runs = num_history_runs
547
+ self.num_history_messages = num_history_messages
548
+ if self.num_history_messages is not None and self.num_history_runs is not None:
549
+ log_warning(
550
+ "num_history_messages and num_history_runs cannot be set at the same time. Using num_history_runs."
551
+ )
552
+ self.num_history_messages = None
553
+ if self.num_history_messages is None and self.num_history_runs is None:
554
+ self.num_history_runs = 3
555
+
544
556
  self.max_tool_calls_from_history = max_tool_calls_from_history
545
557
 
546
558
  self.store_media = store_media
@@ -5133,7 +5145,7 @@ class Agent:
5133
5145
  run_messages.user_message.get_content_string() if run_messages.user_message is not None else None
5134
5146
  )
5135
5147
  if user_message_str is not None and user_message_str.strip() != "" and self.memory_manager is not None:
5136
- log_debug("Creating user memories.")
5148
+ log_debug("Managing user memories")
5137
5149
  self.memory_manager.create_user_memories( # type: ignore
5138
5150
  message=user_message_str,
5139
5151
  user_id=user_id,
@@ -5174,7 +5186,7 @@ class Agent:
5174
5186
  run_messages.user_message.get_content_string() if run_messages.user_message is not None else None
5175
5187
  )
5176
5188
  if user_message_str is not None and user_message_str.strip() != "" and self.memory_manager is not None:
5177
- log_debug("Creating user memories.")
5189
+ log_debug("Managing user memories")
5178
5190
  await self.memory_manager.acreate_user_memories( # type: ignore
5179
5191
  message=user_message_str,
5180
5192
  user_id=user_id,
@@ -7461,6 +7473,7 @@ class Agent:
7461
7473
 
7462
7474
  history: List[Message] = session.get_messages_from_last_n_runs(
7463
7475
  last_n=self.num_history_runs,
7476
+ last_n_messages=self.num_history_messages,
7464
7477
  skip_role=skip_role,
7465
7478
  agent_id=self.id if self.team_id is not None else None,
7466
7479
  )
@@ -7658,9 +7671,17 @@ class Agent:
7658
7671
  if add_history_to_context:
7659
7672
  from copy import deepcopy
7660
7673
 
7674
+ # Only skip messages from history when system_message_role is NOT a standard conversation role.
7675
+ # Standard conversation roles ("user", "assistant", "tool") should never be filtered
7676
+ # to preserve conversation continuity.
7677
+ skip_role = (
7678
+ self.system_message_role if self.system_message_role not in ["user", "assistant", "tool"] else None
7679
+ )
7680
+
7661
7681
  history: List[Message] = session.get_messages_from_last_n_runs(
7662
7682
  last_n=self.num_history_runs,
7663
- skip_role=self.system_message_role,
7683
+ last_n_messages=self.num_history_messages,
7684
+ skip_role=skip_role,
7664
7685
  agent_id=self.id if self.team_id is not None else None,
7665
7686
  )
7666
7687
 
agno/db/dynamo/utils.py CHANGED
@@ -361,7 +361,7 @@ def calculate_date_metrics(date_to_process: date, sessions_data: dict) -> dict:
361
361
  token_metrics[field] += session_metrics.get(field, 0)
362
362
  model_metrics = []
363
363
  for model, count in model_counts.items():
364
- model_id, model_provider = model.split(":")
364
+ model_id, model_provider = model.rsplit(":", 1)
365
365
  model_metrics.append({"model_id": model_id, "model_provider": model_provider, "count": count})
366
366
  metrics["users_count"] = len(all_user_ids)
367
367
  current_time = int(time.time())
@@ -224,7 +224,7 @@ def calculate_date_metrics(date_to_process: date, sessions_data: dict) -> dict:
224
224
 
225
225
  model_metrics = []
226
226
  for model, count in model_counts.items():
227
- model_id, model_provider = model.split(":")
227
+ model_id, model_provider = model.rsplit(":", 1)
228
228
  model_metrics.append({"model_id": model_id, "model_provider": model_provider, "count": count})
229
229
 
230
230
  metrics["users_count"] = len(all_user_ids)
agno/db/gcs_json/utils.py CHANGED
@@ -99,7 +99,7 @@ def calculate_date_metrics(date_to_process: date, sessions_data: dict) -> dict:
99
99
 
100
100
  model_metrics = []
101
101
  for model, count in model_counts.items():
102
- model_id, model_provider = model.split(":")
102
+ model_id, model_provider = model.rsplit(":", 1)
103
103
  model_metrics.append({"model_id": model_id, "model_provider": model_provider, "count": count})
104
104
 
105
105
  metrics["users_count"] = len(all_user_ids)
@@ -99,7 +99,7 @@ def calculate_date_metrics(date_to_process: date, sessions_data: dict) -> dict:
99
99
 
100
100
  model_metrics = []
101
101
  for model, count in model_counts.items():
102
- model_id, model_provider = model.split(":")
102
+ model_id, model_provider = model.rsplit(":", 1)
103
103
  model_metrics.append({"model_id": model_id, "model_provider": model_provider, "count": count})
104
104
 
105
105
  metrics["users_count"] = len(all_user_ids)
agno/db/json/utils.py CHANGED
@@ -99,7 +99,7 @@ def calculate_date_metrics(date_to_process: date, sessions_data: dict) -> dict:
99
99
 
100
100
  model_metrics = []
101
101
  for model, count in model_counts.items():
102
- model_id, model_provider = model.split(":")
102
+ model_id, model_provider = model.rsplit(":", 1)
103
103
  model_metrics.append({"model_id": model_id, "model_provider": model_provider, "count": count})
104
104
 
105
105
  metrics["users_count"] = len(all_user_ids)
agno/db/mongo/__init__.py CHANGED
@@ -1,3 +1,17 @@
1
+ from typing import TYPE_CHECKING
2
+
1
3
  from agno.db.mongo.mongo import MongoDb
2
4
 
3
- __all__ = ["MongoDb"]
5
+ if TYPE_CHECKING:
6
+ from agno.db.mongo.async_mongo import AsyncMongoDb
7
+
8
+ __all__ = ["AsyncMongoDb", "MongoDb"]
9
+
10
+
11
+ def __getattr__(name: str):
12
+ """Lazy import AsyncMongoDb only when accessed."""
13
+ if name == "AsyncMongoDb":
14
+ from agno.db.mongo.async_mongo import AsyncMongoDb
15
+
16
+ return AsyncMongoDb
17
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")