Skip to content

Commit

Permalink
Bug fixes in thread.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bonk1t committed Jan 7, 2025
1 parent 1e28824 commit aebfbe7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion agency_swarm/threads/thread.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import inspect
import json
import logging
import os
import re
import time
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand Down

0 comments on commit aebfbe7

Please sign in to comment.