diff --git a/agency_swarm/threads/thread.py b/agency_swarm/threads/thread.py index e372df26..2ce95fac 100644 --- a/agency_swarm/threads/thread.py +++ b/agency_swarm/threads/thread.py @@ -1,6 +1,7 @@ import asyncio import inspect import json +import logging import os import re import time @@ -18,6 +19,8 @@ from agency_swarm.util.oai import get_openai_client from agency_swarm.util.streaming import AgencyEventHandler +logger = logging.getLogger(__name__) + class Thread: async_mode: str = None @@ -544,7 +547,11 @@ def _submit_tool_outputs(self, tool_outputs, event_handler=None, poll=True): self._run = stream.get_final_run() def _cancel_run(self, thread_id=None, run_id=None, check_status=True): - if check_status and self._run.status in self.terminal_states and not run_id: + if ( + check_status + and (not self._run or self._run.status in self.terminal_states) + and not run_id + ): return try: @@ -697,6 +704,7 @@ def _await_coroutines(self, tool_outputs): def _get_sync_async_tool_calls(self, tool_calls, recipient_agent): async_tool_calls = [] sync_tool_calls = [] + for tool_call in tool_calls: if tool_call.function.name.startswith("SendMessage"): sync_tool_calls.append(tool_call) @@ -711,6 +719,12 @@ def _get_sync_async_tool_calls(self, tool_calls, recipient_agent): None, ) + if tool is None: + logger.warning( + f"Tool {tool_call.function.name} not found in agent {recipient_agent.name}. Skipping." + ) + continue + if ( hasattr(tool.ToolConfig, "async_mode") and tool.ToolConfig.async_mode ) or self.async_mode == "tools_threading": diff --git a/setup.py b/setup.py index dd2b47c7..dde87fc0 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="agency-swarm", - version="0.4.3", + version="0.4.4", author="VRSEN", author_email="me@vrsen.ai", description="An opensource agent orchestration framework built on top of the latest OpenAI Assistants API.",