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

feat (multi-agent): creation of the insight agent for the insight extraction for long texts #510

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
25553a2
feat: create the insight agent
Appointat Apr 17, 2024
c4eda95
feat: add the example for the insight agent
Appointat Apr 17, 2024
088dcac
feat: add unit tests for the insight agent
Appointat Apr 17, 2024
d49a89f
chore: polish the docstring
Appointat Apr 22, 2024
e0dd839
format: fix missing newline at end of file in object_recognition.py
Appointat Apr 22, 2024
3ad4b5a
Merge branch 'master' into feature/insight-agent
Appointat Apr 22, 2024
c1ffb3a
Revert "Merge branch 'master' into feature/insight-agent"
Appointat Apr 22, 2024
ceb6033
refactor: update model_config parameter type in CriticAgent, Embodied…
Appointat Apr 22, 2024
753ecd9
feat: update InsightAgent docstring to provide a detailed explanation…
Appointat Apr 22, 2024
cb4c084
feat: update InsightAgent docstring to provide a more detailed explan…
Appointat Apr 22, 2024
2db30bc
Merge branch 'master' into feature/insight-agent
Appointat Apr 23, 2024
aa725fd
fix: update pyproject.toml to add anthropic package and docutils vers…
Appointat Apr 23, 2024
69c34d3
update lock
Appointat Apr 23, 2024
70b0a2f
feat: create the insight agent
Appointat Apr 17, 2024
c9b8717
feat: add the example for the insight agent
Appointat Apr 17, 2024
b4d9d6e
feat: add unit tests for the insight agent
Appointat Apr 17, 2024
27f14e8
chore: polish the docstring
Appointat Apr 22, 2024
b1ceaaa
format: fix missing newline at end of file in object_recognition.py
Appointat Apr 22, 2024
5b5338f
Revert "Merge branch 'master' into feature/insight-agent"
Appointat Apr 22, 2024
d424f7c
refactor: update model_config parameter type in CriticAgent, Embodied…
Appointat Apr 22, 2024
bd2499e
feat: update InsightAgent docstring to provide a detailed explanation…
Appointat Apr 22, 2024
727caa7
feat: update InsightAgent docstring to provide a more detailed explan…
Appointat Apr 22, 2024
da03703
fix: update pyproject.toml to add anthropic package and docutils vers…
Appointat Apr 23, 2024
9be4ae3
update lock
Appointat Apr 23, 2024
3294fe1
Merge branch 'feature/insight-agent' of https://github.com/camel-ai/c…
Appointat Apr 23, 2024
06de49b
update
Appointat Apr 23, 2024
85b7e77
update
Appointat Apr 23, 2024
5735557
update
Appointat Apr 23, 2024
b17c8da
update
Appointat Apr 23, 2024
e06fbf1
Merge remote-tracking branch 'origin' into feature/insight-agent
Appointat Apr 24, 2024
387234d
Merge branch 'master' into feature/insight-agent
Appointat Apr 28, 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
3 changes: 2 additions & 1 deletion camel/agents/critic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from colorama import Fore

from camel.agents import ChatAgent
from camel.configs import BaseConfig
from camel.memories import AgentMemory
from camel.messages import BaseMessage
from camel.responses import ChatAgentResponse
Expand Down Expand Up @@ -49,7 +50,7 @@ def __init__(
self,
system_message: BaseMessage,
model_type: ModelType = ModelType.GPT_3_5_TURBO,
model_config: Optional[Any] = None,
model_config: Optional[BaseConfig] = None,
memory: Optional[AgentMemory] = None,
message_window_size: int = 6,
retry_attempts: int = 2,
Expand Down
3 changes: 2 additions & 1 deletion camel/agents/embodied_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from colorama import Fore

from camel.agents import BaseToolAgent, ChatAgent
from camel.configs import BaseConfig
from camel.interpreters import (
BaseInterpreter,
InternalPythonInterpreter,
Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(
self,
system_message: BaseMessage,
model_type: ModelType = ModelType.GPT_4,
model_config: Optional[Any] = None,
model_config: Optional[BaseConfig] = None,
message_window_size: Optional[int] = None,
tool_agents: Optional[List[BaseToolAgent]] = None,
code_interpreter: Optional[BaseInterpreter] = None,
Expand Down
320 changes: 320 additions & 0 deletions camel/agents/insight_agent.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions camel/agents/role_assignment_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import re
from typing import Any, Dict, Optional, Union
from typing import Dict, Optional, Union

from camel.agents import ChatAgent
from camel.configs import BaseConfig
from camel.messages import BaseMessage
from camel.prompts import TextPrompt
from camel.types import ModelType, RoleType
Expand All @@ -36,7 +37,7 @@ class RoleAssignmentAgent(ChatAgent):
def __init__(
self,
model_type: ModelType = ModelType.GPT_3_5_TURBO,
model_config: Optional[Any] = None,
model_config: Optional[BaseConfig] = None,
) -> None:
system_message = BaseMessage(
role_name="Role Assigner",
Expand Down
2 changes: 1 addition & 1 deletion camel/prompts/object_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.update({
RoleType.ASSISTANT: self.ASSISTANT_PROMPT,
})
})
107 changes: 107 additions & 0 deletions examples/insight_agent/get_insights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import json

from colorama import Fore

from camel.agents.insight_agent import InsightAgent
from camel.configs import ChatGPTConfig


def main(model_type=None) -> None:
# The context text is an example of a production environment to present the
# capabilities of the Insight Agent.
context_text = """**The Production Environment of the Acme Program System**
The Acme Program System, henceforth referred to as APS, is hosted in a state-of-the-art production environment, which has been meticulously designed to ensure optimal performance, security, and reliability.

1. **Data Centers:**
- APS is hosted across **5** multiple geographically dispersed data centers. These data centers are strategically located in North America, Europe, and Asia to ensure seamless global access and provide redundancy.
- **Security:** Each data center is fortified with biometric access controls, **72** CCTV cameras, and intruder alarm systems. All entry and exit points in our production environment are safeguarded by sophisticated firewall systems, preventing unauthorized access and potential attacks.
- **Environmental Control:** Advanced humidity and temperature control systems maintain a constant **22°C (71.6°F)** with a **45%** relative humidity level.
- **Disaster Recovery:** Each location can withstand up to **7.5** magnitude earthquakes. Each data center is equipped with advanced cooling systems, redundant power sources, and high-speed network connections to facilitate uninterrupted service.
2. **Servers:**
- Within each data center, APS employs a cluster of **150** high-performance servers. These servers run on the latest Intel Xeon processors, equipped with DDR5 RAM and NVMe SSDs, ensuring speedy processing and data retrieval.
- **Virtualization:** Our servers utilize KVM-based hypervisors to run an average of **20** virtual machines each.
- **Server Management:** Automated with tools like Ansible and Puppet, ensuring **98%** uniform server setups across the data centers. They also employ RAID configurations to safeguard against potential data loss.
3. **Networking:**
- Our production environment utilizes top-tier networking equipment with multi-gigabit connections, guaranteeing rapid data transmission. A **10 Gbps** dedicated VPN tunnel interconnects all the data centers.
- **CDN:** APS's content reaches users through **3** leading CDNs, with over **200** edge locations worldwide. We also employ redundant ISPs, ensuring that a failure with one provider doesn't lead to system downtime.


1. **Operating System:**
- APS runs on Linux Ubuntu 20.04 LTS. We chose Ubuntu due to its stability, vast community support, and frequent security patches. Custom kernel optimizations lead to a **15%** improvement in network I/O handling.
2. **Database:**
- The system leverages PostgreSQL 12 as its primary relational database management system. Known for its ACID compliance and extensibility, PostgreSQL ensures data integrity and allows for complex queries, which are vital for APS's operations. The primary database and its **3** replicas ensure **99.999%** data availability.
- **Database Caching:** **12 TB** of data is cached using Redis and Memcached.
3. **Backend Framework:**
- The core of APS is built using the Python Django framework. RabbitMQ, which handles an average of **1 million** messages daily, is used as a middleware for asynchronous processing.
4. **Load Balancers:**
- To distribute incoming traffic and prevent any single server from being a bottleneck, we employ Nginx as our load balancer. It not only ensures smooth user experience during traffic surges but also provides additional layers of security. Sticky sessions benefit **85%** of our active users, reducing login prompts.


1. **Intrusion Detection Systems (IDS):** Advanced IDS solutions monitor network traffic, detecting and blocking an average of **500** suspicious activities daily.
2. **Two-Factor Authentication (2FA):** Over **300** administrators access the system daily using 2FA.
3. **Regular Audits & Penetration Testing:** The APS production environment undergoes periodic security audits by third-party agencies, ensuring adherence to the latest security standards and best practices. **4** major vulnerabilities have been rectified in the past year through regular testing.
4. **Data Encryption:** At rest or in transit, all data within APS is encrypted using advanced encryption standards (AES-256), ensuring data confidentiality.


1. **Backup & Recovery:** Regular backups of all data are taken and stored in geographically distinct locations. This ensures quick recovery in the unfortunate event of data loss or system failures.
2. **Server Patching:** **120** servers are patched every month.
3. **Monitoring Tools:** We use a combination of Grafana, Prometheus, and ELK Stack (Elasticsearch, Logstash, Kibana) to monitor server health, application performance, and log analytics, providing real-time insights and facilitating rapid issue resolution.
4. **Error Tracking:** Tools like Sentry rectify an average of **50** application errors daily.
5. **Continuous Deployment:** Employing Jenkins and Docker, APS follows a CI/CD approach, enabling seamless code integration, testing, and deployment, ensuring that the latest features and patches reach our users without causing system downtimes. APS has maintained a **99.98%** uptime over the past year.


1. **Auto-scaling:** Depending on the load, APS infrastructure can dynamically scale up or down using cloud solutions like AWS EC2 and Kubernetes.
2. **Database Sharding:** To handle vast amounts of data, APS's database is sharded, distributing data across **5** shards.


1. **Web Performance:** APS scores an average of **92** on Google Lighthouse.
2. **Analytics:** APS integrates with Google Analytics and Matomo to track the behavior of over **2 million** unique monthly visitors.""" # noqa: E501

# You can give a brief instruction or suggestion to the Insight Agent to
# guide the extraction process.
insights_instruction = (
"The INSIGHT will be used as retrieve index in database.")

# Initialize the Insight Agent with the model type and configuration.
model_config_description = ChatGPTConfig()
insight_agent = InsightAgent(model_type=model_type,
model_config=model_config_description)

# Get insights from the context text.
insights_json = insight_agent.get_insights(
context_text=context_text, insights_instruction=insights_instruction)

# Use <BLANK> as a placeholder for the expected answer.
expected_answer_template = ("Introduction to the system:\n<BLANK>\n" +
"Devices of the system:\n<BLANK>\n" +
"Deployment of the system:\n<BLANK>")

# Transform the insights into a text format in the answer template.
# According to the meganism of the get_insights method, the insights focus
# on the unknown info by the original knowledge of LLM, so that the
# output text here doesn't contain all the information in the context text,
# but the unknown info, ex. number of the devices, the version of the
# software, etc.
text_of_insights = insight_agent.transform_insights_into_text(
insights=insights_json, answer_template=expected_answer_template)

print(Fore.GREEN + f"Insights from the context text:\n"
f"{json.dumps(insights_json, indent=4)}")
print(Fore.YELLOW + f"Text of insights:\n{text_of_insights}")


if __name__ == "__main__":
main()
4 changes: 0 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.