This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.tools import ToolRuntime | |
| from typing_extensions import TypedDict | |
| from langchain.agents import create_agent | |
| from langchain.agents.middleware.model_call_limit import ( | |
| ModelCallLimitMiddleware, | |
| ModelCallLimitExceededError, | |
| ) | |
| from langchain_core.tools import tool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.agents import create_agent | |
| from langchain.agents.middleware import SummarizationMiddleware | |
| from langchain_community.retrievers import WikipediaRetriever | |
| from langchain_core.tools import tool | |
| retriever = WikipediaRetriever( # type: ignore | |
| top_k_results=1, | |
| doc_content_chars_max=20_000, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.agents import create_agent | |
| from langchain.agents.middleware import ModelFallbackMiddleware | |
| agent = create_agent( | |
| # simulate model failure w/ a typo in the model name (404) | |
| model="anthropic:claude-sonnet-with-typo", | |
| middleware=[ | |
| ModelFallbackMiddleware("openai:gpt-4o-with-typo", "openai:gpt-4o-mini") | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| import tempfile | |
| from langchain.agents import create_agent | |
| from langchain.agents.middleware import TodoListMiddleware | |
| from langchain_core.tools import tool | |
| @tool(parse_docstring=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.agents import create_agent | |
| from langchain.agents.middleware import ToolCallLimitMiddleware | |
| from langchain_core.tools import tool | |
| @tool(parse_docstring=True) | |
| def search_items(query: str) -> str: | |
| """Search for items in the store. | |
| Args: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from langchain.agents import create_agent | |
| from langchain_core.tools import tool | |
| from langchain.agents.middleware import HumanInTheLoopMiddleware | |
| @tool(parse_docstring=True) | |
| def send_email(recipient: str, subject: str, body: str) -> str: | |
| """Send an email to a recipient. | |
| Args: |