Skip to content

Commit a47386f

Browse files
authored
style: more refs polishing (#33601)
1 parent aaf88c1 commit a47386f

File tree

7 files changed

+86
-56
lines changed

7 files changed

+86
-56
lines changed

libs/core/langchain_core/caches.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""`caches` provides an optional caching layer for language models.
1+
"""Optional caching layer for language models.
2+
3+
Distinct from provider-based [prompt caching](https://docs.langchain.com/oss/python/langchain/models#prompt-caching).
24
35
!!! warning
46
This is a beta feature! Please be wary of deploying experimental code to production

libs/core/langchain_core/tools/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class ChildTool(BaseTool):
483483
"""The tool response format.
484484
485485
If `"content"` then the output of the tool is interpreted as the contents of a
486-
ToolMessage. If `"content_and_artifact"` then the output is expected to be a
486+
`ToolMessage`. If `"content_and_artifact"` then the output is expected to be a
487487
two-tuple corresponding to the (content, artifact) of a `ToolMessage`.
488488
"""
489489

libs/core/langchain_core/utils/json_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def dereference_refs(
226226
... }
227227
>>> result = dereference_refs(schema) # Won't cause infinite recursion
228228
229-
Note:
229+
!!! note
230230
- Circular references are handled gracefully by breaking cycles
231231
- Mixed $ref objects (with both $ref and other properties) are supported
232232
- Additional properties in mixed $refs override resolved properties

libs/langchain/langchain_classic/embeddings/base.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,34 @@ def init_embeddings(
137137
installed.
138138
139139
Args:
140-
model: Name of the model to use. Can be either:
140+
model: Name of the model to use.
141+
142+
Can be either:
143+
141144
- A model string like `"openai:text-embedding-3-small"`
142-
- Just the model name if provider is specified
143-
provider: Optional explicit provider name. If not specified,
144-
will attempt to parse from the model string. Supported providers
145-
and their required packages:
145+
- Just the model name if the provider is specified separately or can be
146+
inferred.
147+
148+
See supported providers under the `provider` arg description.
149+
provider: Optional explicit provider name. If not specified, will attempt to
150+
parse from the model string in the `model` arg.
151+
152+
Supported providers:
146153
147-
{_get_provider_list()}
154+
- `openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
155+
- `azure_openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
156+
- `bedrock` -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
157+
- `cohere` -> [`langchain-cohere`](https://docs.langchain.com/oss/python/integrations/providers/cohere)
158+
- `google_vertexai` -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
159+
- `huggingface` -> [`langchain-huggingface`](https://docs.langchain.com/oss/python/integrations/providers/huggingface)
160+
- `mistraiai` -> [`langchain-mistralai`](https://docs.langchain.com/oss/python/integrations/providers/mistralai)
161+
- `ollama` -> [`langchain-ollama`](https://docs.langchain.com/oss/python/integrations/providers/ollama)
148162
149163
**kwargs: Additional model-specific parameters passed to the embedding model.
150164
These vary by provider, see the provider-specific documentation for details.
151165
152166
Returns:
153-
An Embeddings instance that can generate embeddings for text.
167+
An `Embeddings` instance that can generate embeddings for text.
154168
155169
Raises:
156170
ValueError: If the model provider is not supported or cannot be determined

libs/langchain_v1/langchain/agents/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def create_agent( # noqa: PLR0915
525525
"""Creates an agent graph that calls tools in a loop until a stopping condition is met.
526526
527527
For more details on using `create_agent`,
528-
visit [Agents](https://docs.langchain.com/oss/python/langchain/agents) documentation.
528+
visit the [Agents](https://docs.langchain.com/oss/python/langchain/agents) docs.
529529
530530
Args:
531531
model: The language model for the agent. Can be a string identifier

libs/langchain_v1/langchain/embeddings/base.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,34 @@ def init_embeddings(
133133
installed.
134134
135135
Args:
136-
model: Name of the model to use. Can be either:
136+
model: Name of the model to use.
137+
138+
Can be either:
139+
137140
- A model string like `"openai:text-embedding-3-small"`
138-
- Just the model name if provider is specified
139-
provider: Optional explicit provider name. If not specified,
140-
will attempt to parse from the model string. Supported providers
141-
and their required packages:
141+
- Just the model name if the provider is specified separately or can be
142+
inferred.
143+
144+
See supported providers under the `provider` arg description.
145+
provider: Optional explicit provider name. If not specified, will attempt to
146+
parse from the model string in the `model` arg.
147+
148+
Supported providers:
142149
143-
{_get_provider_list()}
150+
- `openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
151+
- `azure_openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
152+
- `bedrock` -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
153+
- `cohere` -> [`langchain-cohere`](https://docs.langchain.com/oss/python/integrations/providers/cohere)
154+
- `google_vertexai` -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
155+
- `huggingface` -> [`langchain-huggingface`](https://docs.langchain.com/oss/python/integrations/providers/huggingface)
156+
- `mistraiai` -> [`langchain-mistralai`](https://docs.langchain.com/oss/python/integrations/providers/mistralai)
157+
- `ollama` -> [`langchain-ollama`](https://docs.langchain.com/oss/python/integrations/providers/ollama)
144158
145159
**kwargs: Additional model-specific parameters passed to the embedding model.
146160
These vary by provider, see the provider-specific documentation for details.
147161
148162
Returns:
149-
An Embeddings instance that can generate embeddings for text.
163+
An `Embeddings` instance that can generate embeddings for text.
150164
151165
Raises:
152166
ValueError: If the model provider is not supported or cannot be determined

libs/langchain_v1/langchain/tools/tool_node.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
- Command-based state updates for advanced control flow
1414
1515
Key Components:
16-
ToolNode: Main class for executing tools in LangGraph workflows
17-
InjectedState: Annotation for injecting graph state into tools
18-
InjectedStore: Annotation for injecting persistent store into tools
19-
tools_condition: Utility function for conditional routing based on tool calls
16+
`ToolNode`: Main class for executing tools in LangGraph workflows
17+
`InjectedState`: Annotation for injecting graph state into tools
18+
`InjectedStore`: Annotation for injecting persistent store into tools
19+
`tools_condition`: Utility function for conditional routing based on tool calls
2020
2121
Typical Usage:
2222
```python
@@ -123,11 +123,11 @@ class ToolCallRequest:
123123
Attributes:
124124
tool_call: Tool call dict with name, args, and id from model output.
125125
tool: BaseTool instance to be invoked, or None if tool is not
126-
registered with the ToolNode. When tool is None, interceptors can
127-
handle the request without validation. If the interceptor calls execute(),
126+
registered with the `ToolNode`. When tool is `None`, interceptors can
127+
handle the request without validation. If the interceptor calls `execute()`,
128128
validation will occur and raise an error for unregistered tools.
129-
state: Agent state (dict, list, or BaseModel).
130-
runtime: LangGraph runtime context (optional, None if outside graph).
129+
state: Agent state (`dict`, `list`, or `BaseModel`).
130+
runtime: LangGraph runtime context (optional, `None` if outside graph).
131131
"""
132132

133133
tool_call: ToolCall
@@ -178,7 +178,7 @@ def override(self, **overrides: Unpack[_ToolCallRequestOverrides]) -> ToolCallRe
178178
with potentially modified requests each time. Each call to execute
179179
is independent and stateless.
180180
181-
Note:
181+
!!! note
182182
When implementing middleware for `create_agent`, use
183183
`AgentMiddleware.wrap_tool_call` which provides properly typed
184184
state parameter for better type safety.
@@ -247,7 +247,7 @@ def handler(request, execute):
247247
class ToolCallWithContext(TypedDict):
248248
"""ToolCall with additional context for graph state.
249249
250-
This is an internal data structure meant to help the ToolNode accept
250+
This is an internal data structure meant to help the `ToolNode` accept
251251
tool calls with additional context (e.g. state) when dispatched using the
252252
Send API.
253253
@@ -268,16 +268,16 @@ class ToolCallWithContext(TypedDict):
268268

269269

270270
def msg_content_output(output: Any) -> str | list[dict]:
271-
"""Convert tool output to ToolMessage content format.
271+
"""Convert tool output to `ToolMessage` content format.
272272
273-
Handles str, list[dict] (content blocks), and arbitrary objects by attempting
273+
Handles `str`, `list[dict]` (content blocks), and arbitrary objects by attempting
274274
JSON serialization with fallback to str().
275275
276276
Args:
277277
output: Tool execution output of any type.
278278
279279
Returns:
280-
String or list of content blocks suitable for ToolMessage.content.
280+
String or list of content blocks suitable for `ToolMessage.content`.
281281
"""
282282
if isinstance(output, str) or (
283283
isinstance(output, list)
@@ -297,7 +297,7 @@ def msg_content_output(output: Any) -> str | list[dict]:
297297
class ToolInvocationError(ToolException):
298298
"""An error occurred while invoking a tool due to invalid arguments.
299299
300-
This exception is only raised when invoking a tool using the ToolNode!
300+
This exception is only raised when invoking a tool using the `ToolNode`!
301301
"""
302302

303303
def __init__(
@@ -338,7 +338,7 @@ def _handle_tool_error(
338338
"""Generate error message content based on exception handling configuration.
339339
340340
This function centralizes error message generation logic, supporting different
341-
error handling strategies configured via the ToolNode's handle_tool_errors
341+
error handling strategies configured via the `ToolNode`'s `handle_tool_errors`
342342
parameter.
343343
344344
Args:
@@ -350,12 +350,12 @@ def _handle_tool_error(
350350
- tuple: Not used in this context (handled by caller)
351351
352352
Returns:
353-
A string containing the error message to include in the ToolMessage.
353+
A string containing the error message to include in the `ToolMessage`.
354354
355355
Raises:
356356
ValueError: If flag is not one of the supported types.
357357
358-
Note:
358+
!!! note
359359
The tuple case is handled by the caller through exception type checking,
360360
not by this function directly.
361361
"""
@@ -392,9 +392,9 @@ def _infer_handled_types(handler: Callable[..., str]) -> tuple[type[Exception],
392392
393393
Raises:
394394
ValueError: If the handler's annotation contains non-Exception types or
395-
if Union types contain non-Exception types.
395+
if Union types contain non-Exception types.
396396
397-
Note:
397+
!!! note
398398
This function supports both single exception types and Union types for
399399
handlers that need to handle multiple exception types differently.
400400
"""
@@ -560,7 +560,7 @@ def __init__(
560560
wrap_tool_call: ToolCallWrapper | None = None,
561561
awrap_tool_call: AsyncToolCallWrapper | None = None,
562562
) -> None:
563-
"""Initialize ToolNode with tools and configuration.
563+
"""Initialize `ToolNode` with tools and configuration.
564564
565565
Args:
566566
tools: Sequence of tools to make available for execution.
@@ -1181,11 +1181,11 @@ def _inject_tool_args(
11811181
11821182
Raises:
11831183
ValueError: If a tool requires store injection but no store is provided,
1184-
or if state injection requirements cannot be satisfied.
1184+
or if state injection requirements cannot be satisfied.
11851185
1186-
Note:
1186+
!!! note
11871187
This method is called automatically during tool execution. It should not
1188-
be called from outside the ToolNode.
1188+
be called from outside the `ToolNode`.
11891189
"""
11901190
if tool_call["name"] not in self.tools_by_name:
11911191
return tool_call
@@ -1329,9 +1329,9 @@ def custom_condition(state):
13291329
return tools_condition(state, messages_key="chat_history")
13301330
```
13311331
1332-
Note:
1333-
This function is designed to work seamlessly with ToolNode and standard
1334-
LangGraph patterns. It expects the last message to be an AIMessage when
1332+
!!! note
1333+
This function is designed to work seamlessly with `ToolNode` and standard
1334+
LangGraph patterns. It expects the last message to be an `AIMessage` when
13351335
tool calls are present, which is the standard output format for tool-calling
13361336
language models.
13371337
"""
@@ -1353,16 +1353,16 @@ def custom_condition(state):
13531353
class ToolRuntime(_DirectlyInjectedToolArg, Generic[ContextT, StateT]):
13541354
"""Runtime context automatically injected into tools.
13551355
1356-
When a tool function has a parameter named 'tool_runtime' with type hint
1357-
'ToolRuntime', the tool execution system will automatically inject
1358-
an instance containing:
1356+
When a tool function has a parameter named `tool_runtime` with type hint
1357+
`ToolRuntime`, the tool execution system will automatically inject an instance
1358+
containing:
13591359
1360-
- state: The current graph state
1361-
- tool_call_id: The ID of the current tool call
1362-
- config: RunnableConfig for the current execution
1363-
- context: Runtime context (from langgraph Runtime)
1364-
- store: BaseStore instance for persistent storage (from langgraph Runtime)
1365-
- stream_writer: StreamWriter for streaming output (from langgraph Runtime)
1360+
- `state`: The current graph state
1361+
- `tool_call_id`: The ID of the current tool call
1362+
- `config`: `RunnableConfig` for the current execution
1363+
- `context`: Runtime context (from langgraph `Runtime`)
1364+
- `store`: `BaseStore` instance for persistent storage (from langgraph `Runtime`)
1365+
- `stream_writer`: `StreamWriter` for streaming output (from langgraph `Runtime`)
13661366
13671367
No `Annotated` wrapper is needed - just use `runtime: ToolRuntime`
13681368
as a parameter.
@@ -1396,7 +1396,7 @@ def my_tool(x: int, runtime: ToolRuntime) -> str:
13961396
return f"Processed {x}"
13971397
```
13981398
1399-
Note:
1399+
!!! note
14001400
This is a marker class used for type checking and detection.
14011401
The actual runtime object will be constructed during tool execution.
14021402
"""
@@ -1470,7 +1470,7 @@ def foo_tool(x: int, foo: Annotated[str, InjectedState("foo")]) -> str:
14701470
]
14711471
```
14721472
1473-
Note:
1473+
!!! note
14741474
- `InjectedState` arguments are automatically excluded from tool schemas
14751475
presented to language models
14761476
- `ToolNode` handles the injection process during execution
@@ -1550,7 +1550,7 @@ def get_preference(
15501550
result2 = graph.invoke({"messages": [HumanMessage("What's my favorite color?")]})
15511551
```
15521552
1553-
Note:
1553+
!!! note
15541554
- `InjectedStore` arguments are automatically excluded from tool schemas
15551555
presented to language models
15561556
- The store instance is automatically injected by `ToolNode` during execution

0 commit comments

Comments
 (0)