diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.py index 8fbdf976a11..4bfcde68e0c 100644 --- a/libs/langchain/langchain/agents/agent.py +++ b/libs/langchain/langchain/agents/agent.py @@ -23,6 +23,14 @@ from typing import ( import yaml from langchain_core._api import deprecated from langchain_core.agents import AgentAction, AgentFinish, AgentStep +from langchain_core.callbacks import ( + AsyncCallbackManagerForChainRun, + AsyncCallbackManagerForToolRun, + BaseCallbackManager, + CallbackManagerForChainRun, + CallbackManagerForToolRun, + Callbacks, +) from langchain_core.exceptions import OutputParserException from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import BaseMessage @@ -39,14 +47,6 @@ from langchain_core.utils.input import get_color_mapping from langchain.agents.agent_iterator import AgentExecutorIterator from langchain.agents.agent_types import AgentType from langchain.agents.tools import InvalidTool -from langchain.callbacks.base import BaseCallbackManager -from langchain.callbacks.manager import ( - AsyncCallbackManagerForChainRun, - AsyncCallbackManagerForToolRun, - CallbackManagerForChainRun, - CallbackManagerForToolRun, - Callbacks, -) from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.utilities.asyncio import asyncio_timeout diff --git a/libs/langchain/langchain/agents/agent_iterator.py b/libs/langchain/langchain/agents/agent_iterator.py index 52b5bd2c1bc..12c995f2e97 100644 --- a/libs/langchain/langchain/agents/agent_iterator.py +++ b/libs/langchain/langchain/agents/agent_iterator.py @@ -20,20 +20,20 @@ from langchain_core.agents import ( AgentFinish, AgentStep, ) -from langchain_core.load.dump import dumpd -from langchain_core.outputs import RunInfo -from langchain_core.runnables.utils import AddableDict -from langchain_core.utils.input import get_color_mapping - -from langchain.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManager, AsyncCallbackManagerForChainRun, CallbackManager, CallbackManagerForChainRun, Callbacks, ) +from langchain_core.load.dump import dumpd +from langchain_core.outputs import RunInfo +from langchain_core.runnables.utils import AddableDict +from langchain_core.tools import BaseTool +from langchain_core.utils.input import get_color_mapping + from langchain.schema import RUN_KEY -from langchain.tools import BaseTool from langchain.utilities.asyncio import asyncio_timeout if TYPE_CHECKING: diff --git a/libs/langchain/langchain/agents/chat/base.py b/libs/langchain/langchain/agents/chat/base.py index 00a320a543c..ffd36852e1e 100644 --- a/libs/langchain/langchain/agents/chat/base.py +++ b/libs/langchain/langchain/agents/chat/base.py @@ -2,6 +2,7 @@ from typing import Any, List, Optional, Sequence, Tuple from langchain_core._api import deprecated from langchain_core.agents import AgentAction +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate from langchain_core.prompts.chat import ( @@ -21,7 +22,6 @@ from langchain.agents.chat.prompt import ( SYSTEM_MESSAGE_SUFFIX, ) from langchain.agents.utils import validate_tools_single_input -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/agents/conversational/base.py b/libs/langchain/langchain/agents/conversational/base.py index fcc03ad1be3..11e2fc12470 100644 --- a/libs/langchain/langchain/agents/conversational/base.py +++ b/libs/langchain/langchain/agents/conversational/base.py @@ -4,6 +4,7 @@ from __future__ import annotations from typing import Any, List, Optional, Sequence from langchain_core._api import deprecated +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import PromptTemplate from langchain_core.pydantic_v1 import Field @@ -14,7 +15,6 @@ from langchain.agents.agent_types import AgentType from langchain.agents.conversational.output_parser import ConvoOutputParser from langchain.agents.conversational.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX from langchain.agents.utils import validate_tools_single_input -from langchain.callbacks.base import BaseCallbackManager from langchain.chains import LLMChain diff --git a/libs/langchain/langchain/agents/conversational_chat/base.py b/libs/langchain/langchain/agents/conversational_chat/base.py index 00f0137cda0..8ee2218780b 100644 --- a/libs/langchain/langchain/agents/conversational_chat/base.py +++ b/libs/langchain/langchain/agents/conversational_chat/base.py @@ -5,6 +5,7 @@ from typing import Any, List, Optional, Sequence, Tuple from langchain_core._api import deprecated from langchain_core.agents import AgentAction +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.output_parsers import BaseOutputParser @@ -26,7 +27,6 @@ from langchain.agents.conversational_chat.prompt import ( TEMPLATE_TOOL_RESPONSE, ) from langchain.agents.utils import validate_tools_single_input -from langchain.callbacks.base import BaseCallbackManager from langchain.chains import LLMChain diff --git a/libs/langchain/langchain/agents/conversational_chat/output_parser.py b/libs/langchain/langchain/agents/conversational_chat/output_parser.py index 4265ee55334..46ccce6d571 100644 --- a/libs/langchain/langchain/agents/conversational_chat/output_parser.py +++ b/libs/langchain/langchain/agents/conversational_chat/output_parser.py @@ -4,10 +4,10 @@ from typing import Union from langchain_core.agents import AgentAction, AgentFinish from langchain_core.exceptions import OutputParserException +from langchain_core.output_parsers.json import parse_json_markdown from langchain.agents import AgentOutputParser from langchain.agents.conversational_chat.prompt import FORMAT_INSTRUCTIONS -from langchain.output_parsers.json import parse_json_markdown # Define a class that parses output for conversational agents diff --git a/libs/langchain/langchain/agents/initialize.py b/libs/langchain/langchain/agents/initialize.py index 65cfbd20039..890bc90e68f 100644 --- a/libs/langchain/langchain/agents/initialize.py +++ b/libs/langchain/langchain/agents/initialize.py @@ -2,13 +2,13 @@ from typing import Any, Optional, Sequence from langchain_core._api import deprecated +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.tools import BaseTool from langchain.agents.agent import AgentExecutor from langchain.agents.agent_types import AgentType from langchain.agents.loading import AGENT_TO_CLASS, load_agent -from langchain.callbacks.base import BaseCallbackManager @deprecated( diff --git a/libs/langchain/langchain/agents/load_tools.py b/libs/langchain/langchain/agents/load_tools.py index 192048b9fc1..ab3a34cfee7 100644 --- a/libs/langchain/langchain/agents/load_tools.py +++ b/libs/langchain/langchain/agents/load_tools.py @@ -18,10 +18,10 @@ import warnings from typing import Any, Dict, List, Optional, Callable, Tuple from mypy_extensions import Arg, KwArg -from langchain.agents.tools import Tool +from langchain_core.tools import Tool from langchain_core.language_models import BaseLanguageModel -from langchain.callbacks.base import BaseCallbackManager -from langchain.callbacks.manager import Callbacks +from langchain_core.callbacks import BaseCallbackManager +from langchain_core.callbacks import Callbacks from langchain.chains.api import news_docs, open_meteo_docs, podcast_docs, tmdb_docs from langchain.chains.api.base import APIChain from langchain.chains.llm_math.base import LLMMathChain diff --git a/libs/langchain/langchain/agents/loading.py b/libs/langchain/langchain/agents/loading.py index 28540fcfd4a..e1d9747df2d 100644 --- a/libs/langchain/langchain/agents/loading.py +++ b/libs/langchain/langchain/agents/loading.py @@ -7,10 +7,10 @@ from typing import Any, List, Optional, Union import yaml from langchain_core._api import deprecated from langchain_core.language_models import BaseLanguageModel +from langchain_core.tools import Tool from langchain_core.utils.loading import try_load_from_hub from langchain.agents.agent import BaseMultiActionAgent, BaseSingleActionAgent -from langchain.agents.tools import Tool from langchain.agents.types import AGENT_TO_CLASS from langchain.chains.loading import load_chain, load_chain_from_config diff --git a/libs/langchain/langchain/agents/mrkl/base.py b/libs/langchain/langchain/agents/mrkl/base.py index 51e3ef2dbae..406390d3f8e 100644 --- a/libs/langchain/langchain/agents/mrkl/base.py +++ b/libs/langchain/langchain/agents/mrkl/base.py @@ -4,6 +4,7 @@ from __future__ import annotations from typing import Any, Callable, List, NamedTuple, Optional, Sequence from langchain_core._api import deprecated +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import PromptTemplate from langchain_core.pydantic_v1 import Field @@ -15,7 +16,6 @@ from langchain.agents.mrkl.output_parser import MRKLOutputParser from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX from langchain.agents.tools import Tool from langchain.agents.utils import validate_tools_single_input -from langchain.callbacks.base import BaseCallbackManager from langchain.chains import LLMChain diff --git a/libs/langchain/langchain/agents/openai_assistant/base.py b/libs/langchain/langchain/agents/openai_assistant/base.py index 498957ad8bc..84d99c8f97e 100644 --- a/libs/langchain/langchain/agents/openai_assistant/base.py +++ b/libs/langchain/langchain/agents/openai_assistant/base.py @@ -7,13 +7,12 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Un from langchain_community.tools.convert_to_openai import format_tool_to_openai_tool from langchain_core.agents import AgentAction, AgentFinish +from langchain_core.callbacks import CallbackManager from langchain_core.load import dumpd from langchain_core.pydantic_v1 import Field from langchain_core.runnables import RunnableConfig, RunnableSerializable, ensure_config from langchain_core.tools import BaseTool -from langchain.callbacks.manager import CallbackManager - if TYPE_CHECKING: import openai from openai.types.beta.threads import ThreadMessage diff --git a/libs/langchain/langchain/agents/openai_functions_agent/base.py b/libs/langchain/langchain/agents/openai_functions_agent/base.py index 1d486dc6856..e0180693202 100644 --- a/libs/langchain/langchain/agents/openai_functions_agent/base.py +++ b/libs/langchain/langchain/agents/openai_functions_agent/base.py @@ -4,6 +4,7 @@ from typing import Any, List, Optional, Sequence, Tuple, Type, Union from langchain_community.tools.convert_to_openai import format_tool_to_openai_function from langchain_core._api import deprecated from langchain_core.agents import AgentAction, AgentFinish +from langchain_core.callbacks import BaseCallbackManager, Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import ( BaseMessage, @@ -27,8 +28,6 @@ from langchain.agents.format_scratchpad.openai_functions import ( from langchain.agents.output_parsers.openai_functions import ( OpenAIFunctionsAgentOutputParser, ) -from langchain.callbacks.base import BaseCallbackManager -from langchain.callbacks.manager import Callbacks @deprecated("0.1.0", alternative="create_openai_functions_agent", removal="0.2.0") diff --git a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py index 168f852c591..03d804c60fd 100644 --- a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py +++ b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py @@ -5,6 +5,7 @@ from typing import Any, List, Optional, Sequence, Tuple, Union from langchain_core._api import deprecated from langchain_core.agents import AgentAction, AgentActionMessageLog, AgentFinish +from langchain_core.callbacks import BaseCallbackManager, Callbacks from langchain_core.exceptions import OutputParserException from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import ( @@ -20,14 +21,12 @@ from langchain_core.prompts.chat import ( MessagesPlaceholder, ) from langchain_core.pydantic_v1 import root_validator +from langchain_core.tools import BaseTool from langchain.agents import BaseMultiActionAgent from langchain.agents.format_scratchpad.openai_functions import ( format_to_openai_function_messages, ) -from langchain.callbacks.base import BaseCallbackManager -from langchain.callbacks.manager import Callbacks -from langchain.tools import BaseTool # For backwards compatibility _FunctionsAgentAction = AgentActionMessageLog diff --git a/libs/langchain/langchain/agents/output_parsers/json.py b/libs/langchain/langchain/agents/output_parsers/json.py index 5fa543ea9df..2dbc56178ff 100644 --- a/libs/langchain/langchain/agents/output_parsers/json.py +++ b/libs/langchain/langchain/agents/output_parsers/json.py @@ -5,9 +5,9 @@ from typing import Union from langchain_core.agents import AgentAction, AgentFinish from langchain_core.exceptions import OutputParserException +from langchain_core.output_parsers.json import parse_json_markdown from langchain.agents.agent import AgentOutputParser -from langchain.output_parsers.json import parse_json_markdown logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/agents/react/base.py b/libs/langchain/langchain/agents/react/base.py index fba742ac458..437eb80e720 100644 --- a/libs/langchain/langchain/agents/react/base.py +++ b/libs/langchain/langchain/agents/react/base.py @@ -6,14 +6,13 @@ from langchain_core.documents import Document from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate from langchain_core.pydantic_v1 import Field -from langchain_core.tools import BaseTool +from langchain_core.tools import BaseTool, Tool from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser from langchain.agents.agent_types import AgentType from langchain.agents.react.output_parser import ReActOutputParser from langchain.agents.react.textworld_prompt import TEXTWORLD_PROMPT from langchain.agents.react.wiki_prompt import WIKI_PROMPT -from langchain.agents.tools import Tool from langchain.agents.utils import validate_tools_single_input from langchain.docstore.base import Docstore diff --git a/libs/langchain/langchain/agents/self_ask_with_search/base.py b/libs/langchain/langchain/agents/self_ask_with_search/base.py index 9df14cb4335..d7526f4c548 100644 --- a/libs/langchain/langchain/agents/self_ask_with_search/base.py +++ b/libs/langchain/langchain/agents/self_ask_with_search/base.py @@ -9,14 +9,13 @@ from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate from langchain_core.pydantic_v1 import Field from langchain_core.runnables import Runnable, RunnablePassthrough -from langchain_core.tools import BaseTool +from langchain_core.tools import BaseTool, Tool from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser from langchain.agents.agent_types import AgentType from langchain.agents.format_scratchpad import format_log_to_str from langchain.agents.self_ask_with_search.output_parser import SelfAskOutputParser from langchain.agents.self_ask_with_search.prompt import PROMPT -from langchain.agents.tools import Tool from langchain.agents.utils import validate_tools_single_input diff --git a/libs/langchain/langchain/agents/structured_chat/base.py b/libs/langchain/langchain/agents/structured_chat/base.py index 53e11b33c01..ef037860d3c 100644 --- a/libs/langchain/langchain/agents/structured_chat/base.py +++ b/libs/langchain/langchain/agents/structured_chat/base.py @@ -3,6 +3,7 @@ from typing import Any, List, Optional, Sequence, Tuple from langchain_core._api import deprecated from langchain_core.agents import AgentAction +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate from langchain_core.prompts.chat import ( @@ -12,6 +13,7 @@ from langchain_core.prompts.chat import ( ) from langchain_core.pydantic_v1 import Field from langchain_core.runnables import Runnable, RunnablePassthrough +from langchain_core.tools import BaseTool from langchain.agents.agent import Agent, AgentOutputParser from langchain.agents.format_scratchpad import format_log_to_str @@ -20,9 +22,7 @@ from langchain.agents.structured_chat.output_parser import ( StructuredChatOutputParserWithRetries, ) from langchain.agents.structured_chat.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain -from langchain.tools import BaseTool from langchain.tools.render import render_text_description_and_args HUMAN_MESSAGE_TEMPLATE = "{input}\n\n{agent_scratchpad}" diff --git a/libs/langchain/langchain/agents/tools.py b/libs/langchain/langchain/agents/tools.py index aaf360afbc5..e804ab25025 100644 --- a/libs/langchain/langchain/agents/tools.py +++ b/libs/langchain/langchain/agents/tools.py @@ -1,12 +1,11 @@ """Interface for tools.""" from typing import List, Optional -from langchain_core.tools import BaseTool, Tool, tool - -from langchain.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) +from langchain_core.tools import BaseTool, Tool, tool class InvalidTool(BaseTool): diff --git a/libs/langchain/langchain/agents/xml/base.py b/libs/langchain/langchain/agents/xml/base.py index bd678979f74..be85a7b9738 100644 --- a/libs/langchain/langchain/agents/xml/base.py +++ b/libs/langchain/langchain/agents/xml/base.py @@ -2,6 +2,7 @@ from typing import Any, List, Sequence, Tuple, Union from langchain_core._api import deprecated from langchain_core.agents import AgentAction, AgentFinish +from langchain_core.callbacks import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts.base import BasePromptTemplate from langchain_core.prompts.chat import AIMessagePromptTemplate, ChatPromptTemplate @@ -12,7 +13,6 @@ from langchain.agents.agent import BaseSingleActionAgent from langchain.agents.format_scratchpad import format_xml from langchain.agents.output_parsers import XMLAgentOutputParser from langchain.agents.xml.prompt import agent_instructions -from langchain.callbacks.base import Callbacks from langchain.chains.llm import LLMChain from langchain.tools.render import render_text_description