Skip to content

Commit

Permalink
Merge pull request #210 from bonk1t/fix/fix-2-thread-py-bugs
Browse files Browse the repository at this point in the history
Bug fixes in thread.py
  • Loading branch information
bonk1t authored Jan 8, 2025
2 parents b86abc0 + aded34a commit 8bc648e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="agency-swarm",
version="0.4.3",
version="0.4.4",
author="VRSEN",
author_email="[email protected]",
description="An opensource agent orchestration framework built on top of the latest OpenAI Assistants API.",
Expand Down

0 comments on commit 8bc648e

Please sign in to comment.