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

chore: Add tool rules example #1998

Merged
merged 21 commits into from
Nov 7, 2024
Merged

chore: Add tool rules example #1998

merged 21 commits into from
Nov 7, 2024

Conversation

mattzh72
Copy link
Collaborator

@mattzh72 mattzh72 commented Nov 7, 2024

Add tool rules example. Ran it successfully e2e:

(base) (letta-py3.12) mattzhou@Matts-MacBook-Pro MemGPT % poetry run python /Users/mattzhou/MemGPT/examples/tool_rule_usage.py
Initializing database...
Deleted agent: a407bebb-bd5c-5bcb-8c8d-1416385c76f3 with ID agent-2ab5503a-8b5f-481b-a62f-6c61c1b50192
/Users/mattzhou/MemGPT/letta/agent.py:251: UserWarning: Tool rules only work reliably for the latest OpenAI models that support structured outputs.
  warnings.warn("Tool rules only work reliably for the latest OpenAI models that support structured outputs.")
Got successful response from client: 

{
    "messages": [
        {
            "id": "message-f79a7a49-b5e6-4f11-a4e5-2a4d0b2add0f",
            "date": "2024-11-07T01:09:41+00:00",
            "message_type": "internal_monologue",
            "internal_monologue": "I should retrieve the first secret word to help find the fourth."
        },
        {
            "id": "message-f79a7a49-b5e6-4f11-a4e5-2a4d0b2add0f",
            "date": "2024-11-07T01:09:41+00:00",
            "message_type": "function_call",
            "function_call": {
                "name": "first_secret_word",
                "arguments": "{\n  \"request_heartbeat\": true\n}",
                "function_call_id": "call_wvQH1XPE7sL0RQyY6S1Rs2pH"
            }
        },
        {
            "id": "message-3e717a69-749b-425f-b6fc-d5c842595115",
            "date": "2024-11-07T01:09:41+00:00",
            "message_type": "function_return",
            "function_return": "{\n  \"status\": \"OK\",\n  \"message\": \"v0iq020i0g\",\n  \"time\": \"2024-11-06 05:09:41 PM PST-0800\"\n}",
            "status": "success",
            "function_call_id": "call_wvQH1XPE7sL0RQyY6S1Rs2pH"
        },
        {
            "id": "message-2554a4cd-b0aa-4aa6-9ea4-e300856dc442",
            "date": "2024-11-07T01:09:43+00:00",
            "message_type": "internal_monologue",
            "internal_monologue": "Now that I have the first secret word, I should retrieve the second one to continue."
        },
        {
            "id": "message-2554a4cd-b0aa-4aa6-9ea4-e300856dc442",
            "date": "2024-11-07T01:09:43+00:00",
            "message_type": "function_call",
            "function_call": {
                "name": "second_secret_word",
                "arguments": "{\n  \"prev_secret_word\": \"v0iq020i0g\",\n  \"request_heartbeat\": true\n}",
                "function_call_id": "call_xCG1m3D4G98AW9WPRKerPkh9"
            }
        },
        {
            "id": "message-7eae72a2-f210-4d45-9f9f-0643e7638df8",
            "date": "2024-11-07T01:09:43+00:00",
            "message_type": "function_return",
            "function_return": "{\n  \"status\": \"OK\",\n  \"message\": \"4rwp2b4gxq\",\n  \"time\": \"2024-11-06 05:09:43 PM PST-0800\"\n}",
            "status": "success",
            "function_call_id": "call_xCG1m3D4G98AW9WPRKerPkh9"
        },
        {
            "id": "message-76e9d6ba-8540-4fb0-a37a-96521cd5f4ff",
            "date": "2024-11-07T01:09:44+00:00",
            "message_type": "internal_monologue",
            "internal_monologue": "I've obtained the second secret word, \"4rwp2b4gxq\". Time to get the third one."
        },
        {
            "id": "message-76e9d6ba-8540-4fb0-a37a-96521cd5f4ff",
            "date": "2024-11-07T01:09:44+00:00",
            "message_type": "function_call",
            "function_call": {
                "name": "third_secret_word",
                "arguments": "{\n  \"prev_secret_word\": \"4rwp2b4gxq\",\n  \"request_heartbeat\": true\n}",
                "function_call_id": "call_dHeodTZYu2TuWjR6fLOuCXrP"
            }
        },
        {
            "id": "message-5f22a9e2-8e36-4a79-9a44-07c3aa8fac3b",
            "date": "2024-11-07T01:09:44+00:00",
            "message_type": "function_return",
            "function_return": "{\n  \"status\": \"OK\",\n  \"message\": \"hj2hwibbqm\",\n  \"time\": \"2024-11-06 05:09:44 PM PST-0800\"\n}",
            "status": "success",
            "function_call_id": "call_dHeodTZYu2TuWjR6fLOuCXrP"
        },
        {
            "id": "message-8302554d-ca0a-47ba-8c15-f8dad0d8d33f",
            "date": "2024-11-07T01:09:45+00:00",
            "message_type": "internal_monologue",
            "internal_monologue": "With the third secret word \"hj2hwibbqm\" in hand, I should now retrieve the fourth."
        },
        {
            "id": "message-8302554d-ca0a-47ba-8c15-f8dad0d8d33f",
            "date": "2024-11-07T01:09:45+00:00",
            "message_type": "function_call",
            "function_call": {
                "name": "fourth_secret_word",
                "arguments": "{\n  \"prev_secret_word\": \"hj2hwibbqm\",\n  \"request_heartbeat\": true\n}",
                "function_call_id": "call_AoLCFuWGjS2WHwxJlU3JVOXy"
            }
        },
        {
            "id": "message-37d9b90f-2158-4357-a62e-c664bb1b6de0",
            "date": "2024-11-07T01:09:45+00:00",
            "message_type": "function_return",
            "function_return": "{\n  \"status\": \"OK\",\n  \"message\": \"banana\",\n  \"time\": \"2024-11-06 05:09:45 PM PST-0800\"\n}",
            "status": "success",
            "function_call_id": "call_AoLCFuWGjS2WHwxJlU3JVOXy"
        },
        {
            "id": "message-14437a25-1579-4970-bb0d-0a6e7afd0f4b",
            "date": "2024-11-07T01:09:46+00:00",
            "message_type": "internal_monologue",
            "internal_monologue": "Now that I've found the fourth secret word, I should tell them the answer."
        },
        {
            "id": "message-14437a25-1579-4970-bb0d-0a6e7afd0f4b",
            "date": "2024-11-07T01:09:46+00:00",
            "message_type": "function_call",
            "function_call": {
                "name": "send_message",
                "arguments": "{\n  \"message\": \"The fourth secret word is \\\"banana\\\". 🍌 Quite an interesting journey through the secrets, isn't it?\"\n}",
                "function_call_id": "call_CB6SdMabWZOFuhOgf8QsNct5"
            }
        },
        {
            "id": "message-b2d343e4-ed66-4d6e-8375-c883b6b40171",
            "date": "2024-11-07T01:09:46+00:00",
            "message_type": "function_return",
            "function_return": "{\n  \"status\": \"OK\",\n  \"message\": \"None\",\n  \"time\": \"2024-11-06 05:09:46 PM PST-0800\"\n}",
            "status": "success",
            "function_call_id": "call_CB6SdMabWZOFuhOgf8QsNct5"
        }
    ],
    "usage": {
        "completion_tokens": 259,
        "prompt_tokens": 10189,
        "total_tokens": 10448,
        "step_count": 5
    }
}
Deleted agent: a407bebb-bd5c-5bcb-8c8d-1416385c76f3 with ID agent-ac772e4d-ebb5-4809-a719-1f84822330c4

@sarahwooders sarahwooders merged commit d9d53db into main Nov 7, 2024
21 checks passed
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

Successfully merging this pull request may close these issues.

2 participants