ZeroShotAgent Class — langchain Architecture
Architecture documentation for the ZeroShotAgent class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c["ZeroShotAgent"] 37fcc3f3_2798_3648_915c_2bffdd19bff7["Agent"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|extends| 37fcc3f3_2798_3648_915c_2bffdd19bff7 08e3637b_3cf5_6dc6_f338_f1122914aba8["base.py"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|defined in| 08e3637b_3cf5_6dc6_f338_f1122914aba8 66bbb2d3_d68f_0d1b_d3bc_2f021869e9e1["_get_default_output_parser()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| 66bbb2d3_d68f_0d1b_d3bc_2f021869e9e1 13cb4024_722a_fbb1_520c_d8cbbbbeeaa5["_agent_type()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| 13cb4024_722a_fbb1_520c_d8cbbbbeeaa5 b1370dba_d2af_58c4_48b0_746779cf51ac["observation_prefix()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| b1370dba_d2af_58c4_48b0_746779cf51ac 41149540_6bef_0c8f_5ea3_26fe55c3b748["llm_prefix()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| 41149540_6bef_0c8f_5ea3_26fe55c3b748 a98a6213_7754_f1a3_d0c4_c6068b628192["create_prompt()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| a98a6213_7754_f1a3_d0c4_c6068b628192 f50a836d_579d_7ed4_e51f_6bb4bd0b8059["from_llm_and_tools()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| f50a836d_579d_7ed4_e51f_6bb4bd0b8059 1c25b3ee_1cc2_569b_6970_bd431e6f54ca["_validate_tools()"] efa737fc_e2bb_00c6_fe6e_ee6cb1f6cb6c -->|method| 1c25b3ee_1cc2_569b_6970_bd431e6f54ca
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/mrkl/base.py lines 45–176
class ZeroShotAgent(Agent):
"""Agent for the MRKL chain.
Args:
output_parser: Output parser for the agent.
"""
output_parser: AgentOutputParser = Field(default_factory=MRKLOutputParser)
@classmethod
@override
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
return MRKLOutputParser()
@property
def _agent_type(self) -> str:
"""Return Identifier of agent type."""
return AgentType.ZERO_SHOT_REACT_DESCRIPTION
@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 create_prompt(
cls,
tools: Sequence[BaseTool],
prefix: str = PREFIX,
suffix: str = SUFFIX,
format_instructions: str = FORMAT_INSTRUCTIONS,
input_variables: list[str] | None = None,
) -> PromptTemplate:
"""Create prompt in the style of the zero shot agent.
Args:
tools: List of tools the agent will have access to, used to format the
prompt.
prefix: String to put before the list of tools.
suffix: String to put after the list of tools.
format_instructions: Instructions on how to use the tools.
input_variables: List of input variables the final prompt will expect.
Returns:
A PromptTemplate with the template assembled from the pieces here.
"""
tool_strings = render_text_description(list(tools))
tool_names = ", ".join([tool.name for tool in tools])
format_instructions = format_instructions.format(tool_names=tool_names)
template = f"{prefix}\n\n{tool_strings}\n\n{format_instructions}\n\n{suffix}"
if input_variables:
return PromptTemplate(template=template, input_variables=input_variables)
return PromptTemplate.from_template(template)
@classmethod
def from_llm_and_tools(
cls,
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
callback_manager: BaseCallbackManager | None = None,
output_parser: AgentOutputParser | None = None,
prefix: str = PREFIX,
suffix: str = SUFFIX,
format_instructions: str = FORMAT_INSTRUCTIONS,
input_variables: list[str] | None = None,
**kwargs: Any,
) -> Agent:
Extends
Source
Frequently Asked Questions
What is the ZeroShotAgent class?
ZeroShotAgent is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/mrkl/base.py.
Where is ZeroShotAgent defined?
ZeroShotAgent is defined in libs/langchain/langchain_classic/agents/mrkl/base.py at line 45.
What does ZeroShotAgent extend?
ZeroShotAgent extends Agent.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free