Skip to content

Commit

Permalink
developing session and thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcstrange committed Jan 19, 2024
1 parent ca8a9c9 commit 0e7d1bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions agency_swarm/sessions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, caller_agent: Literal[Agent, User], recipient_agent: Agent):
self.client = get_openai_client()
if not self.caller_thread:
self.caller_thread = Thread()
self.caller_thread.session = self

def get_completion(self,
message:str,
Expand Down Expand Up @@ -58,11 +57,13 @@ def get_completion(self,
msg.cprint()
except StopIteration as e:
pass
# # 当会话超时,不能释放Thread对象
# print(f"@@@@ DEBUG: Block Here!!{e.value}")
# # while True:
# time.sleep(5)
# # TODO:check是否recipient thread有更新消息
except Exception as e: # 当会话超时,不能释放Thread对象
print(f"Exception{inspect.currentframe().f_code.co_name}{str(e)}")
raise e

# 成功得到recipient回复后
recipient.status = ThreadStatus.Ready
Expand Down Expand Up @@ -125,12 +126,15 @@ def _get_completion_from_thread(self, recipien_thread: Thread, message: str, mes
if inspect.isgenerator(output):
try:
while True:
item = next(output)
item = next(output) # 可能会抛出超时异常(Error Code: 400)
if isinstance(item, MessageOutput) and yield_messages:
yield item
except StopIteration as e:
output = e.value
print(output)
except Exception as e:
print(f"Exception{inspect.currentframe().f_code.co_name}{str(e)}")
raise e
else:
if yield_messages:
yield MessageOutput("function_output", tool_call.function.name, self.recipient_agent.name,
Expand Down Expand Up @@ -176,7 +180,8 @@ def _is_topic_related(self, recipient_thread: Thread, topic: str) -> bool:
# Example usage within this file
if __name__ == "__main__":
from agency_swarm import set_openai_key
set_openai_key("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")
from getpass import getpass
set_openai_key(getpass("Please enter your openai key: "))

agent1 = Agent(name="agent1",
tools=None,
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion agency_swarm/threads/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ThreadProperty(Enum):
class Thread:
thread_id: str = None
openai_thread = None
session = None
assistant_id: str = None
instruction: str = None
topic: str = None
Expand Down

0 comments on commit 0e7d1bf

Please sign in to comment.