Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Tools to Agent Returns errors #1900

Open
NovaBro opened this issue Oct 17, 2024 · 4 comments
Open

Adding Tools to Agent Returns errors #1900

NovaBro opened this issue Oct 17, 2024 · 4 comments

Comments

@NovaBro
Copy link

NovaBro commented Oct 17, 2024

Describe the bug
When following lettas tutorial, letta tutorial, on adding custom tools to letta, I get an error.
Adding tools to the agent throught he online server website also presents weird behavior. i.e. the tool does not run and it removes default tools. It seems that I can either have the default tools OR only my custom tool.

Is there a way to add tools to existing agents?
Where is the html code for the website? i.e. "http://localhost:8283/"

Please describe your setup

  1. I have created a python 3.12 virtual environment

  2. I then did pip install letta

  3. Followed the quickstart guide

  4. macOS 14.6.1, m1 chip,

  5. VSCODE

  6. Running letta though terminal

Here is what happens when I add a tool through python using lettas tutorial on adding custom tools:
(my_letta) (base) williamzheng@WilliamsMBP258 MemGPT_Letta % "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Lett
a/my_letta/bin/python" "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/delete_tool.py"
Initializing database...
Traceback (most recent call last):
File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/delete_tool.py", line 6, in
agent_state = client.create_agent(name="test_agent")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/client/client.py", line 1555, in create_agent
assert embedding_config or self._default_embedding_config, f"Embedding config must be provided"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Embedding config must be provided
(my_letta) (base) williamzheng@WilliamsMBP258 MemGPT_Letta %

Here is when I add a tool through the website.
This is the website I am talking about. Additionally, you can see here that only 1 tool is added, all default tools are removed. I think this prevents letta from returning response.
Screenshot 2024-10-16 at 9 33 21 PM

@sarahwooders
Copy link
Collaborator

Sorry that documentation has an error because of our latest release - you now need to specify the LLMConfig or EmbeddingConfig when creating an agent, or set a default config for the client:

from letta import EmbeddingConfig, LLMConfig

client.set_default_embedding_config(EmbeddingConfig.default_config(provider="openai"))
client.set_default_llm_config(LLMConfig.default_config(model_name="gpt-4"))

Thanks for reporting this issue, and we'll make sure to fix the docs. Let me know if things still aren't working thought!

@NovaBro
Copy link
Author

NovaBro commented Oct 20, 2024

Hello!

Thank you for your response, I tried using the agent I had created through python, however, I am getting an error related to the openai api key. It seems that key is not found. I am not sure where to put my key now that the config file is depreicated?

from letta import create_client 
from letta import EmbeddingConfig, LLMConfig

client = create_client()
client.set_default_embedding_config(EmbeddingConfig.default_config(provider="openai"))
client.set_default_llm_config(LLMConfig.default_config(model_name="gpt-4"))

def query_birthday_db(self, name: str): 
    """
    This tool queries an external database to 
    lookup the birthday of someone given their name.

    Args: 
        name (str): The name to look up 

    Returns: 
        birthday (str): The birthday in mm-dd-yyyy format
    
    """
    my_fake_data = {
        "bob": "03-06-1997", 
        "sarah": "03-06-1997"
    } 
    name = name.lower() 
    if name not in my_fake_data: 
        return None
    else: 
        return my_fake_data[name]

birthday_tool = client.create_tool(query_birthday_db)

agentName = "testing_agent"

agent_1 = client.create_agent(
    name=agentName,
    )

Error message when then using Letta Run:

(my_letta) (base) williamzheng@WilliamsMBP258 MemGPT_Letta % letta run
Initializing database...

? Would you like to select an existing agent? Yes
? Select agent: testing_agent

🔁 Using existing agent testing_agent

Hit enter to begin (will request first Letta message)


An exception occurred when running agent.step(): 
Traceback (most recent call last):
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/main.py", line 413, in run_agent_loop
    new_messages, user_message, skip_next_user_input = process_agent_step(user_message, no_verify)
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/main.py", line 365, in process_agent_step
    step_response = letta_agent.step(
                    ^^^^^^^^^^^^^^^^^
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/agent.py", line 874, in step
    raise e
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/agent.py", line 770, in step
    response = self._get_ai_reply(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/agent.py", line 495, in _get_ai_reply
    raise e
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/agent.py", line 464, in _get_ai_reply
    response = create(
               ^^^^^^^
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/llm_api/llm_api_tools.py", line 101, in wrapper
    raise e
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/llm_api/llm_api_tools.py", line 70, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/williamzheng/Documents/UmichFolder/2025 Fall Semester /Research 499/MemGPT_Letta/my_letta/lib/python3.12/site-packages/letta/llm_api/llm_api_tools.py", line 147, in create
    raise ValueError(f"OpenAI key is missing from letta config file")
ValueError: OpenAI key is missing from letta config file
? Retry agent.step()? (Y/n)

@NovaBro
Copy link
Author

NovaBro commented Oct 20, 2024

I am assuming this issue is appearing from line 127 llm_api_tools.py which has:

    model_settings: Optional[dict] = None,  # TODO: eventually pass from server

moedel_settings is not defined when calling create on line 464 file agent.py:

            response = create(
                # agent_state=self.agent_state,
                llm_config=self.agent_state.llm_config,
                user_id=self.agent_state.user_id,
                messages=message_sequence,
                functions=self.functions,
                functions_python=self.functions_python,
                function_call=function_call,
                # hint
                first_message=first_message,
                # streaming
                stream=stream,
                stream_interface=self.interface,
                # putting inner thoughts in func args or not
                inner_thoughts_in_kwargs_option=inner_thoughts_in_kwargs_option,
            )

@NovaBro
Copy link
Author

NovaBro commented Oct 20, 2024

I am now using the letta free model:

from letta import create_client 
from letta import EmbeddingConfig, LLMConfig

client = create_client()
client.set_default_embedding_config(EmbeddingConfig.default_config(model_name="letta"))
client.set_default_llm_config(LLMConfig.default_config(model_name="letta"))

def query_birthday_db(self, name: str): 
    """
    This tool queries an external database to 
    lookup the birthday of someone given their name.

    Args: 
        name (str): The name to look up 

    Returns: 
        birthday (str): The birthday in mm-dd-yyyy format
    
    """
    my_fake_data = {
        "bob": "03-06-1997", 
        "sarah": "03-06-1997"
    } 
    name = name.lower() 
    if name not in my_fake_data: 
        return None
    else: 
        return my_fake_data[name]

birthday_tool = client.create_tool(query_birthday_db)

But now I wanted to add all tools to my agent,

agentName = "testing_agent"

agent_1 = client.create_agent(
    name=agentName,
    tools=[x.name for x in client.list_tools()]
    )

but there seems to be a different number of tools, 18 vs 10 on the website:

Screenshot 2024-10-20 at 1 25 21 PM Screenshot 2024-10-20 at 1 25 28 PM

Other than this, the letta model is able to use custom tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

2 participants