messages = [ ( "system", "You are a helpful assistant with access to real-time web information.", ), ("human", "What are the latest developments in AI?"),]ai_msg = llm.invoke(messages)ai_msg
Copy
AIMessage(content='Here\'s a summary of the latest AI news and breakthroughs as of ...', additional_kwargs={}, response_metadata={'model': 'speed', 'finish_reason': 'stop', 'created': 1764043410}, id='run--3866fa98-6ac9-4585-8d23-99c5542b582b-0')
Copy
print(ai_msg.content)
Copy
Here's a summary of the latest AI news and breakthroughs as of...
from langchain_core.prompts import ChatPromptTemplateprompt = ChatPromptTemplate( [ ( "system", "You are a helpful research assistant with access to real-time web information. " "Provide comprehensive answers about {topic} with current data.", ), ("human", "{question}"), ])chain = prompt | llmchain.invoke( { "topic": "artificial intelligence", "question": "What are the most significant AI breakthroughs in 2025?", })
Copy
AIMessage(content="Based on the provided search results, here's a summary of the significant AI breakthroughs and trends...", additional_kwargs={}, response_metadata={'model': 'speed', 'finish_reason': 'stop', 'created': 1764043419}, id='run--9c521362-6724-4299-9e65-0565ec13d997-0')
from langchain.messages import HumanMessage, SystemMessage# 这些连续的 system 消息将被自动合并messages = [ SystemMessage("You are a helpful assistant."), SystemMessage("Always be polite and concise."), HumanMessage("What is the weather like today?")]# 在 API 调用前自动合并为单个 system 消息response = llm.invoke(messages)