-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ReAct Implementation #1515
base: master
Are you sure you want to change the base?
Conversation
will be adding tests in some time! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your code. Leave some comments.
I also have a question and would be grateful for your answer:
Maybe it's because I haven't carefully read the ReAct paper. I noticed that the code implements step
using "Thought," "Action," and "Observation." If "Thought" is just the response content of one step in ChatAgent
, "Action" is function calling, and "Observation" is the agent's memory, then isn't ReActAgent
very similar to our existing ChatAgent
? What might be the possible differences between them?
camel/agents/react_agent.py
Outdated
}, | ||
) | ||
|
||
def _parse_react_components( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that more LLM structured output is extracted by generating JSON
or XML
, which may have better results than using colons and strings.
And since camel-ai
already has a module for structured output, I think it would be more robust to use camel's existing structured input and output. What do you think?
reference: https://github.com/camel-ai/camel/tree/master/examples/structured_response
components["Observation"], | ||
) | ||
|
||
def _execute_action(self, action: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use more structured output, maybe we can also input the action type (such as ReActActionSpace
) and parameters of actions here.
camel/agents/react_agent.py
Outdated
if hasattr(tool, 'can_handle') and tool.can_handle(action): | ||
logger.debug("Found tool to handle action") | ||
if hasattr(tool, 'execute'): | ||
return tool.execute(action) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I didn't quite understand this part. I noticed that the functions can_handle
and execute
are used here. But the example provided is MathToolkit
, it seems have no execute
method. And also the action space includes search
, lookup
, and finish
. Is there some inconsistency here?
Ahh nice observation, While ReActAgent and ChatAgent share some similarities in their step-by-step processing, there are differences like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @GitHoobar for the contribution! Left some comments below, and I also wanted to highlight some points that @yiyiyi0817 mentioned
Thanks for your explaination. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a little confused about some places, I left some references for discussion.
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pull this branch and run the scripts, the response is
JSON response: {'thought': "I need to find the most recent population data for Paris, as I don't have access to future data directly. The latest available population figure can be used to estimate the 2024 population based on growth trends.", 'action': 'Lookup', 'observation': [{'result_id': 1, 'title': 'LOOKUP function - Microsoft Support', 'description': 'Learn how to use LOOKUP function to search for a value in a single row or column and return a value from the same position in another row or column. Compare LOOKUP with VLOOKUP and XLOOKUP and see examples and syntax.', 'url': 'https://support.microsoft.com/en-us/office/lookup-function-446d94af-663b-451d-8251-369d5e3864cb'}, {'result_id': 2, 'title': 'Excel LOOKUP function | Exceljet', 'description': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examples, syntax, and tips for the vector and array forms of LOOKUP.', 'url': 'https://exceljet.net/functions/lookup-function'}, {'result_id': 3, 'title': 'Different Types of Lookup to Apply in Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula examples - Ablebits', 'description': 'Learn how to use the Excel LOOKUP function to search and retrieve values in one-column or one-row ranges, or in arrays. See formula examples, tips and alternatives for different scenarios of lookup.', 'url': 'https://www.ablebits.com/office-addins-blog/excel-lookup-function/'}, {'result_id': 5, 'title': '6 Formulas to Lookup in Excel', 'description': 'Learn how to use different Excel functions and formulas to lookup values in tables, from left to right or right to left, horizontally or vertically. Compare the advantages and disadvantages of VLOOKUP, HLOOKUP, INDEX-MATCH, OFFSET-MATCH, LOOKUP and LOOKUP (multiple values).', 'url': 'https://www.exceltip.com/lookup-formulas/6-formulas-to-lookup-in-excel.html'}]}
--------------------------------------------------
JSON response: {'thought': 'I need to find the current population of Paris, which is the capital of France. The previous lookup did not yield the population data directly, so I will search for the latest population statistics for Paris.', 'action': 'Lookup', 'observation': [{'result_id': 1, 'title': 'LOOKUP function - Microsoft Support', 'description': 'Learn how to use LOOKUP function to search for a value in a single row or column and return a value from the same position in another row or column. Compare LOOKUP with VLOOKUP and XLOOKUP and see examples and syntax.', 'url': 'https://support.microsoft.com/en-us/office/lookup-function-446d94af-663b-451d-8251-369d5e3864cb'}, {'result_id': 2, 'title': 'Excel LOOKUP function | Exceljet', 'description': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examples, syntax, and tips for the vector and array forms of LOOKUP.', 'url': 'https://exceljet.net/functions/lookup-function'}, {'result_id': 3, 'title': 'Different Types of Lookup to Apply in Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula eption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examples, syntax, and tips for the vector and array forms of LOOKUP.', 'url': 'https://exceljet.net/functions/lookup-function'}, {'result_id': 3, 'title': 'Different Types of Lookup to Apply in Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula eption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examples, syntax, and tips for the vector and array forms of LOOKUP.', 'url': 'https://exceljet.net/functions/lookup-function'}, {'result_id': 3, 'title': 'Different Types of Lookup to Apply iption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examption': 'Learn how to use the Excel LOOKUP function to perform an approximate match lookup in a one-column or one-row range, and return the corresponding value from another range. See examples, syntax, and tips for the vector and array forms of LOOKUP.', 'url': 'https://exceljet.net/functions/lookup-function'}, {'result_id': 3, 'title': 'Different Types of Lookup to Apply in Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula examples - Ablebits', 'description': 'Learn how to use the Excel LOOKUP function to search and retrieve values in one-column or one-row ranges, or in arrays. See formula examples, tips and alternatives for different scenarios of lookup.', 'url': 'https://www.ablebits.com/office-addins-blog/excel-lookup-function/'}, {'result_id': 5, 'title': '6 Formulas to Lookup in Excel', 'n Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula examples - Ablebits', 'description': 'Learn how to use the Excel LOOKUP function to search and retrieve values in one-column or one-row ranges, or in arrays. See formula examples, tips and n Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula en Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula en Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula en Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUn Excel (8 Types)', 'description': 'Learn how to use different types of lookup functions and formulas in Excel to search for values in a table or array. Compare and contrast LOOKUP, HLOOKUP, VLOOKUP, XLOOKUP, OFFSET, MATCH, INDEX, XMATCH and more.', 'url': 'https://www.exceldemy.com/types-of-lookup-in-excel/'}, {'result_id': 4, 'title': 'Excel LOOKUP function with formula examples - Ablebits', 'description': 'Learn how to use the Excel LOOKUP function to search and retrieve values in one-column or one-row ranges, or in arrays. See formula examples, tips and alternatives for different scenarios of lookup.', 'url': 'https://www.ablebits.com/office-addins-blog/excel-lookup-function/'}, {'result_id': 5, 'title': '6 Formulas to Lookup in Excel', 'description': 'Learn how to use different Excel functions and formulas to lookup values in tables, from left to right or right to left, horizontally or vertically. Compare the advantages and disadvantages of VLOOKUP, HLOOKUP, INDEX-MATCH, OFFSET-MATCH, LOOKUP and LOOKUP (multiple values).', 'url': 'https://www.exceltip.com/lookup-formulas/6-formulas-to-lookup-in-excel.html'}]}
It seems not get information from duckduckgo.
The ReAct as described in paper is used for search tools, and the Lookup is used to find relevant sources of information from DB or queries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @GitHoobar , I’ve noticed that the ReActAgent
sometimes runs into the Finish
tag even when the task isn’t actually finished. There are two things we can look into:
- For the
_set_react_prompt
prompt, we could clarify when the agent should trigger this tag. - Consider using a more specific tag wording, like
CAMEL_TASK_DONE
, to avoid misinterpretation.
Let me know what you think!
I don't see any improvement after changing |
Description
Implementing ReAct : Synergizing Reasoning and Acting in Language Models: https://arxiv.org/pdf/2210.03629 with structured output
Motivation and Context
close #1495
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Implemented Tasks
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!