Giter Site home page Giter Site logo

reflexion-framework's Introduction

reflexion-framework

A simple, modular, non-brittle framework for implementing text-based Reflexion agents. Designed for compatability with diverse problem domains and interopability with existing workflows.

Below is an example of a Reflexion agent that implements functions based on feedback from a code execution environment, which generates its own tests.

from reflexion.agents.programming import PythonReflexionAgent
from reflexion.datasets.programming import HumanEvalDataset
from reflexion.environments.programming import (InternalTestingEnv,
                                                PythonTestingEnv)
from reflexion.llms import OpenAIChatLLM

# Load a task from a dataset 
LANG = "python"
dataset = HumanEvalDataset(language=LANG)
task_id, signature, docstring, tests = dataset[0]

# Instantiate an LLM
llm = OpenAIChatLLM(model_name="gpt-4", temperature=0)

# Instantiate a code execution environment
local_env = PythonTestingEnv(timeout=10)

# Instantiate a Reflexion agent with an internal testing environment 
agent = PythonReflexionAgent(
        function_signature=signature,
        docstring=docstring,
        testing_env=InternalTestingEnv(function_signature=signature,
                        docstring=docstring,
                        language=LANG,
                        local_env=local_env,
                        llm=llm),
        llm=llm
)

# Run the agent for a few steps
for _ in range(3):
    reward, message = agent.step()

# Evaluate the agent's implementation against the ground truth tests
rewards, messages = local_env.step(program=agent.implementation, tests=tests)

Setup

Follow these steps to get reflexion-framework up and running:

  1. Clone the repository with submodules:
git clone --recurse-submodules https://github.com/becklabs/reflexion-framework.git && cd reflexion-framework
  1. Install the package:
pip3 install -e .

Optional Setup

  1. If using the Rust programming environment, Install Cargo

  2. If using OpenAI LLMs, set the OPENAI_API_KEY environment variable to your API key:

export OPENAI_API_KEY=yourkey
  1. If using transformers LLMs, install the necessary libraries:
pip3 install transformers torch
  1. If evaluating with the LeetCodeHard benchmark, build the dataset according to the instructions in the README.

Opportunities for Contribution

  • Wider language support for programming tasks
  • HotpotQA and Alfworld agent and environment implementations

reflexion-framework's People

Contributors

becklabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.