langchain/libs/community/langchain_community/tools
ccurme 975b6129f6
core[patch]: support conversion of runnables to tools (#23992)
Open to other thoughts on UX.

string input:
```python
as_tool = retriever.as_tool()
as_tool.invoke("cat")  # [Document(...), ...]
```

typed dict input:
```python
class Args(TypedDict):
    key: int

def f(x: Args) -> str:
    return str(x["key"] * 2)

as_tool = RunnableLambda(f).as_tool(
    name="my tool",
    description="description",  # name, description are inferred if not supplied
)
as_tool.invoke({"key": 3})  # "6"
```

for untyped dict input, allow specification of parameters + types
```python
def g(x: Dict[str, Any]) -> str:
    return str(x["key"] * 2)

as_tool = RunnableLambda(g).as_tool(arg_types={"key": int})
result = as_tool.invoke({"key": 3})  # "6"
```

Passing the `arg_types` is slightly awkward but necessary to ensure tool
calls populate parameters correctly:
```python
from typing import Any, Dict

from langchain_core.runnables import RunnableLambda
from langchain_openai import ChatOpenAI


def f(x: Dict[str, Any]) -> str:
    return str(x["key"] * 2)

runnable = RunnableLambda(f)
as_tool = runnable.as_tool(arg_types={"key": int})

llm = ChatOpenAI().bind_tools([as_tool])

result = llm.invoke("Use the tool on 3.")
tool_call = result.tool_calls[0]
args = tool_call["args"]
assert args == {"key": 3}

as_tool.run(args)
```

Contrived (?) example with langgraph agent as a tool:
```python
from typing import List, Literal
from typing_extensions import TypedDict

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent


llm = ChatOpenAI(temperature=0)


def magic_function(input: int) -> int:
    """Applies a magic function to an input."""
    return input + 2


agent_1 = create_react_agent(llm, [magic_function])


class Message(TypedDict):
    role: Literal["human"]
    content: str

agent_tool = agent_1.as_tool(
    arg_types={"messages": List[Message]},
    name="Jeeves",
    description="Ask Jeeves.",
)

agent_2 = create_react_agent(llm, [agent_tool])
```

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2024-07-10 19:29:59 -04:00
..
ainetwork infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
amadeus infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
arxiv community: Standardise tool import for arxiv & semantic scholar (#23578) 2024-06-27 16:35:50 -04:00
asknews community[minor]: add AskNews retriever and AskNews tool (#21581) 2024-05-20 18:23:06 -07:00
audio community[patch]: Add missing type annotations (#22758) 2024-06-10 16:59:28 -04:00
azure_ai_services community[minor]: Update Azure Cognitive Services to Azure AI Services (#19488) 2024-03-28 03:19:02 +00:00
azure_cognitive_services docs: docstrings langchain_community update (#14889) 2023-12-19 08:58:24 -05:00
bearly infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
bing_search community[patch]: Update bing results tool name (#16395) 2024-01-22 11:11:03 -08:00
brave_search community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
cassandra_database infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
clickup infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
cogniswitch community[patch]: Add missing type annotations (#22758) 2024-06-10 16:59:28 -04:00
connery community[patch]: Update root_validators to use explicit pre=True or pre=False (#23736) 2024-07-01 17:13:23 -04:00
databricks community: support Databricks Unity Catalog functions as LangChain tools (#22555) 2024-06-06 09:38:50 -07:00
dataforseo_api_search community[patch]: Fixed tool names snake_case (#16397) 2024-01-25 15:24:19 -08:00
dataherald infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
ddg_search [Community]: Fixed DDG DuckDuckGoSearchResults Docstring (#22968) 2024-06-18 03:16:24 +00:00
e2b_data_analysis core[patch]: support conversion of runnables to tools (#23992) 2024-07-10 19:29:59 -04:00
edenai community[patch]: Add linter to catch @root_validator (#24070) 2024-07-10 14:51:03 +00:00
eleven_labs community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
file_management community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
github infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
gitlab infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
gmail infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
golden_query infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
google_cloud (all): update removal in deprecation warnings from 0.2 to 0.3 (#21265) 2024-05-03 14:29:36 -04:00
google_finance community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
google_jobs community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
google_lens community[patch]: Fixed tool names snake_case (#16397) 2024-01-25 15:24:19 -08:00
google_places community[patch]: upgrade to recent version of mypy (#21616) 2024-05-13 14:55:07 -04:00
google_scholar community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
google_search (all): update removal in deprecation warnings from 0.2 to 0.3 (#21265) 2024-05-03 14:29:36 -04:00
google_serper community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
google_trends community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
graphql community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
human infra: add print rule to ruff (#16221) 2024-02-09 16:13:30 -08:00
interaction infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
jira community: add support for 'cloud' parameter in JiraAPIWrapper (#23057) 2024-07-05 15:11:10 +00:00
json infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
memorize infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
merriam_webster community[patch]: Fixed tool names snake_case (#16397) 2024-01-25 15:24:19 -08:00
metaphor_search (all): update removal in deprecation warnings from 0.2 to 0.3 (#21265) 2024-05-03 14:29:36 -04:00
mojeek_search community[minor]: add mojeek search util (#20922) 2024-04-29 15:49:53 +00:00
multion infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
nasa infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
nuclia multiple: get rid of pyproject extras (#22581) 2024-06-06 15:45:22 -07:00
office365 infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
openai_dalle_image_generation community[patch]: add Integration for OpenAI image gen with v1 sdk (#17771) 2024-03-29 00:23:14 +00:00
openapi infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
openweathermap infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
passio_nutrition_ai community[patch]: Add Passio Nutrition AI Food Search Tool to Community Package (#18278) 2024-03-08 20:33:22 +00:00
playwright community[patch]: Add linter to catch @root_validator (#24070) 2024-07-10 14:51:03 +00:00
polygon community: Add PolygonAggregates tool (#18882) 2024-03-11 11:58:10 -07:00
powerbi infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
pubmed community[patch]: upgrade to recent version of mypy (#21616) 2024-05-13 14:55:07 -04:00
reddit_search community[patch]: upgrade to recent version of mypy (#21616) 2024-05-13 14:55:07 -04:00
requests infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
scenexplain infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
searchapi community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
searx_search infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
semanticscholar community: Standardise tool import for arxiv & semantic scholar (#23578) 2024-06-27 16:35:50 -04:00
shell community[patch]: Add linter to catch @root_validator (#24070) 2024-07-10 14:51:03 +00:00
slack infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
sleep infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
spark_sql infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
sql_database infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
stackexchange community[patch]: Fixed tool names snake_case (#16397) 2024-01-25 15:24:19 -08:00
steam community[patch]: Fixed tool names snake_case (#16397) 2024-01-25 15:24:19 -08:00
steamship_image_generation infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
tavily_search [docs]: added info for TavilySearchResults (#22765) 2024-06-13 12:14:11 -07:00
vectorstore community[patch]: Fix VectorStoreQATool (#18529) 2024-03-05 15:56:58 -08:00
wikidata community: Wikidata tool support (#16691) 2024-01-28 16:45:21 -08:00
wikipedia community[patch]: add args_schema to WikipediaQueryRun (#22019) 2024-05-22 21:31:58 +00:00
wolfram_alpha infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
you infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
youtube infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
zapier community[patch]: Add linter to catch @root_validator (#24070) 2024-07-10 14:51:03 +00:00
zenguard Community: Update and fix ZenGuardTool docs and add ZenguardTool to init files (#23415) 2024-06-25 19:26:32 +00:00
__init__.py Community: Update and fix ZenGuardTool docs and add ZenguardTool to init files (#23415) 2024-06-25 19:26:32 +00:00
convert_to_openai.py core[patch], community[patch], openai[patch]: consolidate openai tool… (#16485) 2024-01-25 13:18:46 -08:00
ifttt.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
plugin.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 2023-12-11 13:53:30 -08:00
render.py core[patch], community[patch], openai[patch]: consolidate openai tool… (#16485) 2024-01-25 13:18:46 -08:00
yahoo_finance_news.py community: added args_schema to YahooFinanceNewsTool (#21232) 2024-05-06 13:27:54 -07:00