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

# LangChain tool factories

> make_langchain_tools() returns LangChain @tool callables for CodebaseMemory recall, finding storage, and import-graph impact analysis.

`make_langchain_tools` wires a `CodebaseMemory` instance and an optional `ImportGraph` to a list of LangChain `@tool`-decorated callables. Pass the returned list directly into `create_agent(tools=...)` alongside your own tools. The factory shares the `memory` and `graph` objects you provide, so a finding stored in one step is available to the next recall in the same run.

```python theme={null}
from reasonblocks.integrations import make_langchain_tools
```

## Installation

The LangChain integration requires `langchain-core`:

```bash theme={null}
pip install reasonblocks langchain-core
```

## make\_langchain\_tools

```python theme={null}
make_langchain_tools(
    memory: CodebaseMemory | None = None,
    graph: ImportGraph | None = None,
    *,
    recall_top_k: int = 5,
    recall_threshold: float = 0.25,
    enable_recall: bool = True,
    enable_store: bool = True,
    enable_impact: bool = True,
) -> list
```

Returns a list of LangChain `@tool` callables. The list contains up to three tools (`recall_findings`, `store_finding`, `impact_analysis`) depending on which arguments and flags you provide.

### Parameters

<ParamField path="memory" type="CodebaseMemory | None" default="None">
  The `CodebaseMemory` instance the tools read from and write to. When `None`, both `recall_findings` and `store_finding` are omitted from the returned list regardless of `enable_recall` and `enable_store`.
</ParamField>

<ParamField path="graph" type="ImportGraph | None" default="None">
  Optional `ImportGraph` for the repository. When provided and `enable_impact=True`, an `impact_analysis` tool is added.
</ParamField>

<ParamField path="recall_top_k" type="int" default="5">
  Maximum number of findings returned by a single `recall_findings` call.
</ParamField>

<ParamField path="recall_threshold" type="float" default="0.25">
  Minimum similarity score (0–1) a finding must reach to be included in recall results.
</ParamField>

<ParamField path="enable_recall" type="bool" default="true">
  Include the `recall_findings` tool. Set to `False` to produce a write-only or impact-only tool set. Has no effect when `memory is None`.
</ParamField>

<ParamField path="enable_store" type="bool" default="true">
  Include the `store_finding` tool. Set to `False` for read-only scenarios. Has no effect when `memory is None`.
</ParamField>

<ParamField path="enable_impact" type="bool" default="true">
  Include the `impact_analysis` tool when a `graph` is provided.
</ParamField>

### Returns

<ResponseField name="tools" type="list">
  A list of LangChain `@tool`-decorated callables. Concatenate with your own tool list and pass to `create_agent`.
</ResponseField>

## Tools

### `recall_findings(query)`

Searches `CodebaseMemory` for findings relevant to `query`. The tool returns the same string that `CodebaseMemory.format_recall()` produces.

| Parameter | Type  | Description                                              |
| --------- | ----- | -------------------------------------------------------- |
| `query`   | `str` | Natural-language description of what you are looking for |

### `store_finding(content, file_path, finding_type)`

Persists a finding to `CodebaseMemory`. Returns `"stored (id=<fid>)"` on success or `"store failed"` on transport error.

| Parameter      | Type  | Default  | Description                                                              |
| -------------- | ----- | -------- | ------------------------------------------------------------------------ |
| `content`      | `str` | —        | The finding text (truncated to 8000 chars)                               |
| `file_path`    | `str` | `""`     | Repo-relative path (truncated to 512 chars)                              |
| `finding_type` | `str` | `"note"` | Short tag — `bug`, `behavior`, `pattern`, `note` (truncated to 64 chars) |

### `impact_analysis(file_path)`

Calls `ImportGraph.format_impact()` and returns the rendered string of dependents and dependencies.

| Parameter   | Type  | Description                                   |
| ----------- | ----- | --------------------------------------------- |
| `file_path` | `str` | Repo-relative path, e.g. `"pydantic/main.py"` |

<Note>
  `impact_analysis` is only present when you pass a non-`None` `graph` **and** `enable_impact=True`. Check `len(rb_tools)` rather than assuming a fixed index if you build the list conditionally.
</Note>

## Complete example

<CodeGroup>
  ```python LangChain 1.0 agent theme={null}
  import pathlib
  from langchain.agents import create_agent
  from langchain_anthropic import ChatAnthropic

  from reasonblocks import CodebaseMemory, ImportGraph, ReasonBlocks
  from reasonblocks.integrations import make_langchain_tools

  rb = ReasonBlocks(api_key="rb_live_...")
  memory = CodebaseMemory(codebase_id="my-repo", api_key="rb_live_...")
  graph = ImportGraph().build_from_files(
      {str(p): p.read_text() for p in pathlib.Path("myrepo").rglob("*.py")}
  )

  rb_tools = make_langchain_tools(
      memory,
      graph,
      recall_top_k=8,
      recall_threshold=0.3,
  )

  model = ChatAnthropic(model="claude-haiku-4-5-20251001", max_tokens=1024)

  with rb.middleware(
      run_id="run-1",
      agent_name="reviewer",
      task="Review PR #42",
      model="claude-haiku-4-5-20251001",
      codebase_id="my-repo",
  ) as mw:
      agent = create_agent(
          model=model,
          tools=[*rb_tools, *your_tools],
          system_prompt="You are a senior Python reviewer.",
          middleware=[mw],
      )
      result = agent.invoke({"messages": [("user", "Review PR #42")]})
  ```

  ```python Read-only (no store) theme={null}
  rb_tools = make_langchain_tools(
      memory,
      graph,
      enable_store=False,
  )
  ```

  ```python Without import graph theme={null}
  rb_tools = make_langchain_tools(memory)
  # impact_analysis is omitted — graph is None
  ```
</CodeGroup>

<Tip>
  Build the tool list once per agent run, not once per process. The closure over `memory` and `graph` is fine to share across calls inside the same run, but each run typically wants its own `CodebaseMemory` instance scoped to the right `codebase_id`.
</Tip>
