langchain 1.0.0a8__tar.gz → 1.0.0a9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langchain-1.0.0a8 → langchain-1.0.0a9}/PKG-INFO +1 -1
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/__init__.py +1 -1
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware/prompt_caching.py +2 -1
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware/types.py +5 -5
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware_agent.py +5 -3
- {langchain-1.0.0a8 → langchain-1.0.0a9}/pyproject.toml +1 -1
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_middleware_agent.py +9 -9
- {langchain-1.0.0a8 → langchain-1.0.0a9}/LICENSE +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/README.md +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/_documents.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/_lazy_import.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/_prompts.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/_typing.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/_internal/_utils.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/_internal/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/_internal/_typing.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware/human_in_the_loop.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/middleware/summarization.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/react_agent.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/structured_output.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/agents/tool_node.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/chat_models/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/chat_models/base.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/documents/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/embeddings/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/embeddings/base.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/embeddings/cache.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/globals.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/py.typed +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/storage/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/storage/encoder_backed.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/storage/exceptions.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/storage/in_memory.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/text_splitter.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/langchain/tools/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/agents/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/agents/test_response_format.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/cache/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/cache/fake_embeddings.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/chat_models/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/chat_models/test_base.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/conftest.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/embeddings/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/embeddings/test_base.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/test_compile.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/__snapshots__/test_middleware_agent.ambr +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/__snapshots__/test_react_agent_graph.ambr +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/any_str.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/compose-postgres.yml +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/compose-redis.yml +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/conftest.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/conftest_checkpointer.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/conftest_store.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/memory_assert.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/messages.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/model.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/specifications/responses.json +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/specifications/return_direct.json +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_middleware_decorators.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_react_agent.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_react_agent_graph.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_response_format.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_responses.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_responses_spec.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_return_direct_spec.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_tool_node.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/utils.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/chat_models/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/chat_models/test_chat_models.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/conftest.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/embeddings/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/embeddings/test_base.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/embeddings/test_caching.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/embeddings/test_imports.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/storage/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/storage/test_imports.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/stubs.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/test_dependencies.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/test_imports.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/test_pytest_config.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/tools/__init__.py +0 -0
- {langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/tools/test_imports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Anthropic prompt caching middleware."""
|
|
2
2
|
|
|
3
|
-
from typing import Literal
|
|
3
|
+
from typing import Any, Literal
|
|
4
4
|
from warnings import warn
|
|
5
5
|
|
|
6
6
|
from langchain.agents.middleware.types import AgentMiddleware, ModelRequest
|
|
@@ -42,6 +42,7 @@ class AnthropicPromptCachingMiddleware(AgentMiddleware):
|
|
|
42
42
|
def modify_model_request( # type: ignore[override]
|
|
43
43
|
self,
|
|
44
44
|
request: ModelRequest,
|
|
45
|
+
state: dict[str, Any], # noqa: ARG002
|
|
45
46
|
) -> ModelRequest:
|
|
46
47
|
"""Modify the model request to add cache control blocks."""
|
|
47
48
|
try:
|
|
@@ -45,7 +45,7 @@ __all__ = [
|
|
|
45
45
|
"PublicAgentState",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
|
-
JumpTo = Literal["tools", "model", "
|
|
48
|
+
JumpTo = Literal["tools", "model", "end"]
|
|
49
49
|
"""Destination to jump to when a middleware node returns."""
|
|
50
50
|
|
|
51
51
|
ResponseT = TypeVar("ResponseT")
|
|
@@ -237,7 +237,7 @@ def before_model(
|
|
|
237
237
|
AgentState schema.
|
|
238
238
|
tools: Optional list of additional tools to register with this middleware.
|
|
239
239
|
jump_to: Optional list of valid jump destinations for conditional edges.
|
|
240
|
-
Valid values are: "tools", "model", "
|
|
240
|
+
Valid values are: "tools", "model", "end"
|
|
241
241
|
name: Optional name for the generated middleware class. If not provided,
|
|
242
242
|
uses the decorated function's name.
|
|
243
243
|
|
|
@@ -260,10 +260,10 @@ def before_model(
|
|
|
260
260
|
|
|
261
261
|
Advanced usage with runtime and conditional jumping:
|
|
262
262
|
```python
|
|
263
|
-
@before_model(jump_to=["
|
|
263
|
+
@before_model(jump_to=["end"])
|
|
264
264
|
def conditional_before_model(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:
|
|
265
265
|
if some_condition(state):
|
|
266
|
-
return {"jump_to": "
|
|
266
|
+
return {"jump_to": "end"}
|
|
267
267
|
return None
|
|
268
268
|
```
|
|
269
269
|
|
|
@@ -474,7 +474,7 @@ def after_model(
|
|
|
474
474
|
AgentState schema.
|
|
475
475
|
tools: Optional list of additional tools to register with this middleware.
|
|
476
476
|
jump_to: Optional list of valid jump destinations for conditional edges.
|
|
477
|
-
Valid values are: "tools", "model", "
|
|
477
|
+
Valid values are: "tools", "model", "end"
|
|
478
478
|
name: Optional name for the generated middleware class. If not provided,
|
|
479
479
|
uses the decorated function's name.
|
|
480
480
|
|
|
@@ -505,8 +505,10 @@ def create_agent( # noqa: PLR0915
|
|
|
505
505
|
def _resolve_jump(jump_to: JumpTo | None, first_node: str) -> str | None:
|
|
506
506
|
if jump_to == "model":
|
|
507
507
|
return first_node
|
|
508
|
-
if jump_to:
|
|
509
|
-
return
|
|
508
|
+
if jump_to == "end":
|
|
509
|
+
return "__end__"
|
|
510
|
+
if jump_to == "tools":
|
|
511
|
+
return "tools"
|
|
510
512
|
return None
|
|
511
513
|
|
|
512
514
|
|
|
@@ -602,7 +604,7 @@ def _add_middleware_edge(
|
|
|
602
604
|
|
|
603
605
|
destinations = [default_destination]
|
|
604
606
|
|
|
605
|
-
if "
|
|
607
|
+
if "end" in jump_to:
|
|
606
608
|
destinations.append(END)
|
|
607
609
|
if "tools" in jump_to:
|
|
608
610
|
destinations.append("tools")
|
|
@@ -334,11 +334,11 @@ def test_create_agent_jump(
|
|
|
334
334
|
calls.append("NoopSeven.after_model")
|
|
335
335
|
|
|
336
336
|
class NoopEight(AgentMiddleware):
|
|
337
|
-
before_model_jump_to = [
|
|
337
|
+
before_model_jump_to = ["end"]
|
|
338
338
|
|
|
339
339
|
def before_model(self, state) -> dict[str, Any]:
|
|
340
340
|
calls.append("NoopEight.before_model")
|
|
341
|
-
return {"jump_to":
|
|
341
|
+
return {"jump_to": "end"}
|
|
342
342
|
|
|
343
343
|
def modify_model_request(self, request, state) -> ModelRequest:
|
|
344
344
|
calls.append("NoopEight.modify_model_request")
|
|
@@ -907,7 +907,7 @@ def test_anthropic_prompt_caching_middleware_initialization() -> None:
|
|
|
907
907
|
model_settings={},
|
|
908
908
|
)
|
|
909
909
|
|
|
910
|
-
assert middleware.modify_model_request(fake_request).model_settings == {
|
|
910
|
+
assert middleware.modify_model_request(fake_request, {}).model_settings == {
|
|
911
911
|
"cache_control": {"type": "ephemeral", "ttl": "5m"}
|
|
912
912
|
}
|
|
913
913
|
|
|
@@ -930,7 +930,7 @@ def test_anthropic_prompt_caching_middleware_unsupported_model() -> None:
|
|
|
930
930
|
ValueError,
|
|
931
931
|
match="AnthropicPromptCachingMiddleware caching middleware only supports Anthropic models. Please install langchain-anthropic.",
|
|
932
932
|
):
|
|
933
|
-
middleware.modify_model_request(fake_request)
|
|
933
|
+
middleware.modify_model_request(fake_request, {})
|
|
934
934
|
|
|
935
935
|
langchain_anthropic = ModuleType("langchain_anthropic")
|
|
936
936
|
|
|
@@ -944,12 +944,12 @@ def test_anthropic_prompt_caching_middleware_unsupported_model() -> None:
|
|
|
944
944
|
ValueError,
|
|
945
945
|
match="AnthropicPromptCachingMiddleware caching middleware only supports Anthropic models, not instances of",
|
|
946
946
|
):
|
|
947
|
-
middleware.modify_model_request(fake_request)
|
|
947
|
+
middleware.modify_model_request(fake_request, {})
|
|
948
948
|
|
|
949
949
|
middleware = AnthropicPromptCachingMiddleware(unsupported_model_behavior="warn")
|
|
950
950
|
|
|
951
951
|
with warnings.catch_warnings(record=True) as w:
|
|
952
|
-
result = middleware.modify_model_request(fake_request)
|
|
952
|
+
result = middleware.modify_model_request(fake_request, {})
|
|
953
953
|
assert len(w) == 1
|
|
954
954
|
assert (
|
|
955
955
|
"AnthropicPromptCachingMiddleware caching middleware only supports Anthropic models. Please install langchain-anthropic."
|
|
@@ -959,7 +959,7 @@ def test_anthropic_prompt_caching_middleware_unsupported_model() -> None:
|
|
|
959
959
|
|
|
960
960
|
with warnings.catch_warnings(record=True) as w:
|
|
961
961
|
with patch.dict("sys.modules", {"langchain_anthropic": langchain_anthropic}):
|
|
962
|
-
result = middleware.modify_model_request(fake_request)
|
|
962
|
+
result = middleware.modify_model_request(fake_request, {})
|
|
963
963
|
assert result is fake_request
|
|
964
964
|
assert len(w) == 1
|
|
965
965
|
assert (
|
|
@@ -969,11 +969,11 @@ def test_anthropic_prompt_caching_middleware_unsupported_model() -> None:
|
|
|
969
969
|
|
|
970
970
|
middleware = AnthropicPromptCachingMiddleware(unsupported_model_behavior="ignore")
|
|
971
971
|
|
|
972
|
-
result = middleware.modify_model_request(fake_request)
|
|
972
|
+
result = middleware.modify_model_request(fake_request, {})
|
|
973
973
|
assert result is fake_request
|
|
974
974
|
|
|
975
975
|
with patch.dict("sys.modules", {"langchain_anthropic": {"ChatAnthropic": object()}}):
|
|
976
|
-
result = middleware.modify_model_request(fake_request)
|
|
976
|
+
result = middleware.modify_model_request(fake_request, {})
|
|
977
977
|
assert result is fake_request
|
|
978
978
|
|
|
979
979
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langchain-1.0.0a8 → langchain-1.0.0a9}/tests/integration_tests/agents/test_response_format.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/specifications/responses.json
RENAMED
|
File without changes
|
{langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/specifications/return_direct.json
RENAMED
|
File without changes
|
{langchain-1.0.0a8 → langchain-1.0.0a9}/tests/unit_tests/agents/test_middleware_decorators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|