agno 2.0.7__py3-none-any.whl → 2.0.8__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.
@@ -35,10 +35,16 @@ class EventBuffer:
35
35
 
36
36
  active_tool_call_ids: Set[str] # All currently active tool calls
37
37
  ended_tool_call_ids: Set[str] # All tool calls that have ended
38
+ current_text_message_id: str = "" # ID of the current text message context (for tool call parenting)
39
+ next_text_message_id: str = "" # Pre-generated ID for the next text message
40
+ pending_tool_calls_parent_id: str = "" # Parent message ID for pending tool calls
38
41
 
39
42
  def __init__(self):
40
43
  self.active_tool_call_ids = set()
41
44
  self.ended_tool_call_ids = set()
45
+ self.current_text_message_id = ""
46
+ self.next_text_message_id = str(uuid.uuid4())
47
+ self.pending_tool_calls_parent_id = ""
42
48
 
43
49
  def start_tool_call(self, tool_call_id: str) -> None:
44
50
  """Start a new tool call."""
@@ -49,6 +55,29 @@ class EventBuffer:
49
55
  self.active_tool_call_ids.discard(tool_call_id)
50
56
  self.ended_tool_call_ids.add(tool_call_id)
51
57
 
58
+ def start_text_message(self) -> str:
59
+ """Start a new text message and return its ID."""
60
+ # Use the pre-generated next ID as current, and generate a new next ID
61
+ self.current_text_message_id = self.next_text_message_id
62
+ self.next_text_message_id = str(uuid.uuid4())
63
+ return self.current_text_message_id
64
+
65
+ def get_parent_message_id_for_tool_call(self) -> str:
66
+ """Get the message ID to use as parent for tool calls."""
67
+ # If we have a pending parent ID set (from text message end), use that
68
+ if self.pending_tool_calls_parent_id:
69
+ return self.pending_tool_calls_parent_id
70
+ # Otherwise use current text message ID
71
+ return self.current_text_message_id
72
+
73
+ def set_pending_tool_calls_parent_id(self, parent_id: str) -> None:
74
+ """Set the parent message ID for upcoming tool calls."""
75
+ self.pending_tool_calls_parent_id = parent_id
76
+
77
+ def clear_pending_tool_calls_parent_id(self) -> None:
78
+ """Clear the pending parent ID when a new text message starts."""
79
+ self.pending_tool_calls_parent_id = ""
80
+
52
81
 
53
82
  def convert_agui_messages_to_agno_messages(messages: List[AGUIMessage]) -> List[Message]:
54
83
  """Convert AG-UI messages to Agno messages."""
@@ -113,10 +142,18 @@ def _create_events_from_chunk(
113
142
  message_id: str,
114
143
  message_started: bool,
115
144
  event_buffer: EventBuffer,
116
- ) -> Tuple[List[BaseEvent], bool]:
145
+ ) -> Tuple[List[BaseEvent], bool, str]:
117
146
  """
118
147
  Process a single chunk and return events to emit + updated message_started state.
119
- Returns: (events_to_emit, new_message_started_state)
148
+
149
+ Args:
150
+ chunk: The event chunk to process
151
+ message_id: Current message identifier
152
+ message_started: Whether a message is currently active
153
+ event_buffer: Event buffer for tracking tool call state
154
+
155
+ Returns:
156
+ Tuple of (events_to_emit, new_message_started_state, message_id)
120
157
  """
121
158
  events_to_emit: List[BaseEvent] = []
122
159
 
@@ -133,6 +170,11 @@ def _create_events_from_chunk(
133
170
  # Handle the message start event, emitted once per message
134
171
  if not message_started:
135
172
  message_started = True
173
+ message_id = event_buffer.start_text_message()
174
+
175
+ # Clear pending tool calls parent ID when starting new text message
176
+ event_buffer.clear_pending_tool_calls_parent_id()
177
+
136
178
  start_event = TextMessageStartEvent(
137
179
  type=EventType.TEXT_MESSAGE_START,
138
180
  message_id=message_id,
@@ -149,21 +191,37 @@ def _create_events_from_chunk(
149
191
  )
150
192
  events_to_emit.append(content_event) # type: ignore
151
193
 
152
- # Handle starting a new tool call
153
- elif chunk.event == RunEvent.tool_call_started:
154
- # End the current text message if one is active before starting tool calls
155
- if message_started:
156
- end_message_event = TextMessageEndEvent(type=EventType.TEXT_MESSAGE_END, message_id=message_id)
157
- events_to_emit.append(end_message_event)
158
- message_started = False # Reset message_started state
159
-
194
+ # Handle starting a new tool
195
+ elif chunk.event == RunEvent.tool_call_started or chunk.event == TeamRunEvent.tool_call_started:
160
196
  if chunk.tool is not None: # type: ignore
161
197
  tool_call = chunk.tool # type: ignore
198
+
199
+ # End current text message and handle for tool calls
200
+ current_message_id = message_id
201
+ if message_started:
202
+ # End the current text message
203
+ end_message_event = TextMessageEndEvent(type=EventType.TEXT_MESSAGE_END, message_id=current_message_id)
204
+ events_to_emit.append(end_message_event)
205
+
206
+ # Set this message as the parent for any upcoming tool calls
207
+ # This ensures multiple sequential tool calls all use the same parent
208
+ event_buffer.set_pending_tool_calls_parent_id(current_message_id)
209
+
210
+ # Reset message started state and generate new message_id for future messages
211
+ message_started = False
212
+ message_id = str(uuid.uuid4())
213
+
214
+ # Get the parent message ID - this will use pending parent if set, ensuring multiple tool calls in sequence have the same parent
215
+ parent_message_id = event_buffer.get_parent_message_id_for_tool_call()
216
+
217
+ if not parent_message_id:
218
+ parent_message_id = current_message_id
219
+
162
220
  start_event = ToolCallStartEvent(
163
221
  type=EventType.TOOL_CALL_START,
164
222
  tool_call_id=tool_call.tool_call_id, # type: ignore
165
223
  tool_call_name=tool_call.tool_name, # type: ignore
166
- parent_message_id=message_id,
224
+ parent_message_id=parent_message_id,
167
225
  )
168
226
  events_to_emit.append(start_event)
169
227
 
@@ -175,7 +233,7 @@ def _create_events_from_chunk(
175
233
  events_to_emit.append(args_event) # type: ignore
176
234
 
177
235
  # Handle tool call completion
178
- elif chunk.event == RunEvent.tool_call_completed:
236
+ elif chunk.event == RunEvent.tool_call_completed or chunk.event == TeamRunEvent.tool_call_completed:
179
237
  if chunk.tool is not None: # type: ignore
180
238
  tool_call = chunk.tool # type: ignore
181
239
  if tool_call.tool_call_id not in event_buffer.ended_tool_call_ids:
@@ -203,7 +261,7 @@ def _create_events_from_chunk(
203
261
  step_finished_event = StepFinishedEvent(type=EventType.STEP_FINISHED, step_name="reasoning")
204
262
  events_to_emit.append(step_finished_event)
205
263
 
206
- return events_to_emit, message_started
264
+ return events_to_emit, message_started, message_id
207
265
 
208
266
 
209
267
  def _create_completion_events(
@@ -237,11 +295,16 @@ def _create_completion_events(
237
295
  if tool.tool_call_id is None or tool.tool_name is None:
238
296
  continue
239
297
 
298
+ # Use the current text message ID from event buffer as parent
299
+ parent_message_id = event_buffer.get_parent_message_id_for_tool_call()
300
+ if not parent_message_id:
301
+ parent_message_id = message_id # Fallback to the passed message_id
302
+
240
303
  start_event = ToolCallStartEvent(
241
304
  type=EventType.TOOL_CALL_START,
242
305
  tool_call_id=tool.tool_call_id,
243
306
  tool_call_name=tool.tool_name,
244
- parent_message_id=message_id,
307
+ parent_message_id=parent_message_id,
245
308
  )
246
309
  events_to_emit.append(start_event)
247
310
 
@@ -285,7 +348,7 @@ def stream_agno_response_as_agui_events(
285
348
  response_stream: Iterator[Union[RunOutputEvent, TeamRunOutputEvent]], thread_id: str, run_id: str
286
349
  ) -> Iterator[BaseEvent]:
287
350
  """Map the Agno response stream to AG-UI format, handling event ordering constraints."""
288
- message_id = str(uuid.uuid4())
351
+ message_id = "" # Will be set by EventBuffer when text message starts
289
352
  message_started = False
290
353
  event_buffer = EventBuffer()
291
354
  stream_completed = False
@@ -304,7 +367,7 @@ def stream_agno_response_as_agui_events(
304
367
  stream_completed = True
305
368
  else:
306
369
  # Process regular chunk immediately
307
- events_from_chunk, message_started = _create_events_from_chunk(
370
+ events_from_chunk, message_started, message_id = _create_events_from_chunk(
308
371
  chunk, message_id, message_started, event_buffer
309
372
  )
310
373
 
@@ -345,7 +408,7 @@ async def async_stream_agno_response_as_agui_events(
345
408
  run_id: str,
346
409
  ) -> AsyncIterator[BaseEvent]:
347
410
  """Map the Agno response stream to AG-UI format, handling event ordering constraints."""
348
- message_id = str(uuid.uuid4())
411
+ message_id = "" # Will be set by EventBuffer when text message starts
349
412
  message_started = False
350
413
  event_buffer = EventBuffer()
351
414
  stream_completed = False
@@ -364,7 +427,7 @@ async def async_stream_agno_response_as_agui_events(
364
427
  stream_completed = True
365
428
  else:
366
429
  # Process regular chunk immediately
367
- events_from_chunk, message_started = _create_events_from_chunk(
430
+ events_from_chunk, message_started, message_id = _create_events_from_chunk(
368
431
  chunk, message_id, message_started, event_buffer
369
432
  )
370
433
 
@@ -20,8 +20,8 @@ class Slack(BaseInterface):
20
20
  self.agent = agent
21
21
  self.team = team
22
22
 
23
- if not self.agent and not self.team:
24
- raise ValueError("Slack requires an agent and a team")
23
+ if not (self.agent or self.team):
24
+ raise ValueError("Slack requires an agent or a team")
25
25
 
26
26
  def get_router(self, **kwargs) -> APIRouter:
27
27
  # Cannot be overridden
@@ -17,8 +17,8 @@ class Whatsapp(BaseInterface):
17
17
  self.agent = agent
18
18
  self.team = team
19
19
 
20
- if not self.agent and not self.team:
21
- raise ValueError("Whatsapp requires an agent and a team")
20
+ if not (self.agent or self.team):
21
+ raise ValueError("Whatsapp requires an agent or a team")
22
22
 
23
23
  def get_router(self, **kwargs) -> APIRouter:
24
24
  # Cannot be overridden
agno/os/utils.py CHANGED
@@ -61,6 +61,14 @@ def get_run_input(run_dict: Dict[str, Any], is_workflow_run: bool = False) -> st
61
61
  if message.get("role") == "user":
62
62
  return message.get("content", "")
63
63
 
64
+ # Check the input field directly as final fallback
65
+ if run_dict.get("input") is not None:
66
+ input_value = run_dict.get("input")
67
+ if isinstance(input_value, str):
68
+ return input_value
69
+ else:
70
+ return str(input_value)
71
+
64
72
  if run_dict.get("messages") is not None:
65
73
  for message in run_dict["messages"]:
66
74
  if message.get("role") == "user":
agno/reasoning/default.py CHANGED
@@ -14,6 +14,7 @@ def get_default_reasoning_agent(
14
14
  min_steps: int,
15
15
  max_steps: int,
16
16
  tools: Optional[List[Union[Toolkit, Callable, Function, Dict]]] = None,
17
+ tool_call_limit: Optional[int] = None,
17
18
  use_json_mode: bool = False,
18
19
  telemetry: bool = True,
19
20
  debug_mode: bool = False,
@@ -56,7 +57,7 @@ def get_default_reasoning_agent(
56
57
  - **validate**: When you reach a potential answer, signaling it's ready for validation.
57
58
  - **final_answer**: Only if you have confidently validated the solution.
58
59
  - **reset**: Immediately restart analysis if a critical error or incorrect result is identified.
59
- 6. **Confidence Score**: Provide a numeric confidence score (0.0–1.0) indicating your certainty in the steps correctness and its outcome.
60
+ 6. **Confidence Score**: Provide a numeric confidence score (0.0–1.0) indicating your certainty in the step's correctness and its outcome.
60
61
 
61
62
  Step 5 - Validation (mandatory before finalizing an answer):
62
63
  - Explicitly validate your solution by:
@@ -82,6 +83,7 @@ def get_default_reasoning_agent(
82
83
  - Only create a single instance of ReasoningSteps for your response.\
83
84
  """),
84
85
  tools=tools,
86
+ tool_call_limit=tool_call_limit,
85
87
  output_schema=ReasoningSteps,
86
88
  use_json_mode=use_json_mode,
87
89
  telemetry=telemetry,
agno/session/agent.py CHANGED
@@ -57,8 +57,9 @@ class AgentSession:
57
57
  return None
58
58
 
59
59
  runs = data.get("runs")
60
+ serialized_runs: List[RunOutput] = []
60
61
  if runs is not None and isinstance(runs[0], dict):
61
- runs = [RunOutput.from_dict(run) for run in runs]
62
+ serialized_runs = [RunOutput.from_dict(run) for run in runs]
62
63
 
63
64
  summary = data.get("summary")
64
65
  if summary is not None and isinstance(summary, dict):
@@ -77,7 +78,7 @@ class AgentSession:
77
78
  metadata=metadata,
78
79
  created_at=data.get("created_at"),
79
80
  updated_at=data.get("updated_at"),
80
- runs=runs,
81
+ runs=serialized_runs,
81
82
  summary=summary,
82
83
  )
83
84
 
@@ -151,12 +152,14 @@ class AgentSession:
151
152
  continue
152
153
 
153
154
  for message in run_response.messages or []:
154
- # Skip messages with specified role
155
- if skip_role and message.role == skip_role:
156
- continue
157
155
  # Skip messages that were tagged as history in previous runs
158
156
  if hasattr(message, "from_history") and message.from_history and skip_history_messages:
159
157
  continue
158
+
159
+ # Skip messages with specified role
160
+ if skip_role and message.role == skip_role:
161
+ continue
162
+
160
163
  if message.role == "system":
161
164
  # Only add the system message once
162
165
  if system_message is None:
agno/session/team.py CHANGED
@@ -54,16 +54,18 @@ class TeamSession:
54
54
  log_warning("TeamSession is missing session_id")
55
55
  return None
56
56
 
57
- if data.get("summary") is not None:
57
+ summary = data.get("summary")
58
+ if summary is not None and isinstance(summary, dict):
58
59
  data["summary"] = SessionSummary.from_dict(data["summary"]) # type: ignore
59
60
 
60
- runs = data.get("runs", [])
61
+ runs = data.get("runs")
61
62
  serialized_runs: List[Union[TeamRunOutput, RunOutput]] = []
62
- for run in runs:
63
- if "agent_id" in run:
64
- serialized_runs.append(RunOutput.from_dict(run))
65
- elif "team_id" in run:
66
- serialized_runs.append(TeamRunOutput.from_dict(run))
63
+ if runs is not None and isinstance(runs[0], dict):
64
+ for run in runs:
65
+ if "agent_id" in run:
66
+ serialized_runs.append(RunOutput.from_dict(run))
67
+ elif "team_id" in run:
68
+ serialized_runs.append(TeamRunOutput.from_dict(run))
67
69
 
68
70
  return cls(
69
71
  session_id=data.get("session_id"), # type: ignore
@@ -160,12 +162,14 @@ class TeamSession:
160
162
  continue
161
163
 
162
164
  for message in run_response.messages or []:
163
- # Skip messages with specified role
164
- if skip_role and message.role == skip_role:
165
- continue
166
165
  # Skip messages that were tagged as history in previous runs
167
166
  if hasattr(message, "from_history") and message.from_history and skip_history_messages:
168
167
  continue
168
+
169
+ # Skip messages with specified role
170
+ if skip_role and message.role == skip_role:
171
+ continue
172
+
169
173
  if message.role == "system":
170
174
  # Only add the system message once
171
175
  if system_message is None: