Skip to content

Commit dfb05a7

Browse files
authored
style: refs pass (#33813)
1 parent 2f67f9d commit dfb05a7

File tree

28 files changed

+413
-364
lines changed

28 files changed

+413
-364
lines changed

libs/core/langchain_core/agents.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,33 @@ class AgentAction(Serializable):
5252
"""The input to pass in to the Tool."""
5353
log: str
5454
"""Additional information to log about the action.
55-
This log can be used in a few ways. First, it can be used to audit
56-
what exactly the LLM predicted to lead to this (tool, tool_input).
57-
Second, it can be used in future iterations to show the LLMs prior
58-
thoughts. This is useful when (tool, tool_input) does not contain
59-
full information about the LLM prediction (for example, any `thought`
60-
before the tool/tool_input)."""
55+
56+
This log can be used in a few ways. First, it can be used to audit what exactly the
57+
LLM predicted to lead to this `(tool, tool_input)`.
58+
59+
Second, it can be used in future iterations to show the LLMs prior thoughts. This is
60+
useful when `(tool, tool_input)` does not contain full information about the LLM
61+
prediction (for example, any `thought` before the tool/tool_input).
62+
"""
6163
type: Literal["AgentAction"] = "AgentAction"
6264

6365
# Override init to support instantiation by position for backward compat.
6466
def __init__(self, tool: str, tool_input: str | dict, log: str, **kwargs: Any):
65-
"""Create an AgentAction.
67+
"""Create an `AgentAction`.
6668
6769
Args:
6870
tool: The name of the tool to execute.
69-
tool_input: The input to pass in to the Tool.
71+
tool_input: The input to pass in to the `Tool`.
7072
log: Additional information to log about the action.
7173
"""
7274
super().__init__(tool=tool, tool_input=tool_input, log=log, **kwargs)
7375

7476
@classmethod
7577
def is_lc_serializable(cls) -> bool:
76-
"""AgentAction is serializable.
78+
"""`AgentAction` is serializable.
7779
7880
Returns:
79-
True
81+
`True`
8082
"""
8183
return True
8284

@@ -98,19 +100,23 @@ def messages(self) -> Sequence[BaseMessage]:
98100
class AgentActionMessageLog(AgentAction):
99101
"""Representation of an action to be executed by an agent.
100102
101-
This is similar to AgentAction, but includes a message log consisting of
102-
chat messages. This is useful when working with ChatModels, and is used
103-
to reconstruct conversation history from the agent's perspective.
103+
This is similar to `AgentAction`, but includes a message log consisting of
104+
chat messages.
105+
106+
This is useful when working with `ChatModels`, and is used to reconstruct
107+
conversation history from the agent's perspective.
104108
"""
105109

106110
message_log: Sequence[BaseMessage]
107-
"""Similar to log, this can be used to pass along extra
108-
information about what exact messages were predicted by the LLM
109-
before parsing out the (tool, tool_input). This is again useful
110-
if (tool, tool_input) cannot be used to fully recreate the LLM
111-
prediction, and you need that LLM prediction (for future agent iteration).
111+
"""Similar to log, this can be used to pass along extra information about what exact
112+
messages were predicted by the LLM before parsing out the `(tool, tool_input)`.
113+
114+
This is again useful if `(tool, tool_input)` cannot be used to fully recreate the
115+
LLM prediction, and you need that LLM prediction (for future agent iteration).
116+
112117
Compared to `log`, this is useful when the underlying LLM is a
113-
chat model (and therefore returns messages rather than a string)."""
118+
chat model (and therefore returns messages rather than a string).
119+
"""
114120
# Ignoring type because we're overriding the type from AgentAction.
115121
# And this is the correct thing to do in this case.
116122
# The type literal is used for serialization purposes.
@@ -132,19 +138,22 @@ def messages(self) -> Sequence[BaseMessage]:
132138

133139

134140
class AgentFinish(Serializable):
135-
"""Final return value of an ActionAgent.
141+
"""Final return value of an `ActionAgent`.
136142
137-
Agents return an AgentFinish when they have reached a stopping condition.
143+
Agents return an `AgentFinish` when they have reached a stopping condition.
138144
"""
139145

140146
return_values: dict
141147
"""Dictionary of return values."""
142148
log: str
143149
"""Additional information to log about the return value.
150+
144151
This is used to pass along the full LLM prediction, not just the parsed out
145-
return value. For example, if the full LLM prediction was
146-
`Final Answer: 2` you may want to just return `2` as a return value, but pass
147-
along the full string as a `log` (for debugging or observability purposes).
152+
return value.
153+
154+
For example, if the full LLM prediction was `Final Answer: 2` you may want to just
155+
return `2` as a return value, but pass along the full string as a `log` (for
156+
debugging or observability purposes).
148157
"""
149158
type: Literal["AgentFinish"] = "AgentFinish"
150159

@@ -154,7 +163,7 @@ def __init__(self, return_values: dict, log: str, **kwargs: Any):
154163

155164
@classmethod
156165
def is_lc_serializable(cls) -> bool:
157-
"""Return True as this class is serializable."""
166+
"""Return `True` as this class is serializable."""
158167
return True
159168

160169
@classmethod
@@ -202,7 +211,7 @@ def _convert_agent_observation_to_messages(
202211
observation: Observation to convert to a message.
203212
204213
Returns:
205-
AIMessage that corresponds to the original tool invocation.
214+
`AIMessage` that corresponds to the original tool invocation.
206215
"""
207216
if isinstance(agent_action, AgentActionMessageLog):
208217
return [_create_function_message(agent_action, observation)]
@@ -225,7 +234,7 @@ def _create_function_message(
225234
observation: the result of the tool invocation.
226235
227236
Returns:
228-
FunctionMessage that corresponds to the original tool invocation.
237+
`FunctionMessage` that corresponds to the original tool invocation.
229238
"""
230239
if not isinstance(observation, str):
231240
try:

libs/core/langchain_core/documents/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ class Blob(BaseMedia):
114114
data: bytes | str | None = None
115115
"""Raw data associated with the `Blob`."""
116116
mimetype: str | None = None
117-
"""MimeType not to be confused with a file extension."""
117+
"""MIME type, not to be confused with a file extension."""
118118
encoding: str = "utf-8"
119119
"""Encoding to use if decoding the bytes into a string.
120120
121-
Use `utf-8` as default encoding, if decoding to string.
121+
Uses `utf-8` as default encoding if decoding to string.
122122
"""
123123
path: PathLike | None = None
124124
"""Location where the original content was found."""
@@ -134,7 +134,7 @@ def source(self) -> str | None:
134134
135135
If a path is associated with the `Blob`, it will default to the path location.
136136
137-
Unless explicitly set via a metadata field called `"source"`, in which
137+
Unless explicitly set via a metadata field called `'source'`, in which
138138
case that value will be used instead.
139139
"""
140140
if self.metadata and "source" in self.metadata:
@@ -309,7 +309,7 @@ def __init__(self, page_content: str, **kwargs: Any) -> None:
309309

310310
@classmethod
311311
def is_lc_serializable(cls) -> bool:
312-
"""Return True as this class is serializable."""
312+
"""Return `True` as this class is serializable."""
313313
return True
314314

315315
@classmethod
@@ -322,10 +322,10 @@ def get_lc_namespace(cls) -> list[str]:
322322
return ["langchain", "schema", "document"]
323323

324324
def __str__(self) -> str:
325-
"""Override __str__ to restrict it to page_content and metadata.
325+
"""Override `__str__` to restrict it to page_content and metadata.
326326
327327
Returns:
328-
A string representation of the Document.
328+
A string representation of the `Document`.
329329
"""
330330
# The format matches pydantic format for __str__.
331331
#

libs/core/langchain_core/outputs/generation.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class Generation(Serializable):
2020
2121
LangChain users working with chat models will usually access information via
2222
`AIMessage` (returned from runnable interfaces) or `LLMResult` (available
23-
via callbacks). Please refer the `AIMessage` and `LLMResult` schema documentation
24-
for more information.
23+
via callbacks). Please refer to `AIMessage` and `LLMResult` for more information.
2524
"""
2625

2726
text: str
@@ -34,11 +33,13 @@ class Generation(Serializable):
3433
"""
3534
type: Literal["Generation"] = "Generation"
3635
"""Type is used exclusively for serialization purposes.
37-
Set to "Generation" for this class."""
36+
37+
Set to "Generation" for this class.
38+
"""
3839

3940
@classmethod
4041
def is_lc_serializable(cls) -> bool:
41-
"""Return True as this class is serializable."""
42+
"""Return `True` as this class is serializable."""
4243
return True
4344

4445
@classmethod
@@ -52,7 +53,7 @@ def get_lc_namespace(cls) -> list[str]:
5253

5354

5455
class GenerationChunk(Generation):
55-
"""Generation chunk, which can be concatenated with other Generation chunks."""
56+
"""`GenerationChunk`, which can be concatenated with other Generation chunks."""
5657

5758
def __add__(self, other: GenerationChunk) -> GenerationChunk:
5859
"""Concatenate two `GenerationChunk`s.

libs/core/langchain_core/prompt_values.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PromptValue(Serializable, ABC):
3030

3131
@classmethod
3232
def is_lc_serializable(cls) -> bool:
33-
"""Return True as this class is serializable."""
33+
"""Return `True` as this class is serializable."""
3434
return True
3535

3636
@classmethod
@@ -48,7 +48,7 @@ def to_string(self) -> str:
4848

4949
@abstractmethod
5050
def to_messages(self) -> list[BaseMessage]:
51-
"""Return prompt as a list of Messages."""
51+
"""Return prompt as a list of messages."""
5252

5353

5454
class StringPromptValue(PromptValue):

0 commit comments

Comments
 (0)