Skip to content

Commit 4871024

Browse files
ltwlfclaudemoonbox3
authored
Python: Fix AttributeError in ResponsesAgentThreadActions._get_tool_calls_from_output (#12301)
## Summary Fixes AttributeError: 'ResponseOutputMessage' object has no attribute 'call_id' in `ResponsesAgentThreadActions._get_tool_calls_from_output` - Updated type annotation from `list[ResponseFunctionToolCall]` to `list[ResponseOutputItem < /dev/null | ResponseOutputMessage]` to accurately reflect actual input types - Improved filtering to only process `ResponseFunctionToolCall` objects, safely ignoring other types like `ResponseOutputMessage` - Removed problematic `.delta` access and dangerous cast operations that caused the AttributeError ## Test plan - [x] All existing OpenAI responses agent tests pass (34/34) - [x] Ruff formatting and linting passes - [x] Pre-commit hooks pass Fixes #12296 Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
1 parent 82229ce commit 4871024

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -723,22 +723,24 @@ def _prepare_chat_history_for_request(
723723
return response_inputs
724724

725725
@classmethod
726-
def _get_tool_calls_from_output(cls: type[_T], output: list[ResponseFunctionToolCall]) -> list[FunctionCallContent]:
726+
def _get_tool_calls_from_output(
727+
cls: type[_T], output: list[ResponseOutputItem | ResponseOutputMessage]
728+
) -> list[FunctionCallContent]:
727729
"""Get tool calls from a response output."""
728730
function_calls: list[FunctionCallContent] = []
729-
if not any(isinstance(i, ResponseFunctionToolCall) for i in output):
730-
return []
731-
for tool in cast(list[ResponseFunctionToolCall], output):
732-
content = tool if isinstance(tool, ResponseFunctionToolCall) else tool.delta
733-
function_calls.append(
734-
FunctionCallContent(
735-
id=content.id,
736-
call_id=content.call_id,
737-
index=getattr(content, "index", None),
738-
name=content.name,
739-
arguments=content.arguments,
731+
732+
# Filter to only process ResponseFunctionToolCall objects
733+
for item in output:
734+
if isinstance(item, ResponseFunctionToolCall):
735+
function_calls.append(
736+
FunctionCallContent(
737+
id=item.id,
738+
call_id=item.call_id,
739+
index=getattr(item, "index", None),
740+
name=item.name,
741+
arguments=item.arguments,
742+
)
740743
)
741-
)
742744
return function_calls
743745

744746
@classmethod

0 commit comments

Comments
 (0)