a7d6d88f6f
CI / changes (push) Has been cancelled
CI / cd libs/checkpoint (push) Has been cancelled
CI / cd libs/checkpoint-conformance (push) Has been cancelled
CI / cd libs/checkpoint-postgres (push) Has been cancelled
CI / cd libs/checkpoint-sqlite (push) Has been cancelled
CI / cd libs/cli (push) Has been cancelled
CI / cd libs/prebuilt (push) Has been cancelled
CI / cd libs/sdk-py (push) Has been cancelled
CI / cd libs/langgraph (push) Has been cancelled
CI / Check SDK methods matching (push) Has been cancelled
CI / Check CLI schema hasn't changed #3.13 (push) Has been cancelled
CI / CLI integration test (push) Has been cancelled
CI / sdk-py integration test (push) Has been cancelled
CI / CI Success (push) Has been cancelled
baseline / benchmark (push) Has been cancelled
Deploy Redirects to GitHub Pages / deploy (push) Has been cancelled
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
from collections.abc import Callable
|
|
|
|
import pytest
|
|
from pydantic import BaseModel
|
|
from syrupy import SnapshotAssertion
|
|
|
|
from langgraph.prebuilt import create_react_agent
|
|
from tests.model import FakeToolCallingModel
|
|
|
|
model = FakeToolCallingModel()
|
|
|
|
|
|
def tool() -> None:
|
|
"""Testing tool."""
|
|
...
|
|
|
|
|
|
def pre_model_hook() -> None:
|
|
"""Pre-model hook."""
|
|
...
|
|
|
|
|
|
def post_model_hook() -> None:
|
|
"""Post-model hook."""
|
|
...
|
|
|
|
|
|
class ResponseFormat(BaseModel):
|
|
"""Response format for the agent."""
|
|
|
|
result: str
|
|
|
|
|
|
@pytest.mark.parametrize("tools", [[], [tool]])
|
|
@pytest.mark.parametrize("pre_model_hook", [None, pre_model_hook])
|
|
@pytest.mark.parametrize("post_model_hook", [None, post_model_hook])
|
|
@pytest.mark.parametrize("response_format", [None, ResponseFormat])
|
|
def test_react_agent_graph_structure(
|
|
snapshot: SnapshotAssertion,
|
|
tools: list[Callable],
|
|
pre_model_hook: Callable | None,
|
|
post_model_hook: Callable | None,
|
|
response_format: type[BaseModel] | None,
|
|
) -> None:
|
|
agent = create_react_agent(
|
|
model,
|
|
tools=tools,
|
|
pre_model_hook=pre_model_hook,
|
|
post_model_hook=post_model_hook,
|
|
response_format=response_format,
|
|
)
|
|
assert agent.get_graph().draw_mermaid(with_styles=False) == snapshot
|