self_ask.py — langchain Source File
Architecture documentation for self_ask.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR cadd0a52_4d73_7282_dd36_5fc41c66f3b3["self_ask.py"] cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] cadd0a52_4d73_7282_dd36_5fc41c66f3b3 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"] cadd0a52_4d73_7282_dd36_5fc41c66f3b3 --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] cadd0a52_4d73_7282_dd36_5fc41c66f3b3 --> 75137834_4ba7_dc43_7ec5_182c05eceedf 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] cadd0a52_4d73_7282_dd36_5fc41c66f3b3 --> 91721f45_4909_e489_8c1f_084f8bd87145 e160f068_75de_4342_6673_9969b919de85["langchain_classic.agents.agent"] cadd0a52_4d73_7282_dd36_5fc41c66f3b3 --> e160f068_75de_4342_6673_9969b919de85 style cadd0a52_4d73_7282_dd36_5fc41c66f3b3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from collections.abc import Sequence
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException
from typing_extensions import override
from langchain_classic.agents.agent import AgentOutputParser
class SelfAskOutputParser(AgentOutputParser):
"""Parses self-ask style LLM calls.
Expects output to be in one of two formats.
If the output signals that an action should be taken,
should be in the below format. This will result in an AgentAction
being returned.
```
Thoughts go here...
Follow up: what is the temperature in SF?
```
If the output signals that a final answer should be given,
should be in the below format. This will result in an AgentFinish
being returned.
```
Thoughts go here...
So the final answer is: The temperature is 100 degrees
```
"""
followups: Sequence[str] = ("Follow up:", "Followup:")
finish_string: str = "So the final answer is: "
@override
def parse(self, text: str) -> AgentAction | AgentFinish:
last_line = text.rsplit("\n", maxsplit=1)[-1]
if not any(follow in last_line for follow in self.followups):
if self.finish_string not in last_line:
msg = f"Could not parse output: {text}"
raise OutputParserException(msg)
return AgentFinish({"output": last_line[len(self.finish_string) :]}, text)
after_colon = text.rsplit(":", maxsplit=1)[-1].strip()
return AgentAction("Intermediate Answer", after_colon, text)
@property
def _type(self) -> str:
return "self_ask"
Domain
Subdomains
Classes
Dependencies
- collections.abc
- langchain_classic.agents.agent
- langchain_core.agents
- langchain_core.exceptions
- typing_extensions
Source
Frequently Asked Questions
What does self_ask.py do?
self_ask.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ToolInterface subdomain.
What does self_ask.py depend on?
self_ask.py imports 5 module(s): collections.abc, langchain_classic.agents.agent, langchain_core.agents, langchain_core.exceptions, typing_extensions.
Where is self_ask.py in the architecture?
self_ask.py is located at libs/langchain/langchain_classic/agents/output_parsers/self_ask.py (domain: AgentOrchestration, subdomain: ToolInterface, directory: libs/langchain/langchain_classic/agents/output_parsers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free