try: from livekit.agents.llm import ChatContext, ChatMessage print("Successfully imported livekit.agents.llm") ctx = ChatContext() ctx.add_message(role="user", content="Hello") # Verify 'items' property if hasattr(ctx, 'items'): print(f"ctx.items type: {type(ctx.items)}") print(f"ctx.items content: {ctx.items}") # Try appending to items try: ctx.items.append(ChatMessage(role="system", content="Injected")) print("Successfully appended to ctx.items") print(f"ctx.items content after append: {ctx.items}") except Exception as e: print(f"Failed to append to ctx.items: {e}") # Verify 'insert' method if hasattr(ctx, 'insert'): try: ctx.messages.insert(0, ChatMessage(role="system", content="Inserted")) except AttributeError: print("ctx.messages.insert failed as expected") try: # Try ctx.insert(index, item) ? # Or ctx.items.insert? pass except: pass # Try to verify how to insert at beginning try: # Check if we can do ctx.messages.insert replacement # option 1: ctx.items.insert(0, msg) ctx.items.insert(0, ChatMessage(role="system", content="Inserted at 0")) print("Successfully inserted into ctx.items") except Exception as e: print(f"Failed to insert into ctx.items: {e}") except ImportError: print("Could not import livekit.agents.llm") except Exception as e: print(f"An error occurred: {e}")