langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Adds Reflexion (solves #2316)

Open UmerHA opened this issue 2 years ago • 5 comments

Adds Reflexion (solves #2316)

Introduces the concept of trials to AgentExecutor and implements Reflexion as re-try method. I.e., when the Agent fails, it thinks about what it could have done better & attempts the task again. Based on https://arxiv.org/abs/2303.11366.

Fixes #2316

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested: @vowelparrot

Twitter: @UmerHAdil | Discord: RicChilligerDude#7589

UmerHA avatar May 15 '23 16:05 UmerHA

cc @mbchang

dev2049 avatar May 15 '23 18:05 dev2049

cc @noahshinn024

mbchang avatar May 20 '23 02:05 mbchang

Nice!

noahshinn avatar May 20 '23 17:05 noahshinn

This is really cool! And thank you for the PR and patience! The reason I'm taking some time to review this is that it changes a couple pretty core pieces - the agent executor and callback managers. While you do an excellent job of making sure it's all compatible, we may want to look into if a lighter-touch implementation would be appropriate here. I think @hwchase17 will have some stronger opinions than I right now in terms of how the agent framework should evolve

vowelparrot avatar May 22 '23 16:05 vowelparrot

This is really cool! And thank you for the PR and patience! The reason I'm taking some time to review this is that it changes a couple pretty core pieces - the agent executor and callback managers. While you do an excellent job of making sure it's all compatible, we may want to look into if a lighter-touch implementation would be appropriate here. I think @hwchase17 will have some stronger opinions than I right now in terms of how the agent framework should evolve

Sure! 100% no hurt feelings.

I think we have 2 options:

  1. Implement Reflexion as an agent type. Then there's no need for changes in agent executor & callback managers, but we won't be able to use Reflexion with new agent types.
  2. Introduce the concept of re-trys. Then we can use Reflexion with any agent type, but this requires changes in agent executor & callback managers.

I went with 2 because @noahshinn024 explicitly stated "Reflexion is not a replacement for [...] any [....] decision-guiding approach! It is a simple retry technique that can be used (to) enhance other approaches."

How would you design a light-version? Am happy to implement :)

Edit: formatting

UmerHA avatar May 22 '23 17:05 UmerHA

Hey @hwchase17 any comments?

UmerHA avatar May 30 '23 20:05 UmerHA

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Jul 14, 2023 3:41am

vercel[bot] avatar Jun 22 '23 10:06 vercel[bot]

Hi @hinthornw! I saw you're now the maintainer for Agents / Tools / Toolkits, so am pinging you. Would love to get a rough direction on this, so I can adjust this to the LC team's preferences and get it merged.

UmerHA avatar Jul 14 '23 03:07 UmerHA

@UmerHA Hi , could you, please, resolve the merging issues? After that ping me and I push this PR for the review. Thanks! Please, let me know if you need help!

leo-gan avatar Sep 13 '23 20:09 leo-gan

Hi @leo-gan, nice to see you're an LC collaborator - congrats! :)

I would rather not fix this PR, because @vowelparrot said the key change in this PR needs to be discussed first. This PR introduces the concept of 'trials'. When an agent execution fails, a new run (new 'trial') is started.

From @vowelparrot's comment, LC's preference is to implement this differently - maybe as a chain?

Would love to get clarity on this issue before investing the effort of bringing this PR up-to-date.

UmerHA avatar Sep 21 '23 11:09 UmerHA

@hwchase17 Please, give a feedback to this important PR. Thanks!

leo-gan avatar Sep 21 '23 15:09 leo-gan

Hopping into this one - @UmerHA would you be game to implement this using Runnables (LCEL) in a template? https://github.com/langchain-ai/langchain/blob/master/templates/docs/CONTRIBUTING.md

Would require starting over for the most part, but I don't think this PR is mergable in its current state anyways (library has evolved a lot since this was last worked on!). Let me know how you'd like to proceed! Happy to close this and you can open a new PR, or you're welcome to work from this PR's current state.

efriis avatar Nov 07 '23 04:11 efriis

Hey @efriis, I can't promise to work on this due to time constraints, so feel free to close this. If I find time to adapt this, I'll open a new PR!

UmerHA avatar Nov 07 '23 06:11 UmerHA

Sounds great - thanks @UmerHA !

efriis avatar Nov 07 '23 19:11 efriis