Skip to content
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

[Roadmap] Multi-Agent System Based on the Role-Playing Module #390

Draft
wants to merge 499 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
499 commits
Select commit Hold shift + click to select a range
c316fc9
Rename to role_assignment_agent
Appointat Aug 21, 2023
5a1da91
Update the branch feature/role-generation from master (#265)
Appointat Aug 30, 2023
dfd0d93
Update the branch feature/role-generation from master (#266)
Appointat Aug 30, 2023
4aa42b7
Update
Appointat Aug 31, 2023
4183a6d
Update camel/societies/role_playing.py
Appointat Aug 31, 2023
e573978
Update camel/agents/role_assignment_agent.py
Appointat Aug 31, 2023
84f28a5
Update
Appointat Aug 31, 2023
41f21d3
Update camel/prompts/role_description_prompt_template.py
Appointat Aug 31, 2023
aa0e63a
Update
Appointat Aug 31, 2023
51d9a88
Update
Appointat Aug 31, 2023
5994efb
Update
Appointat Aug 31, 2023
c3b18b6
Update
Appointat Aug 31, 2023
8845dee
Update
Appointat Sep 1, 2023
44cdbdb
Add the feature of task split
Appointat Sep 7, 2023
176373e
add streamlit file with file upload
Wendong-Fan Oct 7, 2023
1f360a4
Add deductive reasoner agent
Appointat Oct 13, 2023
9f43b22
Add a reasoning example
Appointat Oct 13, 2023
1d00fc4
Update the file path
Appointat Oct 13, 2023
7d8b060
Update the prompt of role-playing
Appointat Oct 13, 2023
ac89b0a
Add examples of multi-agent in HTML format
Appointat Oct 13, 2023
adb9af2
Add example of deduction
Appointat Oct 14, 2023
0628485
Pytest for deductive reasoner agent
Appointat Oct 14, 2023
5c12cc9
Update deductive reasoner agent
Appointat Oct 14, 2023
2490d68
Update unit test
Appointat Oct 14, 2023
89ff79a
add muti_agent_communication_ui.py
Wendong-Fan Oct 14, 2023
6da0b3b
update streamlit ui
Wendong-Fan Oct 15, 2023
5e57b7e
add matplotlib into toml and poetry lock
Wendong-Fan Oct 15, 2023
cdd82c9
add networkx and cffi to toml and poetry lock
Wendong-Fan Oct 15, 2023
3d5d6dd
Update the prompt
Appointat Oct 17, 2023
ecb00e5
update networkx version in toml and lock
Wendong-Fan Oct 15, 2023
f8ede40
update output format
Wendong-Fan Oct 15, 2023
02294f1
Add identification of labels and index
Appointat Oct 21, 2023
dfc4e09
Add details in examples
Appointat Oct 21, 2023
76b4e17
interdisciplinary example
Oct 21, 2023
95b3a10
Update the parameters of print function
Appointat Oct 21, 2023
6e9fcae
Update convert_json_to_str
Appointat Oct 22, 2023
24bfe07
Add labels in deduction
Appointat Oct 22, 2023
5db6ef0
Add "get_retrieval_index_from_environment"
Appointat Oct 22, 2023
fcaa1e4
Add an example of "get_retrieval_index"
Appointat Oct 22, 2023
f003be9
Update example of multi-agent communication
Appointat Oct 22, 2023
f88ecb5
Update the markdown and HTML files
Appointat Oct 22, 2023
1563ad2
add LLM modual to reorg uploaded file content
Wendong-Fan Oct 21, 2023
207fd2a
fix typo
Wendong-Fan Oct 22, 2023
1141a0c
polish uploaded content reorg prompt
Wendong-Fan Oct 22, 2023
277f262
Update the prompt of insight agent
Appointat Oct 26, 2023
bb9805e
Update the parameters of function
Appointat Oct 26, 2023
5a66e04
Add an example of wirting science fiction
Appointat Oct 26, 2023
e81089a
Add the result of output
Appointat Oct 26, 2023
f96df2f
delete files
Oct 26, 2023
67f07ff
Add the example of writing a science fiction
Appointat Oct 29, 2023
403474b
Modify the error messages
Appointat Oct 29, 2023
9f01cc3
Add function of transform_dialogue_into_text
Appointat Oct 29, 2023
e9c71c9
Update the prompt and the parameters
Appointat Oct 29, 2023
42a1eca
Update the prompt of conversation analyst
Appointat Oct 29, 2023
d1c25d4
Update the prompt
Appointat Oct 29, 2023
798606b
Update the prompt
Appointat Oct 30, 2023
9412010
Update the prompt
Appointat Oct 30, 2023
23cbebb
Update the prompt of reproduction
Appointat Oct 31, 2023
605771c
Modify the prompt of transform_dialogue_into_text
Appointat Nov 2, 2023
1c91e49
Modify the system prompt
Appointat Nov 2, 2023
fd97b21
Add an example of text tranformation
Appointat Nov 2, 2023
e0199bd
Update the output of the multi-agent communication
Appointat Nov 2, 2023
496f5a1
Add usage of output agent
Appointat Nov 2, 2023
ff8668f
remove streamlit module
Wendong-Fan Oct 28, 2023
56db191
update content in system message
Oct 28, 2023
a59763a
Update DeductiveReasonerAgent by pytest
Appointat Nov 2, 2023
1e74e01
Update the test case of deduction
Appointat Nov 2, 2023
7151f2c
Add unit test for insight agent
Appointat Nov 3, 2023
da02cfd
Remove unnecessary print statements in
Appointat Nov 3, 2023
48e3702
Update example scenarios
Appointat Nov 3, 2023
c510aa2
Add response terminators to ChatAgent and print
Appointat Nov 3, 2023
1f3c19d
Merge branch 'feature/multi-agent' of https://github.com/camel-ai/cam…
Appointat Nov 3, 2023
5ce9278
Update from master
Appointat Nov 3, 2023
773befd
Refactor import statements in test files.
Appointat Nov 3, 2023
e79a38a
Refactor role assignment agent test to accept role
Appointat Nov 3, 2023
1b939f5
Revert search functions
Appointat Nov 3, 2023
f424d42
Sync with master branch
Appointat Nov 3, 2023
240b86d
Fix open source model role playing example
Appointat Nov 3, 2023
e6833f2
Add matplotlib-stubs to optional dependencies
Appointat Nov 4, 2023
10f6d9e
Refactor code to use type annotations and improve
Appointat Nov 4, 2023
2f8c4f4
Fix formatting and spacing in RoleAssignmentAgent
Appointat Nov 4, 2023
856cdbc
Remove print statements and comments from
Appointat Nov 4, 2023
d876489
Fix formatting in multi-agent communication script
Appointat Nov 4, 2023
ca29dfa
Fix multi-agent communication logging
Appointat Nov 4, 2023
924cdf5
clarify agent returns question answer pairs
Nov 5, 2023
1dda6ad
Revert "clarify agent returns question answer pairs"
Appointat Nov 5, 2023
605b6b3
Refactored role assignment and added label
Appointat Nov 5, 2023
713eab9
Refactored role assignment in multi-agent
Appointat Nov 5, 2023
fef9b8e
Update num_subtasks parameter in
Appointat Nov 5, 2023
badc9be
Merge branch 'master' into feature/multi-agent
Appointat Nov 6, 2023
60a9208
Revert "Merge branch 'master' into feature/multi-agent"
Appointat Nov 7, 2023
1b76fd4
Refactor code to improve performance and
Appointat Nov 9, 2023
ce74084
Add input validation for number of roles in
Appointat Nov 9, 2023
a496910
Reorder prompts in
Appointat Nov 9, 2023
0fb4b05
Fix capitalization of "TASK" in prompts
Appointat Nov 9, 2023
4c10f23
Add new files with task prompts and context
Appointat Nov 9, 2023
72d2552
Refactor AI Society prompt structure
Appointat Nov 9, 2023
119730b
Update model_type in main function
Appointat Nov 10, 2023
aa32001
Strip quotation marks from category strings in
Appointat Nov 10, 2023
20d009b
Add multi-agent communication and model
Appointat Nov 10, 2023
a12af53
Refactor role compatibility evaluation and
Appointat Nov 11, 2023
f50ba8b
Remove tenacity retry decorators from
Appointat Nov 12, 2023
cfb95b3
Merge branch 'master' into feature/multi-agent
Appointat Nov 12, 2023
a403a27
Update dependencies in pyproject.toml
Appointat Nov 12, 2023
4e9e6ce
Revert "Update dependencies in pyproject.toml"
Appointat Nov 12, 2023
13ab203
Revert "Merge branch 'master' into feature/multi-agent"
Appointat Nov 12, 2023
5eaaa4d
Revert "Revert "Merge branch 'master' into feature/multi-agent""
Appointat Nov 12, 2023
c2b6612
Refactor linting and pre-commit workflows
Appointat Nov 12, 2023
77ddc42
Add camel.memories and camel.storages packages,
Appointat Nov 12, 2023
95b8a20
Update dependencies in pyproject.toml
Appointat Nov 12, 2023
ac36732
Fix camel.typing import in agents
Appointat Nov 12, 2023
0be7988
Remove tenacity retry decorators from agents
Appointat Nov 12, 2023
3fce61a
Fix formatting and typos in role assignment agent
Appointat Nov 12, 2023
3a2dece
Refactored role assignment and generation code
Appointat Nov 12, 2023
90c15c2
Update entity recognition and detail extraction
Appointat Nov 13, 2023
8f989e5
Refactor role assignment agent to incorporate
Appointat Nov 13, 2023
82eb4f6
Update Python version to 3.9
Appointat Nov 13, 2023
74e97ef
Fix import statements in test files
Appointat Nov 13, 2023
e872bf6
Rename test_deductive_reasoner_agent to
Appointat Nov 13, 2023
8719095
Refactor task splitting language for clarity and
Appointat Nov 16, 2023
eb7f13f
Fix bug in ai_society.py
Appointat Nov 20, 2023
bf68a83
Add more experiments
Appointat Nov 20, 2023
1f9f99e
Merge branch 'master' into feature/multi-agent
Appointat Nov 20, 2023
e19c358
Refactor agent constructors to use model_type
Appointat Nov 21, 2023
a599e29
Add modified SIR model with reinfection
Appointat Nov 21, 2023
d394157
Add examples of math problem
Appointat Nov 22, 2023
efb7fd8
Update the env and multi-agent
Appointat Nov 25, 2023
6141f6e
Fix model_type parameter in DeductiveReasonerAgent
Appointat Nov 25, 2023
0520779
Fix role assignment agent parameter in
Appointat Nov 27, 2023
24d67c6
Fix bug in multi-agent
Appointat Nov 27, 2023
e6e04c6
Add demo for a business novel
Appointat Nov 27, 2023
c5c9340
Update files
Appointat Nov 27, 2023
8c2455f
Update multi_agent_communication.py
Appointat Nov 27, 2023
e70adaa
Fix model_type parameter in InsightAgent
Appointat Nov 27, 2023
8df8690
Refactor label extraction in
Appointat Nov 27, 2023
c0ee489
Add examples
Appointat Dec 3, 2023
9ecdbdd
Add examples
Appointat Dec 3, 2023
a217cdb
Fix regex pattern in insight_agent.py
Appointat Dec 3, 2023
4256ebc
Fix role_assignment_agent model_type parameter
Appointat Dec 3, 2023
5ad935b
Refactor subtask details in
Appointat Dec 3, 2023
da0a2ee
Fix import and update task prompt
Appointat Dec 3, 2023
aa18619
Update the AI Society prompt
Appointat Dec 4, 2023
5c8f10b
Call the code interpreter
Appointat Dec 4, 2023
5d443f0
Add code snippets for using the assistant to
Appointat Dec 4, 2023
f8e4d57
Add transformation of insights into text
Appointat Dec 7, 2023
664578f
Refactor insight_agent.py to transform insights
Appointat Dec 8, 2023
56fdfb5
Fix formatting in role_assignment_agent.py
Appointat Dec 8, 2023
657efc4
Refactor code for improved performance and readability
Appointat Dec 9, 2023
81b4ea7
Update instructions and answer template
Appointat Dec 9, 2023
e313407
Refactor search_google_and_summarize function to use InsightAgent for…
Appointat Dec 9, 2023
253a73c
Add DeductiveReasonerAgent and InsightAgent to agents module
Appointat Dec 9, 2023
5a07eb9
Update multi_agent_communication.py with new model type and configura…
Appointat Dec 9, 2023
4008183
Delete temp files
Appointat Dec 9, 2023
b9ab33b
Refactor multi-agent communication code
Appointat Dec 9, 2023
694bc8a
Fix regex pattern for label extraction in deductive_reasoner_agent.py
Appointat Dec 10, 2023
ec0293c
Update user prompt and action instructions
Appointat Dec 10, 2023
48440c7
Update content in RoleAssignmentAgent class
Appointat Dec 10, 2023
35b99f3
Update multi agent
Appointat Dec 10, 2023
d82200b
examples
ZhangT-tech Dec 10, 2023
5b87f5a
travel plan example
ZhangT-tech Dec 11, 2023
f1786cc
organize example files
ZhangT-tech Dec 11, 2023
91dcc6f
update detective_novel demo
jjyaoao Dec 14, 2023
c9e40b5
Add print functions
Appointat Dec 14, 2023
f6a3d30
Merge branch 'feature/multi-agent-dev' of https://github.com/camel-ai…
Appointat Dec 14, 2023
3d07718
update detective novel V1.1
jjyaoao Dec 15, 2023
4cf2208
Merge branch 'feature/multi-agent-dev' of https://github.com/camel-ai…
jjyaoao Dec 15, 2023
f90fa43
update detective novel V1.2
jjyaoao Dec 16, 2023
ff4773a
update detect_novel 5K
jjyaoao Dec 19, 2023
67a4a97
Merge branch 'feature/multi-agent-prod' of https://github.com/camel-a…
Appointat Dec 24, 2023
86413bf
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 24, 2023
d4e538a
Add top_answer variable to store the first answer found in search_goo…
Appointat Dec 24, 2023
1ee603c
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 24, 2023
0251688
Refactor search function string concatenation
Appointat Dec 24, 2023
ca60dec
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 24, 2023
5dfb75f
Refactor search_google_and_summarize function to improve readability
Appointat Dec 24, 2023
6c252b8
Add OpenAIFunction support to RoleAssignmentAgent
Appointat Dec 24, 2023
f985867
Add function list parameter to role_assignment_agent.run_role_with_de…
Appointat Dec 24, 2023
d8ef8f2
Remove print statement in role_assignment_agent.py
Appointat Dec 24, 2023
581e31e
Remove unnecessary details from search_google_and_summarize function
Appointat Dec 25, 2023
15eec86
Update role assignment and subtask decomposition prompts
Appointat Dec 25, 2023
a058ac4
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 25, 2023
3015304
Refactor search_google_and_summarize function to handle cases where n…
Appointat Dec 26, 2023
d0b44e5
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 26, 2023
b53eda1
Refactor search function prompt template
Appointat Dec 26, 2023
67a979c
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 26, 2023
0d911a0
Add context and task prompt files for multi-agent demo examples
Appointat Dec 27, 2023
9b3818b
Add GPT-4 performance analysis and GPT-5 prediction
Appointat Dec 27, 2023
6d9b827
Add trip planning files for France
Appointat Dec 27, 2023
6feae03
Update task prompts and context content
Appointat Dec 27, 2023
0befcdc
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Dec 27, 2023
9d6da7c
refactor code
ZhangT-tech Dec 27, 2023
9f4ae50
add specified number of roles and modify names
ZhangT-tech Dec 29, 2023
96bd93a
add gpt can't fulfill request exception
ZhangT-tech Dec 29, 2023
ea05424
add structured output for story
ZhangT-tech Dec 29, 2023
70e75bc
add cycle check prompt during task decomposition
ZhangT-tech Dec 29, 2023
bf5ee25
update prompt in case not fullfill request
ZhangT-tech Jan 1, 2024
892af78
fix format warning
ZhangT-tech Jan 1, 2024
2000a0a
set boundary for input role numbers
ZhangT-tech Jan 1, 2024
d6dc5a3
Merge branch 'master' into feature/multi-agent-dev
Appointat Jan 12, 2024
9a8a592
chore: update networkx version to 2.8.8
Appointat Jan 12, 2024
f86ebf0
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Jan 12, 2024
41f8bcc
style: reformat code with pre-commit hooks
Appointat Jan 12, 2024
9432b98
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Jan 12, 2024
fb9c62c
chore: update dependencies in pyproject.toml
Appointat Jan 12, 2024
cade7a9
style: fix formatting in test_deductive_reasoner_agent.py
Appointat Jan 13, 2024
0a174ad
fix: refactor update_license_in_file function to remove unnecessary e…
Appointat Jan 13, 2024
d30d7a5
fix: refactor update_license_in_file function to remove unnecessary e…
Appointat Jan 13, 2024
d218932
style: update task prompts in transform_dialogue_into_text.py
Appointat Jan 14, 2024
d859358
add: add num_roles parameter to main function
Appointat Jan 14, 2024
a76e16f
refactor: Remove print statements and update variable names
Appointat Jan 14, 2024
188b58c
update: update instructions in ai_society.py
Appointat Jan 14, 2024
8212079
update: fix error message in role_assignment_agent.py
Appointat Jan 14, 2024
a09885d
refactor: update error message to clarify violation of guidelines
Appointat Jan 14, 2024
30e8498
fixi: remove unnecessary code and refactor role-playing session initi…
Appointat Jan 14, 2024
3d02de5
add: handle exception in multi_agent_communication.py
Appointat Jan 14, 2024
16ff06c
feat: Implementing Structured Output Support in AI Role-Playing Modul…
Appointat Jan 14, 2024
7c0112f
Merge branch 'feature/multi-agent-dev' into feature/multi-agent-prod
Appointat Jan 14, 2024
3f7259e
chore: fix bug of empty parallel pipeline
Appointat Jan 14, 2024
d505efb
fix: refactor transform_into_text method to accept insights in string…
Appointat Jan 15, 2024
b5300ba
refactor: fix error handling and improve error messages
Appointat Jan 16, 2024
9f4e932
chore: update function calling instructions in AI Society prompt
Appointat Jan 16, 2024
57360cc
add: add RAG learning task and prompt
Appointat Jan 16, 2024
3f6f572
refactor: update role assignment agent model type
Appointat Jan 16, 2024
d9c4b0a
fix: update multi_agent_communication.py with role assignment and con…
Appointat Jan 16, 2024
2794ada
add: add timing logs for role generation and task decomposition
Appointat Jan 16, 2024
07d8372
chore: add prompt for logic chains in multi_agent_communication.py
Appointat Jan 16, 2024
398d3bc
refactor: fix AI response handling in role_assignment_agent.py
Appointat Jan 18, 2024
fa4ba2a
chore: update AI reference to LLM in role_assignment_agent.py
Appointat Jan 20, 2024
959456a
update: update GPT-4 performance indicators and add global AI market …
Appointat Jan 22, 2024
dbf3365
Merge branch 'master' into feature/multi-agent-prod
Appointat Jan 22, 2024
f43b058
refactor: refactor code to improve performance and readability
Appointat Jan 22, 2024
0929b8f
fix: refactor role playing with structured output code
Appointat Jan 22, 2024
0f80603
refactor: refactor role assignment agent to multi-agent
Appointat Jan 22, 2024
a352edd
refactor role play session in multi_agent_communication.py
Appointat Jan 22, 2024
e043dd2
fix: add subtask context to task description
Appointat Feb 21, 2024
d339fc9
perf: update task prompt and split subtasks
Appointat Feb 21, 2024
02937e0
test: update task prompt and split tasks
Appointat Feb 21, 2024
8119738
Merge branch 'master' into feature/multi-agent-dev
Appointat Apr 29, 2024
0867af8
feat: Refactor DeductiveReasonerAgent to use JSON for answer template
Appointat May 19, 2024
6009483
feat: Add utility function to extract JSON from a string
Appointat May 19, 2024
1c1828f
update
Appointat May 19, 2024
f9520d9
Refactor print_and_write_md function to accept optional file_path par…
Appointat May 19, 2024
f2b7d9a
Refactor extract_json_from_string function to handle escape character…
Appointat May 19, 2024
4b0b3af
Refactor extract_json_from_string function to handle escape character…
Appointat May 20, 2024
88826c1
feat: Fix handling of escape characters and newlines in extract_json_…
Appointat May 20, 2024
72bd714
feat: Fix handling of escape characters and newlines in extract_json_…
Appointat May 20, 2024
eb32985
feat: Fix handling of escape characters and newlines in extract_json_…
Appointat May 20, 2024
905a318
feat: Fix handling of escape characters and newlines in extract_json_…
Appointat May 20, 2024
0da3033
feat: add tenacity
Appointat May 21, 2024
310be87
feat: add tenacity
Appointat May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Sphinx build
run: |
cd docs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pytest_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Run pytest
env:
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Run pytest
env:
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pytest_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Run pytest
env:
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Run pytest
env:
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
Expand All @@ -56,7 +56,7 @@ jobs:
- name: Set up Python environment and install dependencies
uses: ./.github/actions/camel_install
with:
python-version: "3.8"
python-version: "3.9"
- name: Run pytest
env:
OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}"
Expand Down
7 changes: 5 additions & 2 deletions camel/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from .chat_agent import ChatAgent
from .critic_agent import CriticAgent
from .embodied_agent import EmbodiedAgent
from .role_assignment_agent import RoleAssignmentAgent
from .insight_agent import InsightAgent
from .multi_agent import MultiAgent
from .task_agent import (
TaskCreationAgent,
TaskPlannerAgent,
Expand All @@ -28,6 +29,8 @@
__all__ = [
'BaseAgent',
'ChatAgent',
'DeductiveReasonerAgent',
'InsightAgent',
'TaskSpecifyAgent',
'TaskPlannerAgent',
'TaskCreationAgent',
Expand All @@ -36,5 +39,5 @@
'BaseToolAgent',
'HuggingFaceToolAgent',
'EmbodiedAgent',
'RoleAssignmentAgent',
'MultiAgent',
]
99 changes: 47 additions & 52 deletions camel/agents/deductive_reasoner_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import re
from typing import Dict, List, Optional, Union

from camel.agents.chat_agent import ChatAgent
from camel.configs import BaseConfig
from camel.messages import BaseMessage
from camel.prompts import TextPrompt
from camel.types import ModelType, RoleType
from camel.utils.structure_output import extract_json_from_string


class DeductiveReasonerAgent(ChatAgent):
Expand Down Expand Up @@ -144,16 +144,27 @@ def deduce_conditions_and_quality(
{target_state}

{role_with_description_prompt}
===== ANSWER TEMPLATE =====
- Characterization and comparison of $A$ and $B$:\n<BLANK>
- Historical & Empirical Analysis:\n<BLANK>/None
- Logical Deduction of Conditions ($C$) (multiple conditions can be deduced):
condition <NUM>:
<BLANK>.
- Entity/Label Recognition of Conditions:\n[<BLANK>, <BLANK>, ...] (include square brackets)
- Quality Assessment ($Q$) (do not use symbols):
<BLANK>.
- Iterative Evaluation:\n<BLANK>/None"""
"""

answer_json_template = """
===== ANSWER TEMPLATE (JSON) =====
{
"Characterization and comparison of A and B": "<BLANK>",
"Historical & Empirical Analysis": "<BLANK>", // use "None" if not applicable
"Logical Deduction of Conditions (C)": {
"condition <NUM>": "<BLANK>",
// it is allowed to have multiple conditions
"condition <NUM_2>": "<BLANK>",
},
"Entity or Label Recognition of Conditions": [
"<BLANK>",
// it is allowed to have multiple labels
"<BLANK>",
],
"Quality Assessment (Q)": "<BLANK>", // do not use symbols
"Iterative Evaluation": "<BLANK>", // use "None" if not applicable
}
"""

if role_descriptions_dict is not None:
role_names = role_descriptions_dict.keys()
Expand All @@ -169,11 +180,12 @@ def deduce_conditions_and_quality(
role_with_description_prompt = ""
deduce_prompt = TextPrompt(deduce_prompt)

deduce = deduce_prompt.format(
deduce: str = deduce_prompt.format(
starting_state=starting_state,
target_state=target_state,
role_with_description_prompt=role_with_description_prompt,
)
deduce += answer_json_template

conditions_and_quality_generation_msg = BaseMessage.make_user_message(
role_name="Deductive Reasoner", content=deduce
Expand All @@ -188,48 +200,31 @@ def deduce_conditions_and_quality(
"Deduction failed. Error:\n" + f"{response.info}"
)
msg: BaseMessage = response.msg
print(f"Message content:\n{msg.content}")

# Extract the conditions from the message
condistions_dict = {
f"condition {i}": cdt.replace("<", "")
.replace(">", "")
.strip()
.strip('\n')
for i, cdt in re.findall(
r"condition (\d+):\s*(.+?)(?=condition \d+|- Entity)",
msg.content,
re.DOTALL,
)
}

# Extract the labels from the message
labels = [
label.strip().strip('\n').strip("\"'")
for label in re.findall(
r"Entity/Label Recognition of Conditions:\n\[(.+?)\]",
msg.content,
re.DOTALL,
)[0].split(",")
]

# Extract the quality from the message
quality = next(
q.strip().strip('\n')
for q in re.findall(
r"Quality Assessment \(\$Q\$\) \(do not use symbols\):"
r"\n(.+?)- Iterative",
msg.content,
re.DOTALL,
)

# Convert them into the dictionary
json_dict = extract_json_from_string(msg.content)

conditions = (
json_dict["Logical Deduction of Conditions (C)"]
if "Logical Deduction of Conditions (C)" in json_dict
else []
)
labels = (
json_dict["Entity or Label Recognition of Conditions"]
if "Entity or Label Recognition of Conditions" in json_dict
else []
)
quality = (
json_dict["Quality Assessment (Q)"]
if "Quality Assessment (Q)" in json_dict
else ""
)

# Convert them into JSON format
conditions_and_quality_json: Dict[
conditions_and_quality_dict: Dict[
str, Union[List[str], Dict[str, str]]
] = {}
conditions_and_quality_json["conditions"] = condistions_dict
conditions_and_quality_json["labels"] = labels
conditions_and_quality_json["evaluate_quality"] = quality
conditions_and_quality_dict["conditions"] = conditions
conditions_and_quality_dict["labels"] = labels
conditions_and_quality_dict["evaluate_quality"] = quality

return conditions_and_quality_json
return conditions_and_quality_dict