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.

fix: Fix composio bugs (#884)

Matthew Zhou85dee1785b12
diff --git a/letta/local_llm/utils.py b/letta/local_llm/utils.py
index f5d541740..21be45c5c 100644
--- a/letta/local_llm/utils.py
+++ b/letta/local_llm/utils.py
@@ -11,8 +11,11 @@ import letta.local_llm.llm_chat_completion_wrappers.configurable_wrapper as conf
import letta.local_llm.llm_chat_completion_wrappers.dolphin as dolphin
import letta.local_llm.llm_chat_completion_wrappers.llama3 as llama3
import letta.local_llm.llm_chat_completion_wrappers.zephyr as zephyr
+from letta.log import get_logger
from letta.schemas.openai.chat_completion_request import Tool, ToolCall
+logger = get_logger(__name__)
+
def post_json_auth_request(uri, json_payload, auth_type, auth_key):
"""Send a POST request with a JSON payload and optional authentication"""
@@ -126,8 +129,11 @@ def num_tokens_from_functions(functions: List[dict], model: str = "gpt-4"):
function_tokens += 2
if isinstance(v["items"], dict) and "type" in v["items"]:
function_tokens += len(encoding.encode(v["items"]["type"]))
+ elif field == "default":
+ function_tokens += 2
+ function_tokens += len(encoding.encode(str(v["default"])))
else:
- warnings.warn(f"num_tokens_from_functions: Unsupported field {field} in function {function}")
+ logger.warning(f"num_tokens_from_functions: Unsupported field {field} in function {function}")
function_tokens += 11
num_tokens += function_tokens
diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.py
index 27188f932..211b3e33f 100644
--- a/letta/services/tool_manager.py
+++ b/letta/services/tool_manager.py
@@ -58,11 +58,15 @@ class ToolManager:
@enforce_types
def create_or_update_composio_tool(self, tool_create: ToolCreate, actor: PydanticUser) -> PydanticTool:
- return self.create_or_update_tool(PydanticTool(tool_type=ToolType.EXTERNAL_COMPOSIO, **tool_create.model_dump()), actor)
+ return self.create_or_update_tool(
+ PydanticTool(tool_type=ToolType.EXTERNAL_COMPOSIO, name=tool_create.json_schema["name"], **tool_create.model_dump()), actor
+ )
@enforce_types
def create_or_update_langchain_tool(self, tool_create: ToolCreate, actor: PydanticUser) -> PydanticTool:
- return self.create_or_update_tool(PydanticTool(tool_type=ToolType.EXTERNAL_LANGCHAIN, **tool_create.model_dump()), actor)
+ return self.create_or_update_tool(
+ PydanticTool(tool_type=ToolType.EXTERNAL_LANGCHAIN, name=tool_create.json_schema["name"], **tool_create.model_dump()), actor
+ )
@enforce_types
def create_tool(self, pydantic_tool: PydanticTool, actor: PydanticUser) -> PydanticTool: