> ## Documentation Index
> Fetch the complete documentation index at: https://private-04b27de1.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.contrib.captainagent.tool_retriever.LocalExecutorWithTools

<h2 id="autogen.agentchat.contrib.captainagent.tool_retriever.LocalExecutorWithTools" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">LocalExecutorWithTools</span>
</h2>

```python theme={null}
LocalExecutorWithTools(tools: list[Tool] | None = None, work_dir: Path | str = PosixPath('.'))
```

An executor that executes code blocks with injected tools. In this executor, the func within the tools can be called directly without declaring in the code block.<br />For example, for a tool converted from langchain, the relevant functions can be called directly.

```python theme={null}
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from autogen.interop import Interoperability

api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=3000)
langchain_tool = WikipediaQueryRun(api_wrapper=api_wrapper)
interop = Interoperability()
ag2_tool = interop.convert_tool(tool=langchain_tool, type="langchain")

# `ag2_tool.name` is wikipedia
local_executor = LocalExecutorWithTools(tools=[ag2_tool], work_dir="./")

code = '''
result = wikipedia(tool_input=\{"query":"Christmas"})
print(result)
'''
print(
    local_executor.execute_code_blocks(
        code_blocks=[
            CodeBlock(language="python", code=code),
        ]
    )
)
```

In this case, the `wikipedia` function can be called directly in the code block. This hides the complexity of the tool.<br />

<b>Parameters:</b>

| Name       | Description                                                                                          |
| ---------- | ---------------------------------------------------------------------------------------------------- |
| `tools`    | **Type:** list\[[Tool](/docs/api-reference/autogen/tools/Tool)] \| None<br /><br />**Default:** None |
| `work_dir` | **Type:** pathlib.Path \| str<br /><br />**Default:** PosixPath('.')                                 |

### Instance Attributes

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### code\_extractor

<br />

(Experimental) Export a code extractor that can be used by an agent.

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### execute\_code\_blocks

```python theme={null}
execute_code_blocks(self, code_blocks: list[CodeBlock]) -> CodeResult
```

Execute code blocks and return the result.<br />

<b>Parameters:</b>

| Name          | Description                                                                                                       |
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
| `code_blocks` | The code blocks to execute.<br /><br />**Type:** list\[[CodeBlock](/docs/api-reference/autogen/coding/CodeBlock)] |

<b>Returns:</b>

| Type                                                        | Description                                   |
| ----------------------------------------------------------- | --------------------------------------------- |
| [CodeResult](/docs/api-reference/autogen/coding/CodeResult) | CodeResult: The result of the code execution. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### restart

```python theme={null}
restart(self) -> 
```

Restart the code executor. Since this executor is stateless, no action is needed.

<br />
