Assistant API function call error.. Plz help

Issue is when the Assistant API call for further input… processing just stops and function is never called…

query_content_global = ""
query_top_global = ""
additional_param_global = ""

def get_current_query_content(query_content, query_top, additional_param):
    global query_content_global, query_top_global, additional_param_global
    query_content_global = query_content
    query_top_global = query_top
    additional_param_global = additional_param
    return "Your request has been received and is being processed."

from openai import OpenAI
client = OpenAI()

info = (
    "The input which you receive from the user has to be divided into 3 different information criteria:\n\n"
    "1. Article Top Query- You shall interpret the input given by the user and see whether the query requires looking into any specific customer or any specific industry vertical. Intent is to get the filter to be applied on the query from where the data has to be taken.\n\n"
    "2. Article Content Query- You will create a text of what is to be searched from the query which will be used for processing later via doing similarity search on the embedding.\n\n"
    "3. Additional filter- Any additional filter to be applied on query asked like timelines.\n\n"
    "Article Top Query and Article Content Query are mandatory and if you are unable to identify these two parameter in user query, ask them again to get these information out.\n\n"
    "Get final confirmation by saying 'Does this cover everything you need, or is there any other detail or specific timeframe you'd like to include in the analysis.\n\n"
"Once confirmation received, use the function instruction and pass the parameter collected as per programming requirement and in the frontend create the output saying your request will be processed soon.Use the function instruction and pass the parameter collected as per programming requirement and in the frontend create the output saying your request will be processed soon."
)
 
assistant = client.beta.assistants.create(
    instructions=info,
    model="gpt-4-turbo",
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_current_query_content",
                "description": "Get the current query content and additional details for specific user input",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "query_content": {
                            "type": "string",
                            "description": "The content inquired by the user"
                        },
                        "query_top": {
                            "type": "string",
                            "description": "Topic related to the query"
                        },
                        "additional_param": {
                            "type": "string",
                            "description": "Additional parameter related to the query"
                        }
                    },
                    "required": ["query_content", "query_top", "additional_param"]
                }
            }
        }
    ]
)

# Step 2: Create a Thread
thread = client.beta.threads.create()

# Step 3: Add a Message to a Thread
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="Can you please give me right to audit clause from Aetna"
)

# Step 4: Run the Assistant
run = client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id=assistant.id
)

print(run.model_dump_json(indent=4))

while True:
    # Wait for 5 seconds
    time.sleep(5)

    # Retrieve the run status
    run_status = client.beta.threads.runs.retrieve(
        thread_id=thread.id,
        run_id=run.id
    )
    print(run_status.model_dump_json(indent=4))

    # If run is completed, get messages
    if run_status.status == 'completed':
        messages = client.beta.threads.messages.list(
            thread_id=thread.id
        )

        # Loop through messages and print content based on role
        for msg in messages.data:
            role = msg.role
            content = msg.content[0].text.value
            print(f"{role.capitalize()}: {content}")

        break  # This break ensures that once the run is completed, the while loop exits.
    elif run_status.status == 'requires_action':
        print("Function Calling")
        required_actions = run_status.required_action.submit_tool_outputs.model_dump()
        print(required_actions)
        tool_outputs = []
        import json
        for action in required_actions["tool_calls"]:
            func_name = action['function']['name']
            arguments = json.loads(action['function']['arguments'])
            
            if func_name == "get_current_query_content":
                # Extract all required parameters from the arguments JSON
                query_content = arguments['query_content']
                query_top = arguments['query_top']
                additional_param = arguments['additional_param']

                # Call the function with all required parameters
                output = get_current_query_content(query_content=query_content, query_top=query_top, additional_param=additional_param)
                tool_outputs.append({
                    "tool_call_id": action['id'],
                    "output": output
                })
            else:
                raise ValueError(f"Unknown function: {func_name}")
            
        print("Submitting outputs back to the Assistant...")
        client.beta.threads.runs.submit_tool_outputs(
            thread_id=thread.id,
            run_id=run.id,
            tool_outputs=tool_outputs
        )
    else:
        print("Waiting for the Assistant to process...")
        time.sleep(5)  # This time.sleep(5) is correctly placed to delay the next iteration of the loop.

Hi. Can you explain your issue a bit more and give more context please? Don’t expect people to just review your whole code and debug stuff for you.

Sure. Assistant APi is currently given instruction to send 3 parameters as function call. Out of these 3 params, 2 are mandatory and if the user have not given those in first promot, API will ask user for further question once and then pass the info back. Issue i am facing is when the assistant has to follow up. function is not calling back. it works fine if all info givenin first go