# agents/agent_helpers.py def format_history_for_prompt(chat_history: list = None) -> str: """Formats the chat history list into a string for the AI prompt.""" if not chat_history: return "" history_for_prompt = "" for turn in chat_history: # Ensure 'parts' is a list and not empty before accessing if turn.get('parts') and isinstance(turn.get('parts'), list): role = "User" if turn['role'] == 'user' else "AI" history_for_prompt += f"{role}: {turn['parts'][0]}\n" return history_for_prompt