用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/vamseeachanta/workspace-hub --skill langchain-3-conversation-memory命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | langchain-3-conversation-memory |
| description | Sub-skill of langchain: 3. Conversation Memory. |
| version | 1.0.0 |
| category | ai-prompting |
| type | reference |
| scripts_exempt | true |
Conversation Buffer Memory:
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_community.chat_message_histories import ChatMessageHistory
from langchain_core.chat_history import BaseChatMessageHistory
# Store for session histories
store = {}
def get_session_history(session_id: str) -> BaseChatMessageHistory:
"""Get or create message history for a session."""
if session_id not in store:
store[session_id] = ChatMessageHistory()
return store[session_id]
def create_conversational_chain():
"""
Create a chain with conversation memory.
"""
llm = ChatOpenAI(model="gpt-4", temperature=0.7)
prompt = ChatPromptTemplate.from_messages([
("system", """You are an expert offshore engineering consultant.
You help with mooring design, vessel dynamics, and marine operations.
Maintain context from previous messages in the conversation."""),
MessagesPlaceholder(variable_name="history"),
("human", "{input}")
])
chain = prompt | llm
# Wrap with message history
chain_with_history = RunnableWithMessageHistory(
chain,
get_session_history,
input_messages_key="input",
history_messages_key="history"
)
return chain_with_history
# Usage
conversational_chain = create_conversational_chain()
# First message
response1 = conversational_chain.invoke(
{"input": "I'm designing a spread mooring system for a 100,000 DWT tanker."},
config={"configurable": {"session_id": "project-123"}}
)
print(f"Assistant: {response1.content}")
# Follow-up (remembers context)
response2 = conversational_chain.invoke(
{"input": "What line configuration would you recommend?"},
config={"configurable": {"session_id": "project-123"}}
)
print(f"Assistant: {response2.content}")
# Check history
history = get_session_history("project-123")
print(f"\nConversation has {len(history.messages)} messages")
Summary Memory for Long Conversations:
from langchain_openai import ChatOpenAI
from langchain.memory import ConversationSummaryBufferMemory
from langchain.chains import ConversationChain
def create_summary_memory_chain():
"""
Create chain with summary memory for long conversations.
Keeps recent messages verbatim, summarizes older ones.
"""
llm = ChatOpenAI(model="gpt-4", temperature=0.7)
# Summary buffer keeps last 1000 tokens verbatim
memory = ConversationSummaryBufferMemory(
llm=llm,
max_token_limit=1000,
return_messages=True
)
chain = ConversationChain(
llm=llm,
memory=memory,
verbose=True
)
return chain, memory
# Usage
chain, memory = create_summary_memory_chain()
# Simulate long conversation
responses = []
questions = [
"What are the main types of mooring systems?",
"Tell me about spread moorings in detail.",
"What about single point moorings?",
"How do turret moorings work?",
"Compare the maintenance requirements.",
"What are the cost implications?"
]
for q in questions:
response = chain.predict(input=q)
responses.append(response)
print(f"Q: {q}")
print(f"A: {response[:200]}...")
print()
# Check memory state
print("Memory Summary:")
print(memory.moving_summary_buffer)
Write outbound email and external messages in Vamsee Achanta's voice — a subtle offer to help, never bold or rash claims. Load before drafting ANY email, LinkedIn/Collide reply, proposal note, or outreach sent under his name.
Save/publish analysis or computation results from ANY ecosystem repo to Hugging Face as a queryable, viewer-renderable dataset. Use when the user wants to "save results to hugging face", "publish dataset to HF", "hugging face data saving", "save analysis results", "hf dataset", "make results queryable", or "render via datasets-server API". Reshapes nested results into flat parquet tables, writes a dataset card with a viewer `configs:` block and provenance, applies license/public-vs-private routing, enforces a domain data-quality gate (faithful-to-source != correct), publishes to `aceengineer/<repo>-<projection>`, and verifies via the datasets-server API.
Clone, create, fork, configure, and manage GitHub repositories. Manage remotes, secrets, releases, and workflows. Works with gh CLI or falls back to git + GitHub REST API via curl.