def post_message()

in AI_Agent_Service/CustomAIAgent.py [0:0]


    def post_message(self, message: str):
        message = self._project_client.agents.create_message(
            thread_id=self._thread_id,
            role="user",
            content=message,
        )
        #print("post_message: Agent Threadid: ", self._thread_id)
        run = self._project_client.agents.create_and_process_run(thread_id=self._thread_id, 
                                                                 assistant_id=self._agent_instance.id,
                                                                 max_completion_tokens=200,
                                                                 max_prompt_tokens=4000
                                                                 ) 
        if run.status == "failed":
            # Check if you got "Rate limit is exceeded.", then you want to get more quota
            print(f"Run failed: {run.last_error}")

        messages = self._project_client.agents.list_messages(thread_id=self._thread_id)
        last_msg = messages.get_last_text_message_by_role("assistant")
        if last_msg:
            #print(f"Agent id:{self._agent_instance.id} - Last Message: {last_msg.text.value}")
            return last_msg.text.value
        else:
            return None