BaseSingleActionAgent Class — langchain Architecture
Architecture documentation for the BaseSingleActionAgent class in agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2066c331_3189_1880_ba09_f5a3c375c553["BaseSingleActionAgent"] e1664047_3353_aa26_2a27_4fcd93c0a2f8["AgentType"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|extends| e1664047_3353_aa26_2a27_4fcd93c0a2f8 0faae8c7_2812_be15_1073_b6537539cea8["agent.py"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|defined in| 0faae8c7_2812_be15_1073_b6537539cea8 c0347dd9_4979_d672_ee07_20aa93cea076["return_values()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| c0347dd9_4979_d672_ee07_20aa93cea076 1758f18d_e340_dd7b_0ea3_7bf08d14d9d7["get_allowed_tools()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 1758f18d_e340_dd7b_0ea3_7bf08d14d9d7 8994748a_d5a3_a0e6_1869_05215e6046e5["plan()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 8994748a_d5a3_a0e6_1869_05215e6046e5 3b577de0_fb5e_78d3_db9f_6c9a46325e38["aplan()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 3b577de0_fb5e_78d3_db9f_6c9a46325e38 b49ce6e7_0876_1c60_3f79_9d23060372b6["input_keys()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| b49ce6e7_0876_1c60_3f79_9d23060372b6 a9280254_f4f8_cb71_2c6b_ad753985e93e["return_stopped_response()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| a9280254_f4f8_cb71_2c6b_ad753985e93e 17edecaa_ea70_0ca0_a54a_689470a272cb["from_llm_and_tools()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 17edecaa_ea70_0ca0_a54a_689470a272cb af16bc1c_c668_a100_0498_2bfa0da62b8e["_agent_type()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| af16bc1c_c668_a100_0498_2bfa0da62b8e 7e22a32a_d4cd_934d_79bf_5d7579310aae["dict()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 7e22a32a_d4cd_934d_79bf_5d7579310aae 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6["save()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 c66318ae_a2d5_5e44_2d5a_a995253a2e7b["tool_run_logging_kwargs()"] 2066c331_3189_1880_ba09_f5a3c375c553 -->|method| c66318ae_a2d5_5e44_2d5a_a995253a2e7b
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/agent.py lines 55–218
class BaseSingleActionAgent(BaseModel):
"""Base Single Action Agent class."""
@property
def return_values(self) -> list[str]:
"""Return values of the agent."""
return ["output"]
def get_allowed_tools(self) -> list[str] | None:
"""Get allowed tools."""
return None
@abstractmethod
def plan(
self,
intermediate_steps: list[tuple[AgentAction, str]],
callbacks: Callbacks = None,
**kwargs: Any,
) -> AgentAction | AgentFinish:
"""Given input, decided what to do.
Args:
intermediate_steps: Steps the LLM has taken to date,
along with observations.
callbacks: Callbacks to run.
**kwargs: User inputs.
Returns:
Action specifying what tool to use.
"""
@abstractmethod
async def aplan(
self,
intermediate_steps: list[tuple[AgentAction, str]],
callbacks: Callbacks = None,
**kwargs: Any,
) -> AgentAction | AgentFinish:
"""Async given input, decided what to do.
Args:
intermediate_steps: Steps the LLM has taken to date,
along with observations.
callbacks: Callbacks to run.
**kwargs: User inputs.
Returns:
Action specifying what tool to use.
"""
@property
@abstractmethod
def input_keys(self) -> list[str]:
"""Return the input keys."""
def return_stopped_response(
self,
early_stopping_method: str,
intermediate_steps: list[tuple[AgentAction, str]], # noqa: ARG002
**_: Any,
) -> AgentFinish:
"""Return response when agent has been stopped due to max iterations.
Args:
early_stopping_method: Method to use for early stopping.
intermediate_steps: Steps the LLM has taken to date,
along with observations.
Returns:
Agent finish object.
Raises:
ValueError: If `early_stopping_method` is not supported.
"""
if early_stopping_method == "force":
# `force` just returns a constant string
return AgentFinish(
{"output": "Agent stopped due to iteration limit or time limit."},
"",
)
msg = f"Got unsupported early_stopping_method `{early_stopping_method}`"
Extends
Source
Frequently Asked Questions
What is the BaseSingleActionAgent class?
BaseSingleActionAgent is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is BaseSingleActionAgent defined?
BaseSingleActionAgent is defined in libs/langchain/langchain_classic/agents/agent.py at line 55.
What does BaseSingleActionAgent extend?
BaseSingleActionAgent extends AgentType.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free