2023-05-14 04:47:10 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from tempfile import TemporaryDirectory
|
|
|
|
|
|
|
|
from langchain.agents.agent_types import AgentType
|
|
|
|
from langchain.agents.initialize import initialize_agent, load_agent
|
2023-06-17 18:00:35 +00:00
|
|
|
from langchain.agents.tools import Tool
|
2023-05-14 04:47:10 +00:00
|
|
|
from langchain.llms.fake import FakeListLLM
|
|
|
|
|
|
|
|
|
|
|
|
def test_mrkl_serialization() -> None:
|
|
|
|
agent = initialize_agent(
|
2023-06-17 18:00:35 +00:00
|
|
|
[
|
|
|
|
Tool(
|
|
|
|
name="Test tool",
|
|
|
|
func=lambda x: x,
|
|
|
|
description="Test description",
|
|
|
|
)
|
|
|
|
],
|
2023-05-14 04:47:10 +00:00
|
|
|
FakeListLLM(responses=[]),
|
|
|
|
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
|
|
|
verbose=True,
|
|
|
|
)
|
|
|
|
with TemporaryDirectory() as tempdir:
|
|
|
|
file = Path(tempdir) / "agent.json"
|
|
|
|
agent.save_agent(file)
|
|
|
|
load_agent(file)
|