> ## Documentation Index
> Fetch the complete documentation index at: https://langchain.idochub.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MemgraphToolkit

This will help you get started with the Memgraph [toolkit](/oss/python/langchain/tools#toolkits).

Tools within `MemgraphToolkit` are designed for the interaction with the `Memgraph` database.

## Setup

To be able tot follow the steps below, make sure you have a running Memgraph instance on your local host. For more details on how to run Memgraph, take a look at [Memgraph docs](https://memgraph.com/docs/getting-started)

If you want to get automated tracing from runs of individual tools, you can also set your [LangSmith](https://docs.smith.langchain.com/) API key by uncommenting below:

```python theme={null}
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
```

### Installation

This toolkit lives in the `langchain-memgraph` package:

```python theme={null}
%pip install -qU langchain-memgraph
```

## Instantiation

Now we can instantiate our toolkit:

```python theme={null}
from langchain.chat_models import init_chat_model
from langchain_memgraph import MemgraphToolkit
from langchain_memgraph.graphs.memgraph import MemgraphLangChain

db = MemgraphLangChain(url=url, username=username, password=password)

llm = init_chat_model("gpt-4o-mini", model_provider="openai")

toolkit = MemgraphToolkit(
    db=db,  # Memgraph instance
    llm=llm,  # LLM chat model for LLM operations
)
```

## Tools

View available tools:

```python theme={null}
toolkit.get_tools()
```

## Invocation

Tools can be individually called by passing an arguments, for QueryMemgraphTool it would be:

```python theme={null}
from langchain_memgraph.tools import QueryMemgraphTool

# Rest of the code omitted for brevity

tool.invoke({QueryMemgraphTool({"query": "MATCH (n) RETURN n LIMIT 5"})})
```

## Use within an agent

```python theme={null}
from langchain.agents import create_agent

agent_executor = create_agent(llm, tools)
```

```python theme={null}
example_query = "MATCH (n) RETURN n LIMIT 1"

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

## API reference

For more details on API visit [Memgraph integration docs](https://memgraph.com/docs/ai-ecosystem/integrations#langchain)
