langchain 1.0.0a2__tar.gz → 1.0.0a3__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.
Potentially problematic release.
This version of langchain might be problematic. Click here for more details.
- {langchain-1.0.0a2 → langchain-1.0.0a3}/PKG-INFO +2 -2
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/__init__.py +2 -2
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/react_agent.py +6 -6
- {langchain-1.0.0a2 → langchain-1.0.0a3}/pyproject.toml +2 -2
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/agents/test_response_format.py +3 -3
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_react_agent.py +49 -51
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_react_agent_graph.py +2 -2
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_response_format.py +25 -31
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_responses_spec.py +1 -1
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_return_direct_spec.py +2 -2
- {langchain-1.0.0a2 → langchain-1.0.0a3}/LICENSE +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/README.md +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/_documents.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/_lazy_import.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/_prompts.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/_typing.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/_internal/_utils.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/_internal/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/_internal/_typing.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/interrupt.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/structured_output.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/agents/tool_node.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/chat_models/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/chat_models/base.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/documents/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/embeddings/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/embeddings/base.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/embeddings/cache.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/globals.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/py.typed +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/storage/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/storage/encoder_backed.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/storage/exceptions.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/storage/in_memory.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/text_splitter.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/langchain/tools/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/agents/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/cache/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/cache/fake_embeddings.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/chat_models/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/chat_models/test_base.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/conftest.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/embeddings/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/embeddings/test_base.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/test_compile.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/__snapshots__/test_react_agent_graph.ambr +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/any_str.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/compose-postgres.yml +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/compose-redis.yml +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/conftest.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/conftest_checkpointer.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/conftest_store.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/memory_assert.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/messages.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/model.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/specifications/responses.json +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/specifications/return_direct.json +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_responses.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/test_tool_node.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/utils.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/chat_models/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/chat_models/test_chat_models.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/conftest.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/embeddings/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/embeddings/test_base.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/embeddings/test_caching.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/embeddings/test_imports.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/storage/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/storage/test_imports.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/stubs.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/test_dependencies.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/test_imports.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/test_pytest_config.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/tools/__init__.py +0 -0
- {langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/tools/test_imports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: langchain
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0a3
|
|
4
4
|
Summary: Building applications with LLMs through composability
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/langchain
|
|
@@ -8,7 +8,7 @@ Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q
|
|
|
8
8
|
Project-URL: repository, https://github.com/langchain-ai/langchain
|
|
9
9
|
Requires-Python: >=3.10
|
|
10
10
|
Requires-Dist: langchain-core<2.0.0,>=0.3.75
|
|
11
|
-
Requires-Dist: langchain-text-splitters<1.0.0,>=0.3.
|
|
11
|
+
Requires-Dist: langchain-text-splitters<1.0.0,>=0.3.11
|
|
12
12
|
Requires-Dist: langgraph>=0.6.0
|
|
13
13
|
Requires-Dist: pydantic>=2.7.4
|
|
14
14
|
Provides-Extra: anthropic
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""langgraph.prebuilt exposes a higher-level API for creating and executing agents and tools."""
|
|
2
2
|
|
|
3
|
-
from langchain.agents.react_agent import AgentState,
|
|
3
|
+
from langchain.agents.react_agent import AgentState, create_agent
|
|
4
4
|
from langchain.agents.tool_node import ToolNode
|
|
5
5
|
|
|
6
6
|
__all__ = [
|
|
7
7
|
"AgentState",
|
|
8
8
|
"ToolNode",
|
|
9
|
-
"
|
|
9
|
+
"create_agent",
|
|
10
10
|
]
|
|
@@ -898,7 +898,7 @@ def _supports_native_structured_output(
|
|
|
898
898
|
)
|
|
899
899
|
|
|
900
900
|
|
|
901
|
-
def
|
|
901
|
+
def create_agent( # noqa: D417
|
|
902
902
|
model: Union[
|
|
903
903
|
str,
|
|
904
904
|
BaseChatModel,
|
|
@@ -928,7 +928,7 @@ def create_react_agent( # noqa: D417
|
|
|
928
928
|
) -> CompiledStateGraph[StateT, ContextT]:
|
|
929
929
|
"""Creates an agent graph that calls tools in a loop until a stopping condition is met.
|
|
930
930
|
|
|
931
|
-
For more details on using `
|
|
931
|
+
For more details on using `create_agent`, visit [Agents](https://langchain-ai.github.io/langgraph/agents/overview/) documentation.
|
|
932
932
|
|
|
933
933
|
Args:
|
|
934
934
|
model: The language model for the agent. Supports static and dynamic
|
|
@@ -1096,13 +1096,13 @@ def create_react_agent( # noqa: D417
|
|
|
1096
1096
|
|
|
1097
1097
|
Example:
|
|
1098
1098
|
```python
|
|
1099
|
-
from langchain.agents import
|
|
1099
|
+
from langchain.agents import create_agent
|
|
1100
1100
|
|
|
1101
1101
|
def check_weather(location: str) -> str:
|
|
1102
1102
|
'''Return the weather forecast for the specified location.'''
|
|
1103
1103
|
return f"It's always sunny in {location}"
|
|
1104
1104
|
|
|
1105
|
-
graph =
|
|
1105
|
+
graph = create_agent(
|
|
1106
1106
|
"anthropic:claude-3-7-sonnet-latest",
|
|
1107
1107
|
tools=[check_weather],
|
|
1108
1108
|
prompt="You are a helpful assistant",
|
|
@@ -1123,7 +1123,7 @@ def create_react_agent( # noqa: D417
|
|
|
1123
1123
|
context_schema = config_schema
|
|
1124
1124
|
|
|
1125
1125
|
if len(deprecated_kwargs) > 0:
|
|
1126
|
-
msg = f"
|
|
1126
|
+
msg = f"create_agent() got unexpected keyword arguments: {deprecated_kwargs}"
|
|
1127
1127
|
raise TypeError(msg)
|
|
1128
1128
|
|
|
1129
1129
|
if response_format and not isinstance(response_format, (ToolStrategy, ProviderStrategy)):
|
|
@@ -1171,5 +1171,5 @@ __all__ = [
|
|
|
1171
1171
|
"AgentStatePydantic",
|
|
1172
1172
|
"AgentStateWithStructuredResponse",
|
|
1173
1173
|
"AgentStateWithStructuredResponsePydantic",
|
|
1174
|
-
"
|
|
1174
|
+
"create_agent",
|
|
1175
1175
|
]
|
|
@@ -9,12 +9,12 @@ authors = []
|
|
|
9
9
|
requires-python = ">=3.10"
|
|
10
10
|
dependencies = [
|
|
11
11
|
"langchain-core<2.0.0,>=0.3.75",
|
|
12
|
-
"langchain-text-splitters<1.0.0,>=0.3.
|
|
12
|
+
"langchain-text-splitters<1.0.0,>=0.3.11",
|
|
13
13
|
"langgraph>=0.6.0",
|
|
14
14
|
"pydantic>=2.7.4",
|
|
15
15
|
]
|
|
16
16
|
name = "langchain"
|
|
17
|
-
version = "1.0.
|
|
17
|
+
version = "1.0.0a3"
|
|
18
18
|
description = "Building applications with LLMs through composability"
|
|
19
19
|
readme = "README.md"
|
|
20
20
|
|
{langchain-1.0.0a2 → langchain-1.0.0a3}/tests/integration_tests/agents/test_response_format.py
RENAMED
|
@@ -2,7 +2,7 @@ import pytest
|
|
|
2
2
|
from langchain_core.messages import HumanMessage
|
|
3
3
|
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from langchain.agents import
|
|
5
|
+
from langchain.agents import create_agent
|
|
6
6
|
from langchain.agents.structured_output import ToolStrategy
|
|
7
7
|
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ def test_inference_to_native_output() -> None:
|
|
|
24
24
|
from langchain_openai import ChatOpenAI
|
|
25
25
|
|
|
26
26
|
model = ChatOpenAI(model="gpt-5")
|
|
27
|
-
agent =
|
|
27
|
+
agent = create_agent(
|
|
28
28
|
model,
|
|
29
29
|
prompt=(
|
|
30
30
|
"You are a helpful weather assistant. Please call the get_weather tool, "
|
|
@@ -54,7 +54,7 @@ def test_inference_to_tool_output() -> None:
|
|
|
54
54
|
from langchain_openai import ChatOpenAI
|
|
55
55
|
|
|
56
56
|
model = ChatOpenAI(model="gpt-4")
|
|
57
|
-
agent =
|
|
57
|
+
agent = create_agent(
|
|
58
58
|
model,
|
|
59
59
|
prompt=(
|
|
60
60
|
"You are a helpful weather assistant. Please call the get_weather tool, "
|
|
@@ -32,7 +32,7 @@ from typing_extensions import TypedDict
|
|
|
32
32
|
from langchain.agents import (
|
|
33
33
|
AgentState,
|
|
34
34
|
ToolNode,
|
|
35
|
-
|
|
35
|
+
create_agent,
|
|
36
36
|
)
|
|
37
37
|
from langchain.agents.react_agent import _validate_chat_history
|
|
38
38
|
from langchain.agents.tool_node import (
|
|
@@ -52,7 +52,7 @@ pytestmark = pytest.mark.anyio
|
|
|
52
52
|
def test_no_prompt(sync_checkpointer: BaseCheckpointSaver) -> None:
|
|
53
53
|
model = FakeToolCallingModel()
|
|
54
54
|
|
|
55
|
-
agent =
|
|
55
|
+
agent = create_agent(
|
|
56
56
|
model,
|
|
57
57
|
[],
|
|
58
58
|
checkpointer=sync_checkpointer,
|
|
@@ -82,7 +82,7 @@ def test_no_prompt(sync_checkpointer: BaseCheckpointSaver) -> None:
|
|
|
82
82
|
async def test_no_prompt_async(async_checkpointer: BaseCheckpointSaver) -> None:
|
|
83
83
|
model = FakeToolCallingModel()
|
|
84
84
|
|
|
85
|
-
agent =
|
|
85
|
+
agent = create_agent(model, [], checkpointer=async_checkpointer)
|
|
86
86
|
inputs = [HumanMessage("hi?")]
|
|
87
87
|
thread = {"configurable": {"thread_id": "123"}}
|
|
88
88
|
response = await agent.ainvoke({"messages": inputs}, thread, debug=True)
|
|
@@ -107,7 +107,7 @@ async def test_no_prompt_async(async_checkpointer: BaseCheckpointSaver) -> None:
|
|
|
107
107
|
|
|
108
108
|
def test_system_message_prompt() -> None:
|
|
109
109
|
prompt = SystemMessage(content="Foo")
|
|
110
|
-
agent =
|
|
110
|
+
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
|
111
111
|
inputs = [HumanMessage("hi?")]
|
|
112
112
|
response = agent.invoke({"messages": inputs})
|
|
113
113
|
expected_response = {"messages": [*inputs, AIMessage(content="Foo-hi?", id="0", tool_calls=[])]}
|
|
@@ -116,7 +116,7 @@ def test_system_message_prompt() -> None:
|
|
|
116
116
|
|
|
117
117
|
def test_string_prompt() -> None:
|
|
118
118
|
prompt = "Foo"
|
|
119
|
-
agent =
|
|
119
|
+
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
|
120
120
|
inputs = [HumanMessage("hi?")]
|
|
121
121
|
response = agent.invoke({"messages": inputs})
|
|
122
122
|
expected_response = {"messages": [*inputs, AIMessage(content="Foo-hi?", id="0", tool_calls=[])]}
|
|
@@ -128,7 +128,7 @@ def test_callable_prompt() -> None:
|
|
|
128
128
|
modified_message = f"Bar {state['messages'][-1].content}"
|
|
129
129
|
return [HumanMessage(content=modified_message)]
|
|
130
130
|
|
|
131
|
-
agent =
|
|
131
|
+
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
|
132
132
|
inputs = [HumanMessage("hi?")]
|
|
133
133
|
response = agent.invoke({"messages": inputs})
|
|
134
134
|
expected_response = {"messages": [*inputs, AIMessage(content="Bar hi?", id="0")]}
|
|
@@ -140,7 +140,7 @@ async def test_callable_prompt_async() -> None:
|
|
|
140
140
|
modified_message = f"Bar {state['messages'][-1].content}"
|
|
141
141
|
return [HumanMessage(content=modified_message)]
|
|
142
142
|
|
|
143
|
-
agent =
|
|
143
|
+
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
|
144
144
|
inputs = [HumanMessage("hi?")]
|
|
145
145
|
response = await agent.ainvoke({"messages": inputs})
|
|
146
146
|
expected_response = {"messages": [*inputs, AIMessage(content="Bar hi?", id="0")]}
|
|
@@ -152,7 +152,7 @@ def test_runnable_prompt() -> None:
|
|
|
152
152
|
lambda state: [HumanMessage(content=f"Baz {state['messages'][-1].content}")]
|
|
153
153
|
)
|
|
154
154
|
|
|
155
|
-
agent =
|
|
155
|
+
agent = create_agent(FakeToolCallingModel(), [], prompt=prompt)
|
|
156
156
|
inputs = [HumanMessage("hi?")]
|
|
157
157
|
response = agent.invoke({"messages": inputs})
|
|
158
158
|
expected_response = {"messages": [*inputs, AIMessage(content="Baz hi?", id="0")]}
|
|
@@ -179,7 +179,7 @@ def test_prompt_with_store() -> None:
|
|
|
179
179
|
model = FakeToolCallingModel()
|
|
180
180
|
|
|
181
181
|
# test state modifier that uses store works
|
|
182
|
-
agent =
|
|
182
|
+
agent = create_agent(
|
|
183
183
|
model,
|
|
184
184
|
[add],
|
|
185
185
|
prompt=prompt,
|
|
@@ -189,7 +189,7 @@ def test_prompt_with_store() -> None:
|
|
|
189
189
|
assert response["messages"][-1].content == "User name is Alice-hi"
|
|
190
190
|
|
|
191
191
|
# test state modifier that doesn't use store works
|
|
192
|
-
agent =
|
|
192
|
+
agent = create_agent(
|
|
193
193
|
model,
|
|
194
194
|
[add],
|
|
195
195
|
prompt=prompt_no_store,
|
|
@@ -219,14 +219,14 @@ async def test_prompt_with_store_async() -> None:
|
|
|
219
219
|
model = FakeToolCallingModel()
|
|
220
220
|
|
|
221
221
|
# test state modifier that uses store works
|
|
222
|
-
agent =
|
|
222
|
+
agent = create_agent(model, [add], prompt=prompt, store=in_memory_store)
|
|
223
223
|
response = await agent.ainvoke(
|
|
224
224
|
{"messages": [("user", "hi")]}, {"configurable": {"user_id": "1"}}
|
|
225
225
|
)
|
|
226
226
|
assert response["messages"][-1].content == "User name is Alice-hi"
|
|
227
227
|
|
|
228
228
|
# test state modifier that doesn't use store works
|
|
229
|
-
agent =
|
|
229
|
+
agent = create_agent(model, [add], prompt=prompt_no_store, store=in_memory_store)
|
|
230
230
|
response = await agent.ainvoke(
|
|
231
231
|
{"messages": [("user", "hi")]}, {"configurable": {"user_id": "2"}}
|
|
232
232
|
)
|
|
@@ -267,7 +267,7 @@ def test_model_with_tools(tool_style: str, include_builtin: bool) -> None:
|
|
|
267
267
|
)
|
|
268
268
|
# check valid agent constructor
|
|
269
269
|
with pytest.raises(ValueError):
|
|
270
|
-
|
|
270
|
+
create_agent(
|
|
271
271
|
model.bind_tools(tools),
|
|
272
272
|
tools,
|
|
273
273
|
)
|
|
@@ -414,7 +414,7 @@ def test_react_agent_with_structured_response() -> None:
|
|
|
414
414
|
model = FakeToolCallingModel[WeatherResponse](
|
|
415
415
|
tool_calls=tool_calls, structured_response=expected_structured_response
|
|
416
416
|
)
|
|
417
|
-
agent =
|
|
417
|
+
agent = create_agent(
|
|
418
418
|
model,
|
|
419
419
|
[get_weather],
|
|
420
420
|
response_format=WeatherResponse,
|
|
@@ -472,7 +472,7 @@ def test_react_agent_update_state(
|
|
|
472
472
|
|
|
473
473
|
tool_calls = [[{"args": {}, "id": "1", "name": "get_user_name"}]]
|
|
474
474
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
475
|
-
agent =
|
|
475
|
+
agent = create_agent(
|
|
476
476
|
model,
|
|
477
477
|
[get_user_name],
|
|
478
478
|
state_schema=CustomState,
|
|
@@ -523,7 +523,7 @@ def test_react_agent_parallel_tool_calls(
|
|
|
523
523
|
[],
|
|
524
524
|
]
|
|
525
525
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
526
|
-
agent =
|
|
526
|
+
agent = create_agent(
|
|
527
527
|
model,
|
|
528
528
|
[human_assistance, get_weather],
|
|
529
529
|
checkpointer=sync_checkpointer,
|
|
@@ -561,7 +561,7 @@ class AgentStateExtraKey(AgentState):
|
|
|
561
561
|
foo: int
|
|
562
562
|
|
|
563
563
|
|
|
564
|
-
def
|
|
564
|
+
def test_create_agent_inject_vars() -> None:
|
|
565
565
|
"""Test that the agent can inject state and store into tool functions."""
|
|
566
566
|
store = InMemoryStore()
|
|
567
567
|
namespace = ("test",)
|
|
@@ -583,7 +583,7 @@ def test_create_react_agent_inject_vars() -> None:
|
|
|
583
583
|
"type": "tool_call",
|
|
584
584
|
}
|
|
585
585
|
model = FakeToolCallingModel(tool_calls=[[tool_call], []])
|
|
586
|
-
agent =
|
|
586
|
+
agent = create_agent(
|
|
587
587
|
model,
|
|
588
588
|
ToolNode([tool1], handle_tool_errors=False),
|
|
589
589
|
state_schema=AgentStateExtraKey,
|
|
@@ -623,7 +623,7 @@ async def test_return_direct() -> None:
|
|
|
623
623
|
tool_calls=first_tool_call,
|
|
624
624
|
)
|
|
625
625
|
model = FakeToolCallingModel(tool_calls=[first_tool_call, []])
|
|
626
|
-
agent =
|
|
626
|
+
agent = create_agent(
|
|
627
627
|
model,
|
|
628
628
|
[tool_return_direct, tool_normal],
|
|
629
629
|
)
|
|
@@ -648,7 +648,7 @@ async def test_return_direct() -> None:
|
|
|
648
648
|
),
|
|
649
649
|
]
|
|
650
650
|
model = FakeToolCallingModel(tool_calls=[second_tool_call, []])
|
|
651
|
-
agent =
|
|
651
|
+
agent = create_agent(model, [tool_return_direct, tool_normal])
|
|
652
652
|
result = agent.invoke({"messages": [HumanMessage(content="Test normal", id="hum1")]})
|
|
653
653
|
assert result["messages"] == [
|
|
654
654
|
HumanMessage(content="Test normal", id="hum1"),
|
|
@@ -675,7 +675,7 @@ async def test_return_direct() -> None:
|
|
|
675
675
|
),
|
|
676
676
|
]
|
|
677
677
|
model = FakeToolCallingModel(tool_calls=[both_tool_calls, []])
|
|
678
|
-
agent =
|
|
678
|
+
agent = create_agent(model, [tool_return_direct, tool_normal])
|
|
679
679
|
result = agent.invoke({"messages": [HumanMessage(content="Test both", id="hum2")]})
|
|
680
680
|
assert result["messages"] == [
|
|
681
681
|
HumanMessage(content="Test both", id="hum2"),
|
|
@@ -712,7 +712,7 @@ def test__get_state_args() -> None:
|
|
|
712
712
|
|
|
713
713
|
def test_inspect_react() -> None:
|
|
714
714
|
model = FakeToolCallingModel(tool_calls=[])
|
|
715
|
-
agent =
|
|
715
|
+
agent = create_agent(model, [])
|
|
716
716
|
inspect.getclosurevars(agent.nodes["agent"].bound.func)
|
|
717
717
|
|
|
718
718
|
|
|
@@ -766,7 +766,7 @@ def test_react_with_subgraph_tools(
|
|
|
766
766
|
]
|
|
767
767
|
)
|
|
768
768
|
tool_node = ToolNode([addition, multiplication], handle_tool_errors=False)
|
|
769
|
-
agent =
|
|
769
|
+
agent = create_agent(
|
|
770
770
|
model,
|
|
771
771
|
tool_node,
|
|
772
772
|
checkpointer=sync_checkpointer,
|
|
@@ -812,7 +812,7 @@ def test_react_agent_subgraph_streaming_sync() -> None:
|
|
|
812
812
|
]
|
|
813
813
|
)
|
|
814
814
|
|
|
815
|
-
agent =
|
|
815
|
+
agent = create_agent(
|
|
816
816
|
model,
|
|
817
817
|
tools=[get_weather],
|
|
818
818
|
prompt="You are a helpful travel assistant.",
|
|
@@ -899,7 +899,7 @@ async def test_react_agent_subgraph_streaming() -> None:
|
|
|
899
899
|
]
|
|
900
900
|
)
|
|
901
901
|
|
|
902
|
-
agent =
|
|
902
|
+
agent = create_agent(
|
|
903
903
|
model,
|
|
904
904
|
tools=[get_weather],
|
|
905
905
|
prompt="You are a helpful travel assistant.",
|
|
@@ -994,7 +994,7 @@ def test_tool_node_node_interrupt(
|
|
|
994
994
|
]
|
|
995
995
|
)
|
|
996
996
|
config = {"configurable": {"thread_id": "1"}}
|
|
997
|
-
agent =
|
|
997
|
+
agent = create_agent(
|
|
998
998
|
model,
|
|
999
999
|
[tool_interrupt, tool_normal],
|
|
1000
1000
|
checkpointer=sync_checkpointer,
|
|
@@ -1045,7 +1045,7 @@ def test_dynamic_model_basic() -> None:
|
|
|
1045
1045
|
return FakeToolCallingModel(tool_calls=[])
|
|
1046
1046
|
return FakeToolCallingModel(tool_calls=[])
|
|
1047
1047
|
|
|
1048
|
-
agent =
|
|
1048
|
+
agent = create_agent(dynamic_model, [])
|
|
1049
1049
|
|
|
1050
1050
|
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
|
1051
1051
|
assert len(result["messages"]) == 2
|
|
@@ -1082,7 +1082,7 @@ def test_dynamic_model_with_tools() -> None:
|
|
|
1082
1082
|
tool_calls=[[{"args": {"x": 1}, "id": "1", "name": "basic_tool"}], []]
|
|
1083
1083
|
)
|
|
1084
1084
|
|
|
1085
|
-
agent =
|
|
1085
|
+
agent = create_agent(dynamic_model, [basic_tool, advanced_tool])
|
|
1086
1086
|
|
|
1087
1087
|
# Test basic tool usage
|
|
1088
1088
|
result = agent.invoke({"messages": [HumanMessage("basic request")]})
|
|
@@ -1114,7 +1114,7 @@ def test_dynamic_model_with_context() -> None:
|
|
|
1114
1114
|
return FakeToolCallingModel(tool_calls=[])
|
|
1115
1115
|
return FakeToolCallingModel(tool_calls=[])
|
|
1116
1116
|
|
|
1117
|
-
agent =
|
|
1117
|
+
agent = create_agent(dynamic_model, [], context_schema=Context)
|
|
1118
1118
|
|
|
1119
1119
|
# Test with basic user
|
|
1120
1120
|
result = agent.invoke(
|
|
@@ -1143,7 +1143,7 @@ def test_dynamic_model_with_state_schema() -> None:
|
|
|
1143
1143
|
return FakeToolCallingModel(tool_calls=[])
|
|
1144
1144
|
return FakeToolCallingModel(tool_calls=[])
|
|
1145
1145
|
|
|
1146
|
-
agent =
|
|
1146
|
+
agent = create_agent(dynamic_model, [], state_schema=CustomDynamicState)
|
|
1147
1147
|
|
|
1148
1148
|
result = agent.invoke({"messages": [HumanMessage("hello")], "model_preference": "advanced"})
|
|
1149
1149
|
assert len(result["messages"]) == 2
|
|
@@ -1157,7 +1157,7 @@ def test_dynamic_model_with_prompt() -> None:
|
|
|
1157
1157
|
return FakeToolCallingModel(tool_calls=[])
|
|
1158
1158
|
|
|
1159
1159
|
# Test with string prompt
|
|
1160
|
-
agent =
|
|
1160
|
+
agent = create_agent(dynamic_model, [], prompt="system_msg")
|
|
1161
1161
|
result = agent.invoke({"messages": [HumanMessage("human_msg")]})
|
|
1162
1162
|
assert result["messages"][-1].content == "system_msg-human_msg"
|
|
1163
1163
|
|
|
@@ -1166,7 +1166,7 @@ def test_dynamic_model_with_prompt() -> None:
|
|
|
1166
1166
|
"""Generate a dynamic system message based on state."""
|
|
1167
1167
|
return [{"role": "system", "content": "system_msg"}, *list(state["messages"])]
|
|
1168
1168
|
|
|
1169
|
-
agent =
|
|
1169
|
+
agent = create_agent(dynamic_model, [], prompt=dynamic_prompt)
|
|
1170
1170
|
result = agent.invoke({"messages": [HumanMessage("human_msg")]})
|
|
1171
1171
|
assert result["messages"][-1].content == "system_msg-human_msg"
|
|
1172
1172
|
|
|
@@ -1177,7 +1177,7 @@ async def test_dynamic_model_async() -> None:
|
|
|
1177
1177
|
def dynamic_model(state: AgentState, runtime: Runtime) -> BaseChatModel:
|
|
1178
1178
|
return FakeToolCallingModel(tool_calls=[])
|
|
1179
1179
|
|
|
1180
|
-
agent =
|
|
1180
|
+
agent = create_agent(dynamic_model, [])
|
|
1181
1181
|
|
|
1182
1182
|
result = await agent.ainvoke({"messages": [HumanMessage("hello async")]})
|
|
1183
1183
|
assert len(result["messages"]) == 2
|
|
@@ -1205,7 +1205,7 @@ def test_dynamic_model_with_structured_response() -> None:
|
|
|
1205
1205
|
],
|
|
1206
1206
|
)
|
|
1207
1207
|
|
|
1208
|
-
agent =
|
|
1208
|
+
agent = create_agent(dynamic_model, [], response_format=TestResponse)
|
|
1209
1209
|
|
|
1210
1210
|
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
|
1211
1211
|
assert "structured_response" in result
|
|
@@ -1229,7 +1229,7 @@ def test_dynamic_model_with_checkpointer(sync_checkpointer) -> None:
|
|
|
1229
1229
|
index=call_count,
|
|
1230
1230
|
)
|
|
1231
1231
|
|
|
1232
|
-
agent =
|
|
1232
|
+
agent = create_agent(dynamic_model, [], checkpointer=sync_checkpointer)
|
|
1233
1233
|
config = {"configurable": {"thread_id": "test_dynamic"}}
|
|
1234
1234
|
|
|
1235
1235
|
# First call
|
|
@@ -1267,7 +1267,7 @@ def test_dynamic_model_state_dependent_tools() -> None:
|
|
|
1267
1267
|
tool_calls=[[{"args": {"x": 1}, "id": "1", "name": "tool_a"}], []]
|
|
1268
1268
|
)
|
|
1269
1269
|
|
|
1270
|
-
agent =
|
|
1270
|
+
agent = create_agent(dynamic_model, [tool_a, tool_b])
|
|
1271
1271
|
|
|
1272
1272
|
# Ask to use tool B
|
|
1273
1273
|
result = agent.invoke({"messages": [HumanMessage("use_b please")]})
|
|
@@ -1291,7 +1291,7 @@ def test_dynamic_model_error_handling() -> None:
|
|
|
1291
1291
|
raise ValueError(msg)
|
|
1292
1292
|
return FakeToolCallingModel(tool_calls=[])
|
|
1293
1293
|
|
|
1294
|
-
agent =
|
|
1294
|
+
agent = create_agent(failing_dynamic_model, [])
|
|
1295
1295
|
|
|
1296
1296
|
# Normal operation should work
|
|
1297
1297
|
result = agent.invoke({"messages": [HumanMessage("hello")]})
|
|
@@ -1306,13 +1306,13 @@ def test_dynamic_model_vs_static_model_behavior() -> None:
|
|
|
1306
1306
|
"""Test that dynamic and static models produce equivalent results when configured the same."""
|
|
1307
1307
|
# Static model
|
|
1308
1308
|
static_model = FakeToolCallingModel(tool_calls=[])
|
|
1309
|
-
static_agent =
|
|
1309
|
+
static_agent = create_agent(static_model, [])
|
|
1310
1310
|
|
|
1311
1311
|
# Dynamic model returning the same model
|
|
1312
1312
|
def dynamic_model(state, runtime: Runtime):
|
|
1313
1313
|
return FakeToolCallingModel(tool_calls=[])
|
|
1314
1314
|
|
|
1315
|
-
dynamic_agent =
|
|
1315
|
+
dynamic_agent = create_agent(dynamic_model, [])
|
|
1316
1316
|
|
|
1317
1317
|
input_msg = {"messages": [HumanMessage("test message")]}
|
|
1318
1318
|
|
|
@@ -1337,7 +1337,7 @@ def test_dynamic_model_receives_correct_state() -> None:
|
|
|
1337
1337
|
received_states.append(state)
|
|
1338
1338
|
return FakeToolCallingModel(tool_calls=[])
|
|
1339
1339
|
|
|
1340
|
-
agent =
|
|
1340
|
+
agent = create_agent(dynamic_model, [], state_schema=CustomAgentState)
|
|
1341
1341
|
|
|
1342
1342
|
# Test with initial state
|
|
1343
1343
|
input_state = {"messages": [HumanMessage("hello")], "custom_field": "test_value"}
|
|
@@ -1368,7 +1368,7 @@ async def test_dynamic_model_receives_correct_state_async() -> None:
|
|
|
1368
1368
|
received_states.append(state)
|
|
1369
1369
|
return FakeToolCallingModel(tool_calls=[])
|
|
1370
1370
|
|
|
1371
|
-
agent =
|
|
1371
|
+
agent = create_agent(dynamic_model, [], state_schema=CustomAgentStateAsync)
|
|
1372
1372
|
|
|
1373
1373
|
# Test with initial state
|
|
1374
1374
|
input_state = {
|
|
@@ -1397,7 +1397,7 @@ def test_pre_model_hook() -> None:
|
|
|
1397
1397
|
def pre_model_hook(state: AgentState):
|
|
1398
1398
|
return {"llm_input_messages": [HumanMessage("Hello!")]}
|
|
1399
1399
|
|
|
1400
|
-
agent =
|
|
1400
|
+
agent = create_agent(model, [], pre_model_hook=pre_model_hook)
|
|
1401
1401
|
assert "pre_model_hook" in agent.nodes
|
|
1402
1402
|
result = agent.invoke({"messages": [HumanMessage("hi?")]})
|
|
1403
1403
|
assert result == {
|
|
@@ -1411,7 +1411,7 @@ def test_pre_model_hook() -> None:
|
|
|
1411
1411
|
def pre_model_hook(state: AgentState):
|
|
1412
1412
|
return {"messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES), HumanMessage("Hello!")]}
|
|
1413
1413
|
|
|
1414
|
-
agent =
|
|
1414
|
+
agent = create_agent(model, [], pre_model_hook=pre_model_hook)
|
|
1415
1415
|
result = agent.invoke({"messages": [HumanMessage("hi?")]})
|
|
1416
1416
|
assert result == {
|
|
1417
1417
|
"messages": [
|
|
@@ -1430,9 +1430,7 @@ def test_post_model_hook() -> None:
|
|
|
1430
1430
|
def post_model_hook(state: FlagState) -> dict[str, bool]:
|
|
1431
1431
|
return {"flag": True}
|
|
1432
1432
|
|
|
1433
|
-
pmh_agent =
|
|
1434
|
-
model, [], post_model_hook=post_model_hook, state_schema=FlagState
|
|
1435
|
-
)
|
|
1433
|
+
pmh_agent = create_agent(model, [], post_model_hook=post_model_hook, state_schema=FlagState)
|
|
1436
1434
|
|
|
1437
1435
|
assert "post_model_hook" in pmh_agent.nodes
|
|
1438
1436
|
|
|
@@ -1480,7 +1478,7 @@ def test_post_model_hook_with_structured_output() -> None:
|
|
|
1480
1478
|
return {"flag": True}
|
|
1481
1479
|
|
|
1482
1480
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
1483
|
-
agent =
|
|
1481
|
+
agent = create_agent(
|
|
1484
1482
|
model,
|
|
1485
1483
|
[get_weather],
|
|
1486
1484
|
response_format=WeatherResponse,
|
|
@@ -1496,7 +1494,7 @@ def test_post_model_hook_with_structured_output() -> None:
|
|
|
1496
1494
|
|
|
1497
1495
|
# Reset the state of the model
|
|
1498
1496
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
1499
|
-
agent =
|
|
1497
|
+
agent = create_agent(
|
|
1500
1498
|
model,
|
|
1501
1499
|
[get_weather],
|
|
1502
1500
|
response_format=WeatherResponse,
|
|
@@ -1568,7 +1566,7 @@ def test_post_model_hook_with_structured_output() -> None:
|
|
|
1568
1566
|
]
|
|
1569
1567
|
|
|
1570
1568
|
|
|
1571
|
-
def
|
|
1569
|
+
def test_create_agent_inject_vars_with_post_model_hook() -> None:
|
|
1572
1570
|
store = InMemoryStore()
|
|
1573
1571
|
namespace = ("test",)
|
|
1574
1572
|
store.put(namespace, "test_key", {"bar": 3})
|
|
@@ -1594,7 +1592,7 @@ def test_create_react_agent_inject_vars_with_post_model_hook() -> None:
|
|
|
1594
1592
|
return {"foo": 2}
|
|
1595
1593
|
|
|
1596
1594
|
model = FakeToolCallingModel(tool_calls=[[tool_call], []])
|
|
1597
|
-
agent =
|
|
1595
|
+
agent = create_agent(
|
|
1598
1596
|
model,
|
|
1599
1597
|
ToolNode([tool1], handle_tool_errors=False),
|
|
1600
1598
|
state_schema=AgentStateExtraKey,
|
|
@@ -1629,7 +1627,7 @@ def test_response_format_using_tool_choice() -> None:
|
|
|
1629
1627
|
|
|
1630
1628
|
expected_structured_response = WeatherResponse(temperature=75)
|
|
1631
1629
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
1632
|
-
agent =
|
|
1630
|
+
agent = create_agent(
|
|
1633
1631
|
model,
|
|
1634
1632
|
[get_weather],
|
|
1635
1633
|
response_format=WeatherResponse,
|
|
@@ -5,7 +5,7 @@ import pytest
|
|
|
5
5
|
from pydantic import BaseModel
|
|
6
6
|
from syrupy.assertion import SnapshotAssertion
|
|
7
7
|
|
|
8
|
-
from langchain.agents import
|
|
8
|
+
from langchain.agents import create_agent
|
|
9
9
|
|
|
10
10
|
from .model import FakeToolCallingModel
|
|
11
11
|
|
|
@@ -39,7 +39,7 @@ def test_react_agent_graph_structure(
|
|
|
39
39
|
pre_model_hook: Union[Callable, None],
|
|
40
40
|
post_model_hook: Union[Callable, None],
|
|
41
41
|
) -> None:
|
|
42
|
-
agent =
|
|
42
|
+
agent = create_agent(
|
|
43
43
|
model,
|
|
44
44
|
tools=tools,
|
|
45
45
|
pre_model_hook=pre_model_hook,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Test suite for
|
|
1
|
+
"""Test suite for create_agent with structured output response_format permutations."""
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ from dataclasses import dataclass
|
|
|
6
6
|
from typing import Union
|
|
7
7
|
|
|
8
8
|
from langchain_core.messages import HumanMessage
|
|
9
|
-
from langchain.agents import
|
|
9
|
+
from langchain.agents import create_agent
|
|
10
10
|
from langchain.agents.structured_output import (
|
|
11
11
|
MultipleStructuredOutputsError,
|
|
12
12
|
ProviderStrategy,
|
|
@@ -114,7 +114,7 @@ class TestResponseFormatAsModel:
|
|
|
114
114
|
|
|
115
115
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
116
116
|
|
|
117
|
-
agent =
|
|
117
|
+
agent = create_agent(model, [get_weather], response_format=WeatherBaseModel)
|
|
118
118
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
119
119
|
|
|
120
120
|
assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC
|
|
@@ -135,7 +135,7 @@ class TestResponseFormatAsModel:
|
|
|
135
135
|
|
|
136
136
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
137
137
|
|
|
138
|
-
agent =
|
|
138
|
+
agent = create_agent(model, [get_weather], response_format=WeatherDataclass)
|
|
139
139
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
140
140
|
|
|
141
141
|
assert response["structured_response"] == EXPECTED_WEATHER_DATACLASS
|
|
@@ -156,7 +156,7 @@ class TestResponseFormatAsModel:
|
|
|
156
156
|
|
|
157
157
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
158
158
|
|
|
159
|
-
agent =
|
|
159
|
+
agent = create_agent(model, [get_weather], response_format=WeatherTypedDict)
|
|
160
160
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
161
161
|
|
|
162
162
|
assert response["structured_response"] == EXPECTED_WEATHER_DICT
|
|
@@ -177,7 +177,7 @@ class TestResponseFormatAsModel:
|
|
|
177
177
|
|
|
178
178
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
179
179
|
|
|
180
|
-
agent =
|
|
180
|
+
agent = create_agent(model, [get_weather], response_format=weather_json_schema)
|
|
181
181
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
182
182
|
|
|
183
183
|
assert response["structured_response"] == EXPECTED_WEATHER_DICT
|
|
@@ -200,9 +200,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
200
200
|
|
|
201
201
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
202
202
|
|
|
203
|
-
agent =
|
|
204
|
-
model, [get_weather], response_format=ToolStrategy(WeatherBaseModel)
|
|
205
|
-
)
|
|
203
|
+
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherBaseModel))
|
|
206
204
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
207
205
|
|
|
208
206
|
assert response["structured_response"] == EXPECTED_WEATHER_PYDANTIC
|
|
@@ -223,9 +221,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
223
221
|
|
|
224
222
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
225
223
|
|
|
226
|
-
agent =
|
|
227
|
-
model, [get_weather], response_format=ToolStrategy(WeatherDataclass)
|
|
228
|
-
)
|
|
224
|
+
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherDataclass))
|
|
229
225
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
230
226
|
|
|
231
227
|
assert response["structured_response"] == EXPECTED_WEATHER_DATACLASS
|
|
@@ -246,9 +242,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
246
242
|
|
|
247
243
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
248
244
|
|
|
249
|
-
agent =
|
|
250
|
-
model, [get_weather], response_format=ToolStrategy(WeatherTypedDict)
|
|
251
|
-
)
|
|
245
|
+
agent = create_agent(model, [get_weather], response_format=ToolStrategy(WeatherTypedDict))
|
|
252
246
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
253
247
|
|
|
254
248
|
assert response["structured_response"] == EXPECTED_WEATHER_DICT
|
|
@@ -269,7 +263,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
269
263
|
|
|
270
264
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
271
265
|
|
|
272
|
-
agent =
|
|
266
|
+
agent = create_agent(
|
|
273
267
|
model, [get_weather], response_format=ToolStrategy(weather_json_schema)
|
|
274
268
|
)
|
|
275
269
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
@@ -292,7 +286,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
292
286
|
|
|
293
287
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
294
288
|
|
|
295
|
-
agent =
|
|
289
|
+
agent = create_agent(
|
|
296
290
|
model,
|
|
297
291
|
[get_weather, get_location],
|
|
298
292
|
response_format=ToolStrategy({"oneOf": [weather_json_schema, location_json_schema]}),
|
|
@@ -316,7 +310,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
316
310
|
|
|
317
311
|
model_location = FakeToolCallingModel(tool_calls=tool_calls_location)
|
|
318
312
|
|
|
319
|
-
agent_location =
|
|
313
|
+
agent_location = create_agent(
|
|
320
314
|
model_location,
|
|
321
315
|
[get_weather, get_location],
|
|
322
316
|
response_format=ToolStrategy({"oneOf": [weather_json_schema, location_json_schema]}),
|
|
@@ -344,7 +338,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
344
338
|
tool_calls=tool_calls
|
|
345
339
|
)
|
|
346
340
|
|
|
347
|
-
agent =
|
|
341
|
+
agent = create_agent(
|
|
348
342
|
model,
|
|
349
343
|
[get_weather, get_location],
|
|
350
344
|
response_format=ToolStrategy(Union[WeatherBaseModel, LocationResponse]),
|
|
@@ -368,7 +362,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
368
362
|
|
|
369
363
|
model_location = FakeToolCallingModel(tool_calls=tool_calls_location)
|
|
370
364
|
|
|
371
|
-
agent_location =
|
|
365
|
+
agent_location = create_agent(
|
|
372
366
|
model_location,
|
|
373
367
|
[get_weather, get_location],
|
|
374
368
|
response_format=ToolStrategy(Union[WeatherBaseModel, LocationResponse]),
|
|
@@ -397,7 +391,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
397
391
|
|
|
398
392
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
399
393
|
|
|
400
|
-
agent =
|
|
394
|
+
agent = create_agent(
|
|
401
395
|
model,
|
|
402
396
|
[],
|
|
403
397
|
response_format=ToolStrategy(
|
|
@@ -438,7 +432,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
438
432
|
|
|
439
433
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
440
434
|
|
|
441
|
-
agent =
|
|
435
|
+
agent = create_agent(
|
|
442
436
|
model,
|
|
443
437
|
[],
|
|
444
438
|
response_format=ToolStrategy(
|
|
@@ -467,7 +461,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
467
461
|
|
|
468
462
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
469
463
|
|
|
470
|
-
agent =
|
|
464
|
+
agent = create_agent(
|
|
471
465
|
model,
|
|
472
466
|
[],
|
|
473
467
|
response_format=ToolStrategy(
|
|
@@ -503,7 +497,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
503
497
|
|
|
504
498
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
505
499
|
|
|
506
|
-
agent =
|
|
500
|
+
agent = create_agent(
|
|
507
501
|
model,
|
|
508
502
|
[],
|
|
509
503
|
response_format=ToolStrategy(
|
|
@@ -549,7 +543,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
549
543
|
return "Custom error: Multiple outputs not allowed"
|
|
550
544
|
return "Custom error"
|
|
551
545
|
|
|
552
|
-
agent =
|
|
546
|
+
agent = create_agent(
|
|
553
547
|
model,
|
|
554
548
|
[],
|
|
555
549
|
response_format=ToolStrategy(
|
|
@@ -587,7 +581,7 @@ class TestResponseFormatAsToolStrategy:
|
|
|
587
581
|
|
|
588
582
|
model = FakeToolCallingModel(tool_calls=tool_calls)
|
|
589
583
|
|
|
590
|
-
agent =
|
|
584
|
+
agent = create_agent(
|
|
591
585
|
model,
|
|
592
586
|
[],
|
|
593
587
|
response_format=ToolStrategy(
|
|
@@ -617,7 +611,7 @@ class TestResponseFormatAsProviderStrategy:
|
|
|
617
611
|
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_PYDANTIC
|
|
618
612
|
)
|
|
619
613
|
|
|
620
|
-
agent =
|
|
614
|
+
agent = create_agent(
|
|
621
615
|
model, [get_weather], response_format=ProviderStrategy(WeatherBaseModel)
|
|
622
616
|
)
|
|
623
617
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
@@ -635,7 +629,7 @@ class TestResponseFormatAsProviderStrategy:
|
|
|
635
629
|
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DATACLASS
|
|
636
630
|
)
|
|
637
631
|
|
|
638
|
-
agent =
|
|
632
|
+
agent = create_agent(
|
|
639
633
|
model, [get_weather], response_format=ProviderStrategy(WeatherDataclass)
|
|
640
634
|
)
|
|
641
635
|
response = agent.invoke(
|
|
@@ -655,7 +649,7 @@ class TestResponseFormatAsProviderStrategy:
|
|
|
655
649
|
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DICT
|
|
656
650
|
)
|
|
657
651
|
|
|
658
|
-
agent =
|
|
652
|
+
agent = create_agent(
|
|
659
653
|
model, [get_weather], response_format=ProviderStrategy(WeatherTypedDict)
|
|
660
654
|
)
|
|
661
655
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
@@ -673,7 +667,7 @@ class TestResponseFormatAsProviderStrategy:
|
|
|
673
667
|
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_DICT
|
|
674
668
|
)
|
|
675
669
|
|
|
676
|
-
agent =
|
|
670
|
+
agent = create_agent(
|
|
677
671
|
model, [get_weather], response_format=ProviderStrategy(weather_json_schema)
|
|
678
672
|
)
|
|
679
673
|
response = agent.invoke({"messages": [HumanMessage("What's the weather?")]})
|
|
@@ -699,7 +693,7 @@ def test_union_of_types() -> None:
|
|
|
699
693
|
tool_calls=tool_calls, structured_response=EXPECTED_WEATHER_PYDANTIC
|
|
700
694
|
)
|
|
701
695
|
|
|
702
|
-
agent =
|
|
696
|
+
agent = create_agent(
|
|
703
697
|
model,
|
|
704
698
|
[get_weather, get_location],
|
|
705
699
|
response_format=ToolStrategy(Union[WeatherBaseModel, LocationResponse]),
|
|
@@ -71,14 +71,14 @@ def test_return_direct_integration_matrix(case: TestCase) -> None:
|
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
if case.response_format:
|
|
74
|
-
agent =
|
|
74
|
+
agent = create_agent(
|
|
75
75
|
model,
|
|
76
76
|
tools=[poll_tool["tool"]],
|
|
77
77
|
prompt=AGENT_PROMPT,
|
|
78
78
|
response_format=ToolStrategy(case.response_format),
|
|
79
79
|
)
|
|
80
80
|
else:
|
|
81
|
-
agent =
|
|
81
|
+
agent = create_agent(
|
|
82
82
|
model,
|
|
83
83
|
tools=[poll_tool["tool"]],
|
|
84
84
|
prompt=AGENT_PROMPT,
|
|
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
|
|
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.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/specifications/responses.json
RENAMED
|
File without changes
|
{langchain-1.0.0a2 → langchain-1.0.0a3}/tests/unit_tests/agents/specifications/return_direct.json
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
|