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

Failure executing a tool with Letta pypi server 0.6.12 #2371

Open
kaihuchen opened this issue Jan 21, 2025 · 3 comments
Open

Failure executing a tool with Letta pypi server 0.6.12 #2371

kaihuchen opened this issue Jan 21, 2025 · 3 comments

Comments

@kaihuchen
Copy link

I am having problem getting an agent to execute a tool properly. The Letta server is executed from Windows command line with the 0.6.12 release.

Here is the code for my python client, which simply copies the roll-dice tool from the quick-start guide:

from letta import create_client, agent, EmbeddingConfig, LLMConfig
client = create_client()
def roll_dice_20() -> str:
    """
    Simulate the roll of a 20-sided die (d20).
    This function generates a random integer between 1 and 20, inclusive,
    which represents the outcome of a single roll of a d20.
    Returns:
        str: The result of the die roll.
    """
    import random
    dice_role_outcome = random.randint(1, 20)
    output_string = f"You rolled a {dice_role_outcome}"
    return output_string

def create_agent(client):
    try:
        tool = client.create_tool(
            func=roll_dice_20,
            name = 'rd20f',
        )
        print(f"...Created tool {tool.name}")
        agent = client.create_agent(
            tool_ids=[tool.id]
        )
        return agent
    except Exception as e:
        print(f"Error creating agent: {e}")
        return None

client.set_default_llm_config(LLMConfig.default_config(model_name="gpt-4"))
client.set_default_embedding_config(EmbeddingConfig.default_config(model_name="text-embedding-ada-002"))
agent = create_agent(client)

After opening up this newly created agent in ADE, the dialog goes as follows:

User: roll dice
Agent: It looks like the dice game isn't working at the moment. How about we chat instead? Do you have any burning questions that you've been pondering over recently?

When searching for this newly created tool in the ADE, it does appear in the "All tools" list.

Letta Config

Here is my ~/.letta/config file:

[defaults]
preset = memgpt_chat
persona = sam_pov
human = basic

[archival_storage]
type = sqlite
path = C:\Users\kaihu\.letta

[recall_storage]
type = sqlite
path = C:\Users\kaihu\.letta

[metadata_storage]
type = sqlite
path = C:\Users\kaihu\.letta

[version]
letta_version = 0.6.12
@mattzh72
Copy link
Collaborator

Interesting...can you go to the debug mode in the ADE and show me what the error with the tool is?

Image

@kaihuchen
Copy link
Author

kaihuchen commented Jan 21, 2025

Here you go:

Image

Image

@kaihuchen
Copy link
Author

I think I figured it out.

Seems that the argument 'name' is the source of the problem.

The following call executed with no error, but the agent can't find the roll_dice_20 function. In addition, if I call it more than one then I get SQL error since name is an unique key in the DB. If I keep changing the name to avoid the SQL unique key error, then I ended up with many copies of the function in the DB.

tool = client.create_tool(
    func=roll_dice_20,
    name='rd20g')

With the following, roll_dict_20 gets called in ADE without problem, but the call can be made only once for the same reason as above, so I got problem if I am updating my code for some reason.

tool = client.create_tool(
    func=roll_dice_20)

The following seems to be the best practice, where I don't get the SQL unique key exception, and I don't end up with many copies of the function in the DB in different names, and it also works fine in ADE.

tool = client.create_or_update_tool(
        func=roll_dice_20)

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

No branches or pull requests

2 participants