Skip to content

Commit

Permalink
hotfix for broken sync agent code (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker authored Oct 29, 2023
1 parent e82d323 commit c4b8ec6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion memgpt/agent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
import inspect
import datetime
import pickle
import math
Expand Down Expand Up @@ -154,6 +156,14 @@ async def get_ai_reply_async(
raise e


# Assuming function_to_call is either sync or async
async def call_function(function_to_call, **function_args):
if inspect.iscoroutinefunction(function_to_call):
return await function_to_call(**function_args)
else:
return function_to_call(**function_args)


class Agent(object):
def __init__(
self,
Expand Down Expand Up @@ -814,7 +824,7 @@ async def handle_ai_response(self, response_message):
# Failure case 3: function failed during execution
await self.interface.function_message(f"Running {function_name}({function_args})")
try:
function_response_string = await function_to_call(**function_args)
function_response_string = await call_function(function_to_call, **function_args)
function_response = package_function_response(True, function_response_string)
function_failed = False
except Exception as e:
Expand Down

0 comments on commit c4b8ec6

Please sign in to comment.