> ## 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.

# OpenAI Agents SDK tool factories

> make_openai_tools() returns function_tool callables for the openai-agents SDK, wiring CodebaseMemory recall, finding storage, and import-graph impact analysis.

`make_openai_tools` wraps a `CodebaseMemory` instance and an optional `ImportGraph` in `@function_tool`-decorated callables for the `openai-agents` SDK. Pass the returned list directly to `Agent(tools=[...])`.

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

## Installation

```bash theme={null}
pip install reasonblocks openai-agents
```

## make\_openai\_tools

```python theme={null}
make_openai_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 up to three `@function_tool`-decorated callables (`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 regardless of the enable flags.
</ParamField>

<ParamField path="graph" type="ImportGraph | None" default="None">
  Optional `ImportGraph`. 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 per `recall_findings` call.
</ParamField>

<ParamField path="recall_threshold" type="float" default="0.25">
  Minimum similarity score for recall results.
</ParamField>

<ParamField path="enable_recall" type="bool" default="true">
  Include `recall_findings`. Has no effect when `memory is None`.
</ParamField>

<ParamField path="enable_store" type="bool" default="true">
  Include `store_finding`. Has no effect when `memory is None`.
</ParamField>

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

### Returns

<ResponseField name="tools" type="list">
  A list of `@function_tool`-decorated callables. Spread into the `Agent` tool list: `tools=[*rb_tools, *your_tools]`.
</ResponseField>

## Tools

### `recall_findings(query)`

Searches `CodebaseMemory` and returns the formatted recall string.

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

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

Persists a finding. 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 (truncated to 64 chars)           |

### `impact_analysis(file_path)`

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

| 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 Basic usage theme={null}
  import asyncio
  import pathlib
  from agents import Agent, Runner
  from reasonblocks import CodebaseMemory, ImportGraph, ReasonBlocks
  from reasonblocks.integrations import make_openai_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_openai_tools(memory, graph)

  agent = Agent(
      name="code-reviewer",
      instructions="You are a senior engineer reviewing Python codebases.",
      tools=[*rb_tools, *your_tools],
  )

  hooks = rb.openai_hooks(
      run_id="run-1",
      agent_name="code-reviewer",
      task="Review auth module for security issues",
  )

  async def main():
      async with hooks:
          result = await Runner.run(
              agent,
              input="Review auth/session.py for security issues",
              hooks=hooks,
          )
      print(result.final_output)

  asyncio.run(main())
  ```

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

  ```python Tune recall sensitivity theme={null}
  rb_tools = make_openai_tools(
      memory,
      graph,
      recall_top_k=10,
      recall_threshold=0.35,
  )
  ```
</CodeGroup>

## Telemetry: openai\_hooks

`make_openai_tools` handles tool wiring only. Run telemetry — `run_start`, per-step events, and `run_finish` — is provided separately by `rb.openai_hooks()`, which returns a `RunHooks` adapter you pass to `Runner.run(hooks=...)`.

<Warning>
  `openai_hooks` is telemetry-only. Unlike the LangChain middleware, it does **not** inject E-trace steering text into the agent's prompt. The OpenAI Agents SDK has no `before_model` analog to splice content into the system prompt mid-run; running `openai_hooks` gives you dashboard rows and per-step events but not in-loop steering.
</Warning>

For the full `openai_hooks` reference and lifecycle details, see the [OpenAI Agents integration guide](/guides/openai-agents).
