Skip to content

Commit b84f985

Browse files
fix: improve handoff robustness and fix test import
- Fix callback parameter mismatch handling with proper warnings - Add check for __annotations__ before accessing it - Fix tool_calls filter to check key existence rather than truthiness - Update test import path for HandoffInputData Co-authored-by: Mervin Praison <[email protected]>
1 parent 85c6938 commit b84f985

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/praisonai-agents/praisonaiagents/agent/handoff.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ def handoff_tool(**kwargs):
109109
self.on_handoff()
110110
elif num_params == 1:
111111
self.on_handoff(source_agent)
112-
elif num_params == 2 and self.input_type:
113-
input_data = self.input_type(**kwargs) if kwargs else self.input_type()
114-
self.on_handoff(source_agent, input_data)
112+
elif num_params == 2:
113+
if self.input_type:
114+
input_data = self.input_type(**kwargs) if kwargs else self.input_type()
115+
self.on_handoff(source_agent, input_data)
116+
else:
117+
# Callback expects 2 params but no input_type provided
118+
logger.warning(f"Callback {self.on_handoff.__name__} expects 2 parameters but no input_type was provided")
119+
self.on_handoff(source_agent, None)
115120
else:
116-
# Fallback for other cases, which may raise a TypeError.
121+
# Callback has unexpected number of parameters
122+
logger.warning(f"Callback {self.on_handoff.__name__} has {num_params} parameters, expected 0, 1, or 2")
123+
# Try calling with source_agent only
117124
self.on_handoff(source_agent)
118125

119126
# Prepare handoff data
@@ -164,7 +171,7 @@ def handoff_tool(**kwargs):
164171
handoff_tool.__doc__ = self.tool_description
165172

166173
# Add input type annotations if provided
167-
if self.input_type:
174+
if self.input_type and hasattr(self.input_type, '__annotations__'):
168175
sig_params = []
169176
for field_name, field_type in self.input_type.__annotations__.items():
170177
sig_params.append(
@@ -236,7 +243,7 @@ def remove_all_tools(data: HandoffInputData) -> HandoffInputData:
236243
"""Remove all tool calls from the message history."""
237244
filtered_messages = []
238245
for msg in data.messages:
239-
if isinstance(msg, dict) and (msg.get('tool_calls') or msg.get('role') == 'tool'):
246+
if isinstance(msg, dict) and ('tool_calls' in msg or msg.get('role') == 'tool'):
240247
# Skip messages with tool calls
241248
continue
242249
filtered_messages.append(msg)

src/praisonai-agents/tests/test_handoff_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_mixed_handoffs():
125125

126126
def test_handoff_filters():
127127
"""Test handoff filter functions"""
128-
from praisonaiagents.handoff import HandoffInputData
128+
from praisonaiagents.agent.handoff import HandoffInputData
129129

130130
messages = [
131131
{"role": "system", "content": "System prompt"},

0 commit comments

Comments
 (0)