Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

hotfix for broken sync agent code (#171)

Charles Packera9a6a2629a95
diff --git a/memgpt/agent.py b/memgpt/agent.py
index bef024d36..dec854163 100644
--- a/memgpt/agent.py
+++ b/memgpt/agent.py
@@ -1,3 +1,5 @@
+import asyncio
+import inspect
import datetime
import pickle
import math
@@ -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,
@@ -814,7 +824,7 @@ class AgentAsync(Agent):
# 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: