Files
langchain/libs/cli/langchain_cli/integration_template/docs/tools.ipynb
T
2025-03-09 21:14:43 +00:00

7.4 KiB

Cell:
[Cell type raw - unsupported, skipped]

ModuleName

  • TODO: Make sure API reference link is correct.

This notebook provides a quick overview for getting started with ModuleName tool. For detailed documentation of all ModuleName features and configurations head to the API reference.

  • TODO: Add any other relevant links, like information about underlying API, etc.

Overview

Integration details

  • TODO: Make sure links and features are correct
Class Package Serializable JS support Package latest
ModuleName langchain-community beta/❌ ✅/❌ PyPI - Version

Tool features

  • TODO: Add feature table if it makes sense

Setup

  • TODO: Add any additional deps

The integration lives in the langchain-community package.

In [ ]:
%pip install --quiet -U langchain-community

Credentials

  • TODO: Add any credentials that are needed
In [2]:
import getpass
import os

# if not os.environ.get("__MODULE_NAME___API_KEY"):
#     os.environ["__MODULE_NAME___API_KEY"] = getpass.getpass("__MODULE_NAME__ API key:\n")

It's also helpful (but not needed) to set up LangSmith for best-in-class observability:

In [3]:
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()

Instantiation

  • TODO: Fill in instantiation params

Here we show how to instantiate an instance of the ModuleName tool, with

In [4]:
from langchain_community.tools import __ModuleName__


tool = __ModuleName__(
    ...
)

Invocation

Invoke directly with args

  • TODO: Describe what the tool args are, fill them in, run cell
In [ ]:
tool.invoke({...})

Invoke with ToolCall

We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:

  • TODO: Fill in tool args and run cell
In [ ]:
# This is usually generated by a model, but we'll create a tool call directly for demo purposes.
model_generated_tool_call = {
    "args": {...},  # TODO: FILL IN
    "id": "1",
    "name": tool.name,
    "type": "tool_call",
}
tool.invoke(model_generated_tool_call)

Use within an agent

  • TODO: Add user question and run cells

We can use our tool in an agent. For this we will need a LLM with tool-calling capabilities:

import ChatModelTabs from "@theme/ChatModelTabs";

In [16]:
# | output: false
# | echo: false

# !pip install -qU langchain langchain-openai
from langchain.chat_models import init_chat_model

llm = init_chat_model(model="gpt-4o", model_provider="openai")
In [ ]:
from langgraph.prebuilt import create_react_agent

tools = [tool]
agent = create_react_agent(llm, tools)
In [ ]:
example_query = "..."

events = agent.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)
for event in events:
    event["messages"][-1].pretty_print()

API reference

For detailed documentation of all ModuleName features and configurations head to the API reference: https://python.langchain.com/v0.2/api_reference/community/tools/langchain_community.tools.module_name.tool.ModuleName.html