Papers
arxiv:2210.03629

ReAct: Synergizing Reasoning and Acting in Language Models

Published on Oct 6, 2022
Authors:
,
,
,
,
,
,

Abstract

While large language models (LLMs) have demonstrated impressive capabilities across tasks in language understanding and interactive decision making, their abilities for reasoning (e.g. chain-of-thought prompting) and acting (e.g. action plan generation) have primarily been studied as separate topics. In this paper, we explore the use of LLMs to generate both reasoning traces and task-specific actions in an interleaved manner, allowing for greater synergy between the two: reasoning traces help the model induce, track, and update action plans as well as handle exceptions, while actions allow it to interface with external sources, such as knowledge bases or environments, to gather additional information. We apply our approach, named ReAct, to a diverse set of language and decision making tasks and demonstrate its effectiveness over state-of-the-art baselines, as well as improved human interpretability and trustworthiness over methods without reasoning or acting components. Concretely, on question answering (HotpotQA) and fact verification (Fever), ReAct overcomes issues of hallucination and error propagation prevalent in chain-of-thought reasoning by interacting with a simple Wikipedia API, and generates human-like task-solving trajectories that are more interpretable than baselines without reasoning traces. On two interactive decision making benchmarks (ALFWorld and WebShop), ReAct outperforms imitation and reinforcement learning methods by an absolute success rate of 34% and 10% respectively, while being prompted with only one or two in-context examples. Project site with code: https://react-lm.github.io

Community

import json
from typing import Callable, Dict, Any

Define available tools/functions

TOOL_REGISTRY = {
"send_email": send_email_function,
"get_weather": get_weather,
"place_order": ecommerce_api.order,
# ... add more tools
}

def run_function(tool_name: str, args: Dict[str, Any]) -> Any:
"""Execute a function chosen by the LLM with provided arguments."""
# Safety check 1: Verify tool exists
if tool_name not in TOOL_REGISTRY:
raise ValueError(f"Unknown tool: {tool_name}")

# Safety check 2: Validate arguments
tool = TOOL_REGISTRY[tool_name]
if not validate_args(tool, args):
    raise ValueError(f"Invalid args for {tool_name}")

# Execute with error handling
try:
    return tool(**args)
except Exception as e:
    log_error(f"Tool {tool_name} failed: {str(e)}")
    raise
Your need to confirm your account before you can post a new comment.

Sign up or log in to comment

Models citing this paper 51

Browse 51 models citing this paper

Datasets citing this paper 2

Spaces citing this paper 238

Collections including this paper 41