# create_react_agent

> **Function** in `langchain_classic`

📖 [View in docs](https://reference.langchain.com/python/langchain-classic/agents/react/agent/create_react_agent)

Create an agent that uses ReAct prompting.

Based on paper "ReAct: Synergizing Reasoning and Acting in Language Models"
(https://arxiv.org/abs/2210.03629)

!!! warning

    This implementation is based on the foundational ReAct paper but is older and
    not well-suited for production applications.

    For a more robust and feature-rich implementation, we recommend using the
    `create_agent` function from the `langchain` library.

    See the
    [reference doc](https://reference.langchain.com/python/langchain/agents/)
    for more information.

## Signature

```python
create_react_agent(
    llm: BaseLanguageModel,
    tools: Sequence[BaseTool],
    prompt: BasePromptTemplate,
    output_parser: AgentOutputParser | None = None,
    tools_renderer: ToolsRenderer = render_text_description,
    *,
    stop_sequence: bool | list[str] = True,
) -> Runnable
```

## Description

Prompt:

The prompt must have input keys:
    * `tools`: contains descriptions and arguments for each tool.
    * `tool_names`: contains all tool names.
    * `agent_scratchpad`: contains previous agent actions and tool outputs as a
        string.

Here's an example:

```python
from langchain_core.prompts import PromptTemplate

template = '''Answer the following questions as best you can. You have access to the following tools:

{tools}

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: {input}
Thought:{agent_scratchpad}'''

prompt = PromptTemplate.from_template(template)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `llm` | `BaseLanguageModel` | Yes | LLM to use as the agent. |
| `tools` | `Sequence[BaseTool]` | Yes | Tools this agent has access to. |
| `prompt` | `BasePromptTemplate` | Yes | The prompt to use. See Prompt section below for more. |
| `output_parser` | `AgentOutputParser \| None` | No | AgentOutputParser for parse the LLM output. (default: `None`) |
| `tools_renderer` | `ToolsRenderer` | No | This controls how the tools are converted into a string and then passed into the LLM. (default: `render_text_description`) |
| `stop_sequence` | `bool \| list[str]` | No | bool or list of str. If `True`, adds a stop token of "Observation:" to avoid hallucinates. If `False`, does not add a stop token. If a list of str, uses the provided list as the stop tokens.  You may to set this to False if the LLM you are using does not support stop sequences. (default: `True`) |

## Returns

`Runnable`

A Runnable sequence representing an agent. It takes as input all the same input

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/f0c5a28fa05adcda89aebcb449d897245ab21fa4/libs/langchain/langchain_classic/agents/react/agent.py#L16)