save() — langchain Function Reference
Architecture documentation for the save() function in agent.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6["save()"] 2066c331_3189_1880_ba09_f5a3c375c553["BaseSingleActionAgent"] 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 -->|defined in| 2066c331_3189_1880_ba09_f5a3c375c553 10a43326_6487_3430_716b_2f50b7e5d0b6["save_agent()"] 10a43326_6487_3430_716b_2f50b7e5d0b6 -->|calls| 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 7e22a32a_d4cd_934d_79bf_5d7579310aae["dict()"] 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 -->|calls| 7e22a32a_d4cd_934d_79bf_5d7579310aae 257c3f1d_0639_2e4e_fd2a_a566e69f1c1d["save()"] 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 -->|calls| 257c3f1d_0639_2e4e_fd2a_a566e69f1c1d style 008c369d_f4fc_8ebd_1976_f8b1ae09e0b6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/agent.py lines 182–214
def save(self, file_path: Path | str) -> None:
"""Save the agent.
Args:
file_path: Path to file to save the agent to.
Example:
```python
# If working with agent executor
agent.agent.save(file_path="path/agent.yaml")
```
"""
# Convert file to Path object.
save_path = Path(file_path) if isinstance(file_path, str) else file_path
directory_path = save_path.parent
directory_path.mkdir(parents=True, exist_ok=True)
# Fetch dictionary to save
agent_dict = self.dict()
if "_type" not in agent_dict:
msg = f"Agent {self} does not support saving"
raise NotImplementedError(msg)
if save_path.suffix == ".json":
with save_path.open("w") as f:
json.dump(agent_dict, f, indent=4)
elif save_path.suffix.endswith((".yaml", ".yml")):
with save_path.open("w") as f:
yaml.dump(agent_dict, f, default_flow_style=False)
else:
msg = f"{save_path} must be json or yaml"
raise ValueError(msg)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does save() do?
save() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/agent.py.
Where is save() defined?
save() is defined in libs/langchain/langchain_classic/agents/agent.py at line 182.
What does save() call?
save() calls 2 function(s): dict, save.
What calls save()?
save() is called by 1 function(s): save_agent.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free