llm-edge / hal-9100

Edge full-stack LLM platform. Written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tool_calls include calls from other assistants/threads

CakeCrusher opened this issue · comments

This tool_calls can include tool calls to functions that are not present in the current assistant:

GETTING RUN:  {
    "id": "aae9c006-8c73-4ce4-8ada-fcf1c550b31b",
    "assistant_id": "8b28757e-ddd8-4229-8141-25ae4c891455",
    "cancelled_at": null,
    "completed_at": null,
    "created_at": 1704260862,
    "expires_at": null,
    "failed_at": null,
    "file_ids": [],
    "instructions": "You are an assistant with the ability to use APIs by first using tools available to you.",
    "last_error": null,
    "metadata": {},
    "model": "",
    "object": "",
    "required_action": {
        "submit_tool_outputs": {
            "tool_calls": [
                {
                    "id": "ff9dfc0c-5e3d-451a-81cb-8a18ea8b50f5",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "18358ef6-bbac-4836-90c8-a291abc61f3f",
                    "function": {
                        "arguments": "{\"query\":\"cat\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "4dc1d2b2-fa14-4e77-9586-5278edb3d310",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                }
            ]
        },
        "type": "submit_tool_outputs"
    },
    "started_at": null,
    "status": "requires_action",
    "thread_id": "d39d6ffa-f651-4998-8a03-f20dedb4ffed",
    "tools": []
}

@CakeCrusher thanks! I pushed a fix let me know if it happens again

@louis030195 Although I have not seen it with multiple different (different config) assistants, it is aggregating tool_calls from previous assistants (for what its worth, different assistants with the same config)
TLDR: ran the same code twice (which instantiates a brand new assistant), each time the number of calls increases (used to be 12 now 15).
High level code

with open("example_openapi.json", "r") as f:
    openapi = json.load(f)
o_to_f = OpenapiToFunction(openapi_spec=openapi)
tools = [fcs.to_json_tool() for fcs in o_to_f.build_function_signatures()]
request_builders = o_to_f.build_request_builders()
assistant = create_assistant(tools)
thread = create_thread()
create_message(thread.id, "Show me one gif of a dog")
run = create_run(thread.id, assistant.id)
while True:
    run = get_run(thread.id, run.id)
    if run.status == "requires_action":
        print("RUN: ", model_to_json_str(run))
        print("len run tool_calls", len(run.required_action.submit_tool_outputs.tool_calls))
        tool_calls = run.required_action.submit_tool_outputs.tool_calls
        submit_tool_outputs(thread.id, run.id, tool_calls, request_builders)
        break
    print("WAITING FOR RUN TO REQUIRE ACTION...")
    time.sleep(1)
    
while True:
    messages = get_messages(thread.id)
    if any(message.role == 'assistant' for message in messages.data):
        print("MESSAGES: ", model_to_json_str(messages))
        break
    print("WAITING FOR ASSISTANT TO RESPOND...")
    time.sleep(1)
get_messages(thread.id, True)

Output (previous run tool call length was 12, now its 15)

WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
WAITING FOR RUN TO REQUIRE ACTION...
RUN:  {
    "id": "431c9ad1-c81e-485a-8c4a-ac4c6a2ff827",
    "assistant_id": "eb0d097f-b06f-4349-91de-650a4bc25041",
    "cancelled_at": null,
    "completed_at": null,
    "created_at": 1704341862,
    "expires_at": null,
    "failed_at": null,
    "file_ids": [],
    "instructions": "You are an assistant with the ability to use APIs by first using tools available to you.",
    "last_error": null,
    "metadata": {},
    "model": "",
    "object": "",
    "required_action": {
        "submit_tool_outputs": {
            "tool_calls": [
                {
                    "id": "10ab3296-9b04-4704-80a5-120a03916413",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "4cece4b5-58e2-42b9-8ea2-2e55aa1fdc29",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                },
                {
                    "id": "4e274e2b-9497-4f13-8337-2b262ff82aaa",
                    "function": {
                        "arguments": "{\"query\":\"dog\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "d2475023-d06b-4ed1-bd99-60eb8dcb129a",
                    "function": {
                        "arguments": "{\"query\":\"dog\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "95bcea3a-7b7d-4e05-92ee-b5ee93901308",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                },
                {
                    "id": "c42cffef-c519-45d6-bb49-a8a79516a16a",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "c5e9d0a6-b960-40ca-8b0c-60a72ae6f108",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                },
                {
                    "id": "fe186a3c-9ae7-43ae-be4a-1573705ac8da",
                    "function": {
                        "arguments": "{\"query\":\"dog\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "dcdb7b89-5da9-4519-8abb-a8aa10996317",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "4a5b3867-e354-4aea-b932-e835e125ca3c",
                    "function": {
                        "arguments": "{\"query\":\"dog\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "3c9b7095-1f6e-4d09-9878-6185d6e4a907",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "925302cb-0de8-40db-921f-2af37c30f314",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                },
                {
                    "id": "001ad2a5-f6b5-4550-96af-f2772f1c88ce",
                    "function": {
                        "arguments": "{\"query\":\"dog\"}",
                        "name": "getSearchResults"
                    },
                    "type": "function"
                },
                {
                    "id": "63116192-37ea-44cb-b4a8-f305fb02bf1e",
                    "function": {
                        "arguments": "{}",
                        "name": "root_healthcheck_get"
                    },
                    "type": "function"
                },
                {
                    "id": "6f1fb4b5-9daf-41a5-a63a-a96ba57246b7",
                    "function": {
                        "arguments": "{}",
                        "name": "getTrendingResults"
                    },
                    "type": "function"
                }
            ]
        },
        "type": "submit_tool_outputs"
    },
    "started_at": null,
    "status": "requires_action",
    "thread_id": "4371717f-2f84-4e32-9cdb-d9567be9ea86",
    "tools": []
}
len run tool_calls 15
WAITING FOR ASSISTANT TO RESPOND...
WAITING FOR ASSISTANT TO RESPOND...
MESSAGES:  {
    "data": [
        {
            "id": "6493bc72-35fc-4e6a-87e1-bcee8785e6e7",
            "assistant_id": "00000000-0000-0000-0000-000000000000",
            "content": [
                {
                    "text": {
                        "annotations": [],
                        "value": "Show me one gif of a dog"
                    },
                    "type": "text"
                }
            ],
            "created_at": 1704341862,
            "file_ids": [],
            "metadata": null,
            "object": "",
            "role": "user",
            "run_id": "00000000-0000-0000-0000-000000000000",
            "thread_id": "4371717f-2f84-4e32-9cdb-d9567be9ea86"
        },
        {
            "id": "ba7347c6-8869-4849-9407-82141d055549",
            "assistant_id": "00000000-0000-0000-0000-000000000000",
            "content": [
                {
                    "text": {
                        "annotations": [],
                        "value": "Understood. How can I assist you today?"
                    },
                    "type": "text"
                }
            ],
            "created_at": 1704341889,
            "file_ids": [],
            "metadata": null,
            "object": "",
            "role": "assistant",
            "run_id": "00000000-0000-0000-0000-000000000000",
            "thread_id": "4371717f-2f84-4e32-9cdb-d9567be9ea86"
        }
    ],
    "object": "list",
    "first_id": "6493bc72-35fc-4e6a-87e1-bcee8785e6e7",
    "last_id": "ba7347c6-8869-4849-9407-82141d055549",
    "has_more": false
}
GETTING MESSAGES:  {
    "data": [
        {
            "id": "6493bc72-35fc-4e6a-87e1-bcee8785e6e7",
            "assistant_id": "00000000-0000-0000-0000-000000000000",
            "content": [
                {
                    "text": {
                        "annotations": [],
                        "value": "Show me one gif of a dog"
                    },
                    "type": "text"
                }
            ],
            "created_at": 1704341862,
            "file_ids": [],
            "metadata": null,
            "object": "",
            "role": "user",
            "run_id": "00000000-0000-0000-0000-000000000000",
            "thread_id": "4371717f-2f84-4e32-9cdb-d9567be9ea86"
        },
        {
            "id": "ba7347c6-8869-4849-9407-82141d055549",
            "assistant_id": "00000000-0000-0000-0000-000000000000",
            "content": [
                {
                    "text": {
                        "annotations": [],
                        "value": "Understood. How can I assist you today?"
                    },
                    "type": "text"
                }
            ],
            "created_at": 1704341889,
            "file_ids": [],
            "metadata": null,
            "object": "",
            "role": "assistant",
            "run_id": "00000000-0000-0000-0000-000000000000",
            "thread_id": "4371717f-2f84-4e32-9cdb-d9567be9ea86"
        }
    ],
    "object": "list",
    "first_id": "6493bc72-35fc-4e6a-87e1-bcee8785e6e7",
    "last_id": "ba7347c6-8869-4849-9407-82141d055549",
    "has_more": false
}

@CakeCrusher I'm not sure to understand the use case

You seem to add multiples time the function output, shouldn't be possible I guess. Should see how it behave on OpenAI API. My bet is that it would either return 400 or update the tool call?