ConversationalChatAgent Class — langchain Architecture
Architecture documentation for the ConversationalChatAgent class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 37dfdb3a_fc75_8e43_a082_e000915175c2["ConversationalChatAgent"] 37fcc3f3_2798_3648_915c_2bffdd19bff7["Agent"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|extends| 37fcc3f3_2798_3648_915c_2bffdd19bff7 13cdba7d_c4a4_edb6_521f_09c39f95cf58["base.py"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|defined in| 13cdba7d_c4a4_edb6_521f_09c39f95cf58 5e0d227f_9765_818c_3c02_743fc1bc0c86["_get_default_output_parser()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 5e0d227f_9765_818c_3c02_743fc1bc0c86 00ca2fb7_cdfd_af44_4ed6_3ce8b4278290["_agent_type()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 00ca2fb7_cdfd_af44_4ed6_3ce8b4278290 feb1728c_6b31_023b_2cde_af5cdf93de3c["observation_prefix()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| feb1728c_6b31_023b_2cde_af5cdf93de3c 750ee5bd_8767_0a1d_24d7_62ec922493ff["llm_prefix()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 750ee5bd_8767_0a1d_24d7_62ec922493ff 37ebc42f_11ae_0dcf_a66a_08e26fb475df["_validate_tools()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 37ebc42f_11ae_0dcf_a66a_08e26fb475df a6206bc9_89e6_ac37_3164_590e3974b4f6["create_prompt()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| a6206bc9_89e6_ac37_3164_590e3974b4f6 3a5094fa_f1ec_4d12_ae46_7af52ecae3e1["_construct_scratchpad()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 3a5094fa_f1ec_4d12_ae46_7af52ecae3e1 792d39b0_6cc6_56c1_0b6c_cc11d6f11d45["from_llm_and_tools()"] 37dfdb3a_fc75_8e43_a082_e000915175c2 -->|method| 792d39b0_6cc6_56c1_0b6c_cc11d6f11d45
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/conversational_chat/base.py lines 37–181
class ConversationalChatAgent(Agent):
"""An agent designed to hold a conversation in addition to using tools."""
output_parser: AgentOutputParser = Field(default_factory=ConvoOutputParser)
"""Output parser for the agent."""
template_tool_response: str = TEMPLATE_TOOL_RESPONSE
"""Template for the tool response."""
@classmethod
@override
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
return ConvoOutputParser()
@property
def _agent_type(self) -> str:
raise NotImplementedError
@property
def observation_prefix(self) -> str:
"""Prefix to append the observation with.
Returns:
"Observation: "
"""
return "Observation: "
@property
def llm_prefix(self) -> str:
"""Prefix to append the llm call with.
Returns:
"Thought: "
"""
return "Thought:"
@classmethod
def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
super()._validate_tools(tools)
validate_tools_single_input(cls.__name__, tools)
@classmethod
def create_prompt(
cls,
tools: Sequence[BaseTool],
system_message: str = PREFIX,
human_message: str = SUFFIX,
input_variables: list[str] | None = None,
output_parser: BaseOutputParser | None = None,
) -> BasePromptTemplate:
"""Create a prompt for the agent.
Args:
tools: The tools to use.
system_message: The `SystemMessage` to use.
human_message: The `HumanMessage` to use.
input_variables: The input variables to use.
output_parser: The output parser to use.
Returns:
A `PromptTemplate`.
"""
tool_strings = "\n".join(
[f"> {tool.name}: {tool.description}" for tool in tools],
)
tool_names = ", ".join([tool.name for tool in tools])
_output_parser = output_parser or cls._get_default_output_parser()
format_instructions = human_message.format(
format_instructions=_output_parser.get_format_instructions(),
)
final_prompt = format_instructions.format(
tool_names=tool_names,
tools=tool_strings,
)
if input_variables is None:
input_variables = ["input", "chat_history", "agent_scratchpad"]
messages = [
SystemMessagePromptTemplate.from_template(system_message),
MessagesPlaceholder(variable_name="chat_history"),
HumanMessagePromptTemplate.from_template(final_prompt),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
Extends
Source
Frequently Asked Questions
What is the ConversationalChatAgent class?
ConversationalChatAgent is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/conversational_chat/base.py.
Where is ConversationalChatAgent defined?
ConversationalChatAgent is defined in libs/langchain/langchain_classic/agents/conversational_chat/base.py at line 37.
What does ConversationalChatAgent extend?
ConversationalChatAgent extends Agent.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free