# OpenAIAssistantV2Runnable

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable)

Run an OpenAI Assistant.

## Signature

```python
OpenAIAssistantV2Runnable()
```

## Description

**Example using OpenAI tools:**

.. code-block:: python

from langchain_classic.agents.openai_assistant import OpenAIAssistantV2Runnable

assistant = OpenAIAssistantV2Runnable.create_assistant(
    name="math assistant",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4-1106-preview"
)
output = assistant.invoke({"content": "What's 10 - 4 raised to the 2.7"})

**Example using custom tools and AgentExecutor:**

.. code-block:: python

from langchain_classic.agents.openai_assistant import OpenAIAssistantV2Runnable
from langchain_classic.agents import AgentExecutor
from langchain_classic.tools import E2BDataAnalysisTool

tools = [E2BDataAnalysisTool(api_key="...")]
agent = OpenAIAssistantV2Runnable.create_assistant(
    name="langchain assistant e2b tool",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=tools,
    model="gpt-4-1106-preview",
    as_agent=True
)

agent_executor = AgentExecutor(agent=agent, tools=tools)
agent_executor.invoke({"content": "Analyze the data..."})

**Example using custom tools and custom execution:**

.. code-block:: python

from langchain_classic.agents.openai_assistant import OpenAIAssistantV2Runnable
from langchain_classic.agents import AgentExecutor
from langchain_core.agents import AgentFinish
from langchain_classic.tools import E2BDataAnalysisTool

tools = [E2BDataAnalysisTool(api_key="...")]
agent = OpenAIAssistantV2Runnable.create_assistant(
    name="langchain assistant e2b tool",
    instructions="You are a personal math tutor. Write and run code to answer math questions.",
    tools=tools,
    model="gpt-4-1106-preview",
    as_agent=True
)

def execute_agent(agent, tools, input):
    tool_map = {tool.name: tool for tool in tools}
    response = agent.invoke(input)
    while not isinstance(response, AgentFinish):
        tool_outputs = []
        for action in response:
            tool_output = tool_map[action.tool].invoke(action.tool_input)
            tool_outputs.append({"output": tool_output, "tool_call_id": action.tool_call_id})
        response = agent.invoke(
            {
                "tool_outputs": tool_outputs,
                "run_id": action.run_id,
                "thread_id": action.thread_id
            }
        )

    return response

response = execute_agent(agent, tools, {"content": "What's 10 - 4 raised to the 2.7"})
next_response = execute_agent(agent, tools, {"content": "now add 17.241", "thread_id": response.thread_id})

## Extends

- `OpenAIAssistantRunnable`

## Properties

- `client`
- `async_client`
- `assistant_id`
- `check_every_ms`
- `as_agent`

## Methods

- [`validate_async_client()`](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable/validate_async_client)
- [`create_assistant()`](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable/create_assistant)
- [`invoke()`](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable/invoke)
- [`acreate_assistant()`](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable/acreate_assistant)
- [`ainvoke()`](https://reference.langchain.com/python/langchain-community/agents/openai_assistant/base/OpenAIAssistantV2Runnable/ainvoke)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/d5ea8358933260ad48dd31f7f8076555c7b4885a/libs/community/langchain_community/agents/openai_assistant/base.py#L146)