conversational

conversational is an agent for coding agents from xt765/LangChain-Chinese-Comment. It costs 0 tokens per session (803 once invoked), scanned A, original, MIT.

An agent design for conversations that includes earlier messages when deciding what to say or do. It uses a prompt template with separate fields for the user, the AI, and the conversation history.

In plain words
What is it for?
Use it for chat-based agents that need to remember previous messages while answering questions or calling tools.
Why use it?
It prevents the agent from treating every message as a completely new request. Earlier exchanges remain available as context for later replies and tool decisions.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/xt765/langchain-chinese-comment/conversational
Clone the repo
git clone --depth 1 https://github.com/xt765/LangChain-Chinese-Comment

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for conversational

README.md
[![agentmods](https://agentmods.dev/badge/agents/xt765/langchain-chinese-comment/conversational.svg)](https://agentmods.dev/agents/xt765/langchain-chinese-comment/conversational)
Your own site
<a href="https://agentmods.dev/agents/xt765/langchain-chinese-comment/conversational"><img src="https://agentmods.dev/badge/agents/xt765/langchain-chinese-comment/conversational.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 803 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00803
Opus 5 $0.00000 $0.00402
Sonnet 5 $0.00000 $0.00161
Haiku 4.5 $0.00000 $0.00080

Measured 4d ago against content hash 34c1c155d2e7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

conversational scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

code_comment/libs/langchain/langchain_classic/agents/conversational.md · 89 lines

How it starts

The opening of the file, as written. The whole thing — 89 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Conversational Agent

ConversationalAgent 是专为对话场景设计的 Agent。它在 ReAct 范式的基础上,通过引入 chat_history(对话历史)来保持上下文连贯性。

核心功能

与标准的 ZeroShotAgent 不同,ConversationalAgent 的提示词模板包含一个专门用于存储历史对话的变量。这使得 Agent 能够记住之前的交互,而不仅仅是处理单一的请求。

  • chat_history: 存储 Human 和 AI 之间之前的对话内容。
  • ai_prefix / human_prefix: 用于在 Prompt 中标识不同说话者的前缀(默认为 "AI" 和 "Human")。

执行逻辑 (Verbatim Snippet)

提示词结构 (ConversationalAgent.create_prompt)

@classmethod
def create_prompt(
    cls,
    tools: Sequence[BaseTool],
    prefix: str = PREFIX,
    suffix: str = SUFFIX,
    format_instructions: str = FORMAT_INSTRUCTIONS,
    ai_prefix: str = "AI",
    human_prefix: str = "Human",
    input_variables: list[str] | None = None,
) -> PromptTemplate:
    # 1. 渲染工具描述
    tool_strings = "\n".join(
        [f"> {tool.name}: {tool.description}" for tool in tools],
    )
    # 2. 注入对话相关的变量名
    if input_variables is None:
        input_variables = ["input", "chat_history", "agent_scratchpad"]
    
    # 3. 构造模板
    template = f"{prefix}\n\n{tool_strings}\n\n{format_instructions}\n\n{suffix}"
    return PromptTemplate(template=template, input_variables=input_variables)

提示词模板内容

{prefix}
{tool_strings}
{format_instructions}

{chat_history}
Human: {input}
Thought: {agent_scratchpad}

迁移指南 (LangGraph)

在现代 LangChain 中,对话能力通常由 LangGraph 的 State(状态)管理,而不是硬编码在 Prompt 模板中。

经典方式 (initialize_agent)

from langchain.memory import ConversationBufferMemory
from langchain.agents import initialize_agent, AgentType

memory = ConversationBufferMemory(memory_key="chat_history")
agent = initialize_agent(
    tools, 
    llm, 
    agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
    memory=memory,
    verbose=True
)

现代方式 (LangGraph)

from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent

# 使用内存检查点来自动保存对话历史
memory = MemorySaver()
app = create_react_agent(model, tools, checkpointer=memory)

# 运行时提供 thread_id 以识别不同会话
config = {"configurable": {"thread_id": "user-123"}}
app.invoke({"messages": [("user", "My name is Bob")]}, config)
app.invoke({"messages": [("user", "What is my name?")]}, config)

Read the full file on GitHub · 89 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 89 lines · 0 tokens per session scan A 34c1c155d2e7

Subscribe to this mod's changes

conversational is an agent published in the GitHub repository xt765/LangChain-Chinese-Comment (20 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 803 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.