File size: 1,363 Bytes
4962437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
This example demonstrates how to build an agent that can dynamically query Amazon Redshift Serverless tables and store its contents on the local hard drive.

Let's build a support agent that uses GPT-4:

```python
import boto3
from swarms.drivers import AmazonRedshiftSqlDriver, OpenAiPromptDriver
from swarms.loaders import SqlLoader
from swarms.rules import Ruleset, Rule
from swarms.structures import Agent
from swarms.tools import SqlClient, FileManager
from swarms.utils import Chat

session = boto3.Session(region_name="REGION_NAME")

sql_loader = SqlLoader(
    sql_driver=AmazonRedshiftSqlDriver(
        database="DATABASE",
        session=session,
        workgroup_name="WORKGROUP_NAME"
    )
)

sql_tool = SqlClient(
    sql_loader=sql_loader,
    table_name="people",
    table_description="contains information about tech industry professionals",
    engine_name="redshift"
)

agent = Agent(
    tools=[sql_tool, FileManager())],
    rulesets=[
        Ruleset(
            name="HumansOrg Agent",
            rules=[
                Rule("Act and introduce yourself as a HumansOrg, Inc. support agent"),
                Rule("Your main objective is to help with finding information about people"),
                Rule("Only use information about people from the sources available to you")
            ]
        )
    ]
)

Chat(agent).start()
```