solace-agent-mesh 0.1.2__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of solace-agent-mesh might be problematic. Click here for more details.
- solace_agent_mesh/agents/base_agent_component.py +2 -0
- solace_agent_mesh/agents/global/actions/plantuml_diagram.py +14 -2
- solace_agent_mesh/agents/global/actions/plotly_graph.py +49 -40
- solace_agent_mesh/agents/web_request/actions/do_web_request.py +34 -33
- solace_agent_mesh/cli/__init__.py +1 -1
- solace_agent_mesh/cli/commands/add/gateway.py +162 -9
- solace_agent_mesh/cli/commands/build.py +0 -1
- solace_agent_mesh/cli/commands/init/builtin_agent_step.py +1 -6
- solace_agent_mesh/cli/commands/init/create_config_file_step.py +5 -0
- solace_agent_mesh/cli/commands/init/create_other_project_files_step.py +52 -1
- solace_agent_mesh/cli/commands/init/init.py +1 -5
- solace_agent_mesh/cli/commands/init/project_structure_step.py +0 -29
- solace_agent_mesh/cli/commands/plugin/add.py +3 -1
- solace_agent_mesh/cli/commands/plugin/build.py +11 -2
- solace_agent_mesh/cli/commands/plugin/plugin.py +20 -5
- solace_agent_mesh/cli/commands/plugin/remove.py +3 -1
- solace_agent_mesh/cli/config.py +4 -0
- solace_agent_mesh/cli/utils.py +7 -2
- solace_agent_mesh/common/action_response.py +13 -0
- solace_agent_mesh/common/constants.py +12 -0
- solace_agent_mesh/common/postgres_database.py +11 -5
- solace_agent_mesh/common/utils.py +16 -11
- solace_agent_mesh/configs/monitor_stim_and_errors_to_slack.yaml +3 -0
- solace_agent_mesh/configs/service_embedding.yaml +1 -1
- solace_agent_mesh/configs/service_llm.yaml +1 -1
- solace_agent_mesh/gateway/components/gateway_base.py +7 -1
- solace_agent_mesh/gateway/components/gateway_input.py +8 -5
- solace_agent_mesh/gateway/components/gateway_output.py +12 -3
- solace_agent_mesh/orchestrator/action_manager.py +13 -1
- solace_agent_mesh/orchestrator/components/orchestrator_stimulus_processor_component.py +25 -5
- solace_agent_mesh/orchestrator/orchestrator_prompt.py +155 -35
- solace_agent_mesh/services/file_service/file_service.py +5 -0
- solace_agent_mesh/services/file_service/file_service_constants.py +1 -1
- solace_agent_mesh/services/file_service/file_transformations.py +11 -1
- solace_agent_mesh/services/file_service/file_utils.py +2 -0
- solace_agent_mesh/services/history_service/history_providers/base_history_provider.py +21 -45
- solace_agent_mesh/services/history_service/history_providers/file_history_provider.py +74 -0
- solace_agent_mesh/services/history_service/history_providers/index.py +40 -0
- solace_agent_mesh/services/history_service/history_providers/memory_history_provider.py +19 -153
- solace_agent_mesh/services/history_service/history_providers/mongodb_history_provider.py +66 -0
- solace_agent_mesh/services/history_service/history_providers/redis_history_provider.py +40 -137
- solace_agent_mesh/services/history_service/history_providers/sql_history_provider.py +93 -0
- solace_agent_mesh/services/history_service/history_service.py +315 -41
- solace_agent_mesh/services/history_service/long_term_memory/__init__.py +0 -0
- solace_agent_mesh/services/history_service/long_term_memory/long_term_memory.py +399 -0
- solace_agent_mesh/services/llm_service/components/llm_request_component.py +24 -0
- solace_agent_mesh/templates/gateway-config-template.yaml +2 -1
- solace_agent_mesh/templates/gateway-default-config.yaml +3 -3
- solace_agent_mesh/templates/plugin-gateway-default-config.yaml +29 -0
- solace_agent_mesh/templates/rest-api-default-config.yaml +2 -1
- solace_agent_mesh/templates/slack-default-config.yaml +1 -1
- solace_agent_mesh/templates/web-default-config.yaml +2 -1
- {solace_agent_mesh-0.1.2.dist-info → solace_agent_mesh-0.2.0.dist-info}/METADATA +38 -8
- {solace_agent_mesh-0.1.2.dist-info → solace_agent_mesh-0.2.0.dist-info}/RECORD +57 -52
- solace_agent_mesh/cli/commands/init/rest_api_step.py +0 -50
- solace_agent_mesh/cli/commands/init/web_ui_step.py +0 -40
- {solace_agent_mesh-0.1.2.dist-info → solace_agent_mesh-0.2.0.dist-info}/WHEEL +0 -0
- {solace_agent_mesh-0.1.2.dist-info → solace_agent_mesh-0.2.0.dist-info}/entry_points.txt +0 -0
- {solace_agent_mesh-0.1.2.dist-info → solace_agent_mesh-0.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -12,6 +12,7 @@ from solace_ai_connector.common.utils import ensure_slash_on_end
|
|
|
12
12
|
from ..services.llm_service.components.llm_service_component_base import LLMServiceComponentBase
|
|
13
13
|
from ..common.action_list import ActionList
|
|
14
14
|
from ..common.action_response import ActionResponse, ErrorInfo
|
|
15
|
+
from ..common.constants import ORCHESTRATOR_COMPONENT_NAME
|
|
15
16
|
from ..services.file_service import FileService
|
|
16
17
|
from ..services.file_service.file_utils import recursive_file_resolver
|
|
17
18
|
from ..services.middleware_service.middleware_service import MiddlewareService
|
|
@@ -185,6 +186,7 @@ class BaseAgentComponent(LLMServiceComponentBase, ABC):
|
|
|
185
186
|
action_response.action_idx = data.get("action_idx")
|
|
186
187
|
action_response.action_name = action_name
|
|
187
188
|
action_response.action_params = data.get("action_params", {})
|
|
189
|
+
action_response.originator = data.get("originator", ORCHESTRATOR_COMPONENT_NAME)
|
|
188
190
|
try:
|
|
189
191
|
action_response_dict = action_response.to_dict()
|
|
190
192
|
except Exception as e:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""PlantUML diagram"""
|
|
2
2
|
|
|
3
|
+
import platform
|
|
3
4
|
import os
|
|
4
5
|
import tempfile
|
|
5
6
|
import subprocess
|
|
@@ -41,6 +42,10 @@ class PlantUmlDiagram(Action):
|
|
|
41
42
|
)
|
|
42
43
|
|
|
43
44
|
def invoke(self, params, meta={}) -> ActionResponse:
|
|
45
|
+
if platform.system() == "Windows":
|
|
46
|
+
return ActionResponse(
|
|
47
|
+
message=f"Unfortunately, the PlantUML is not available on {platform.system()}"
|
|
48
|
+
)
|
|
44
49
|
# Do a local command to run plantuml -tpng
|
|
45
50
|
description = params.get("diagram_description")
|
|
46
51
|
agent = self.get_agent()
|
|
@@ -49,8 +54,15 @@ class PlantUmlDiagram(Action):
|
|
|
49
54
|
{"role": "user", "content": description},
|
|
50
55
|
]
|
|
51
56
|
agent = self.get_agent()
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
try:
|
|
58
|
+
response = agent.do_llm_service_request(messages=messages)
|
|
59
|
+
expression = response.get("content")
|
|
60
|
+
except TimeoutError as e:
|
|
61
|
+
log.error("LLM request timed out: %s", str(e))
|
|
62
|
+
return ActionResponse(message="LLM request timed out")
|
|
63
|
+
except Exception as e:
|
|
64
|
+
log.error("Failed to process content with LLM: %s", str(e))
|
|
65
|
+
return ActionResponse(message="Failed to process content with LLM")
|
|
54
66
|
|
|
55
67
|
# Surround expression with @startuml and @enduml if missing
|
|
56
68
|
if not expression.startswith("@startuml"):
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"""Plotly graph generation"""
|
|
2
2
|
|
|
3
|
+
import platform
|
|
3
4
|
import os
|
|
4
5
|
import random
|
|
5
6
|
import tempfile
|
|
6
7
|
import json
|
|
7
8
|
import yaml
|
|
9
|
+
from importlib.metadata import version
|
|
8
10
|
from io import BytesIO
|
|
11
|
+
from packaging.version import parse
|
|
9
12
|
from solace_ai_connector.common.log import log
|
|
10
13
|
|
|
11
14
|
import plotly.graph_objects as go
|
|
@@ -34,52 +37,58 @@ class PlotlyGraph(Action):
|
|
|
34
37
|
],
|
|
35
38
|
"required_scopes": ["global:plotly:read"],
|
|
36
39
|
"examples": [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
</example>
|
|
76
|
-
"""
|
|
40
|
+
{
|
|
41
|
+
"docstring": "This is an example of a user asking for a bar graph. The plotly action from the global agent is invoked to generate the graph.",
|
|
42
|
+
"tag_prefix_placeholder": "{tp}",
|
|
43
|
+
"starting_id": "12",
|
|
44
|
+
"user_input": "Please generate a random bar graph for me",
|
|
45
|
+
"metadata": [
|
|
46
|
+
"local_time: 2024-09-04 15:59:02 EDT-0400 (Wednesday)"
|
|
47
|
+
],
|
|
48
|
+
"reasoning": [
|
|
49
|
+
"- user has requested a random bar graph",
|
|
50
|
+
"- invoke the plotly action from the global agent to generate a bar graph with random data"
|
|
51
|
+
],
|
|
52
|
+
"response_text": "Certainly! I'd be happy to generate a random bar graph for you.",
|
|
53
|
+
"status_update": "I'll use our plotting tool to create this for you right away.",
|
|
54
|
+
"action": {
|
|
55
|
+
"agent": "global",
|
|
56
|
+
"name": "plotly",
|
|
57
|
+
"parameter_name": "plotly_figure_config",
|
|
58
|
+
"parameters": {
|
|
59
|
+
"plotly_figure_config": [
|
|
60
|
+
"{{",
|
|
61
|
+
" \"data\": [",
|
|
62
|
+
" {{",
|
|
63
|
+
" \"x\": [\"A\", \"B\", \"C\", \"D\", \"E\"],",
|
|
64
|
+
" \"y\": [23, 45, 56, 78, 90],",
|
|
65
|
+
" \"type\": \"bar\"",
|
|
66
|
+
" }}",
|
|
67
|
+
" ],",
|
|
68
|
+
" \"layout\": {{",
|
|
69
|
+
" \"title\": \"Random Bar Graph\",",
|
|
70
|
+
" \"xaxis\": {{\"title\": \"Categories\"}},",
|
|
71
|
+
" \"yaxis\": {{\"title\": \"Values\"}}",
|
|
72
|
+
" }}",
|
|
73
|
+
"}}"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
77
78
|
],
|
|
78
79
|
},
|
|
79
80
|
**kwargs,
|
|
80
81
|
)
|
|
81
82
|
|
|
82
83
|
def invoke(self, params, meta={}) -> ActionResponse:
|
|
84
|
+
if platform.system() == "Windows":
|
|
85
|
+
kaleido_version = version('kaleido')
|
|
86
|
+
min_version = parse('0.1.0.post1')
|
|
87
|
+
max_version = parse('0.2.0')
|
|
88
|
+
if parse(kaleido_version) < min_version or parse(kaleido_version) >= max_version:
|
|
89
|
+
return ActionResponse(
|
|
90
|
+
message="For Windows users, the plotting functionality requires a specific version of Kaleido. Please refer to the documentation."
|
|
91
|
+
)
|
|
83
92
|
obj = params["plotly_figure_config"]
|
|
84
93
|
if isinstance(obj, str):
|
|
85
94
|
# Remove any leading/trailing quote characters
|
|
@@ -31,37 +31,31 @@ class DoWebRequest(Action):
|
|
|
31
31
|
],
|
|
32
32
|
"required_scopes": ["web_request:do_web_request:read"],
|
|
33
33
|
"examples": [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</{tp}invoke_action>
|
|
60
|
-
|
|
61
|
-
<{tp}status_update>Retrieving the latest weather data for Ottawa...</{tp}status_update>'
|
|
62
|
-
</example_response>
|
|
63
|
-
</example>
|
|
64
|
-
"""
|
|
34
|
+
{
|
|
35
|
+
"docstring": "This is an example of a user requesting to fetch information from the web. The web_request agent is open so invoke the do_web_request action to fetch the content from the url and process the information according to the llm_prompt.",
|
|
36
|
+
"tag_prefix_placeholder": "{tp}",
|
|
37
|
+
"starting_id": "10",
|
|
38
|
+
"user_input": "What is the weather in Ottawa?",
|
|
39
|
+
"metadata": [
|
|
40
|
+
"local_time: 2024-11-06 12:33:12 EST-0500 (Wednesday)"
|
|
41
|
+
],
|
|
42
|
+
"reasoning": [
|
|
43
|
+
"- User is asking for current weather information in Ottawa",
|
|
44
|
+
"- We need to fetch up-to-date weather data",
|
|
45
|
+
"- Use the web_request agent to get the latest weather information",
|
|
46
|
+
"- Plan to use the Environment Canada website for accurate local weather data"
|
|
47
|
+
],
|
|
48
|
+
"response_text": "Certainly! I'll fetch the current weather information for Ottawa for you right away.",
|
|
49
|
+
"status_update": "Retrieving the latest weather data for Ottawa...",
|
|
50
|
+
"action": {
|
|
51
|
+
"agent": "web_request",
|
|
52
|
+
"name": "do_web_request",
|
|
53
|
+
"parameters": {
|
|
54
|
+
"url": "https://weather.gc.ca/city/pages/on-118_metric_e.html",
|
|
55
|
+
"llm_prompt": "Extract the current temperature, weather conditions, and any important weather alerts or warnings for Ottawa from the webpage. Format the response as a bulleted list with emoji where appropriate."
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
65
59
|
],
|
|
66
60
|
},
|
|
67
61
|
**kwargs,
|
|
@@ -127,8 +121,15 @@ class DoWebRequest(Action):
|
|
|
127
121
|
]
|
|
128
122
|
|
|
129
123
|
agent = self.get_agent()
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
try:
|
|
125
|
+
response = agent.do_llm_service_request(messages=messages)
|
|
126
|
+
content = response.get("content")
|
|
127
|
+
except TimeoutError as e:
|
|
128
|
+
log.error("LLM request timed out: %s", str(e))
|
|
129
|
+
return ActionResponse(message="LLM request timed out")
|
|
130
|
+
except Exception as e:
|
|
131
|
+
log.error("Failed to process content with LLM: %s", str(e))
|
|
132
|
+
return ActionResponse(message="Failed to process content with LLM")
|
|
132
133
|
|
|
133
134
|
# Code to create the image using the provided content
|
|
134
135
|
return ActionResponse(message=content)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
import click
|
|
4
|
+
import re
|
|
4
5
|
|
|
5
|
-
from cli.utils import get_display_path, load_template, log_error, get_formatted_names
|
|
6
|
+
from cli.utils import get_display_path, load_template, log_error, get_formatted_names, log_warning
|
|
6
7
|
from cli.commands.plugin.build import get_all_plugin_gateway_interfaces
|
|
7
8
|
from cli.config import Config
|
|
8
9
|
|
|
@@ -34,6 +35,126 @@ def _add_python_files(modules_directory, template_args, created_file_names):
|
|
|
34
35
|
f.write(gateway_template)
|
|
35
36
|
created_file_names.append(gateway_path)
|
|
36
37
|
|
|
38
|
+
def _update_gateway_yaml(yaml_string, interface_gateway_config):
|
|
39
|
+
# Update system_purpose
|
|
40
|
+
if "system_purpose" in interface_gateway_config:
|
|
41
|
+
yaml_string = re.sub(
|
|
42
|
+
r'(system_purpose: >\n\s+)(.*?)(?=\n\s{4}\S)',
|
|
43
|
+
lambda m: f'{m.group(1)}{interface_gateway_config["system_purpose"]}',
|
|
44
|
+
yaml_string,
|
|
45
|
+
flags=re.DOTALL
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Update interaction_type
|
|
49
|
+
if "interaction_type" in interface_gateway_config:
|
|
50
|
+
yaml_string = re.sub(
|
|
51
|
+
r'(interaction_type: )".*?"',
|
|
52
|
+
lambda m: f'{m.group(1)}"{interface_gateway_config["interaction_type"]}"',
|
|
53
|
+
yaml_string
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Update history settings
|
|
57
|
+
history_config = interface_gateway_config.get("history", {})
|
|
58
|
+
if not history_config.get("enabled", False):
|
|
59
|
+
yaml_string = re.sub(r'\n\s+history_config: \n\s+<<: \*default_history_policy', '', yaml_string)
|
|
60
|
+
yaml_string = re.sub(r'(retain_history: )true', r'\1false', yaml_string)
|
|
61
|
+
yaml_string = re.sub(
|
|
62
|
+
r'\n- history_policy:.*?(?=\n\n)',
|
|
63
|
+
'',
|
|
64
|
+
yaml_string,
|
|
65
|
+
flags=re.DOTALL
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
else:
|
|
69
|
+
if history_config.get("type") is not None:
|
|
70
|
+
yaml_string = re.sub(
|
|
71
|
+
r'(type: )".*?"',
|
|
72
|
+
lambda m: f'{m.group(1)}"{history_config.get("type")}"',
|
|
73
|
+
yaml_string,
|
|
74
|
+
count=1 # Update only the first occurrence
|
|
75
|
+
)
|
|
76
|
+
if history_config.get("time_to_live") is not None:
|
|
77
|
+
yaml_string = re.sub(
|
|
78
|
+
r'(time_to_live: )\d+',
|
|
79
|
+
lambda m: f'{m.group(1)}{history_config.get("time_to_live")}',
|
|
80
|
+
yaml_string
|
|
81
|
+
)
|
|
82
|
+
if history_config.get("expiration_check_interval") is not None:
|
|
83
|
+
yaml_string = re.sub(
|
|
84
|
+
r'(expiration_check_interval: )\d+',
|
|
85
|
+
lambda m: f'{m.group(1)}{history_config.get("expiration_check_interval")}',
|
|
86
|
+
yaml_string
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if history_config.get("max_turns") is not None:
|
|
90
|
+
yaml_string = re.sub(
|
|
91
|
+
r'(max_turns: )\d+',
|
|
92
|
+
lambda m: f'{m.group(1)}{history_config.get("max_turns")}',
|
|
93
|
+
yaml_string
|
|
94
|
+
)
|
|
95
|
+
if history_config.get("max_characters") is not None:
|
|
96
|
+
yaml_string = re.sub(
|
|
97
|
+
r'(max_characters: )\d+',
|
|
98
|
+
lambda m: f'{m.group(1)}{history_config.get("max_characters")}',
|
|
99
|
+
yaml_string
|
|
100
|
+
)
|
|
101
|
+
if history_config.get("enforce_alternate_message_roles") is not None:
|
|
102
|
+
yaml_string = re.sub(
|
|
103
|
+
r'(enforce_alternate_message_roles: )\w+',
|
|
104
|
+
lambda m: f'{m.group(1)}{str(history_config.get("enforce_alternate_message_roles", True)).lower()}',
|
|
105
|
+
yaml_string
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Inject long-term memory before history_policy
|
|
109
|
+
if history_config.get("long_term_memory", {}).get("enabled", False):
|
|
110
|
+
# Build llm_config string
|
|
111
|
+
llm_config_items = history_config['long_term_memory'].get('llm_config', {})
|
|
112
|
+
if llm_config_items:
|
|
113
|
+
llm_config_parts = []
|
|
114
|
+
for key, value in llm_config_items.items():
|
|
115
|
+
llm_config_parts.append(f"{key}: {value}")
|
|
116
|
+
llm_config = "\n " + "\n ".join(llm_config_parts) + "\n"
|
|
117
|
+
else:
|
|
118
|
+
llm_config = " {} \n"
|
|
119
|
+
|
|
120
|
+
# Build store_config string
|
|
121
|
+
store_config_items = history_config['long_term_memory'].get('store_config', {})
|
|
122
|
+
if store_config_items:
|
|
123
|
+
store_config_parts = []
|
|
124
|
+
for key, value in store_config_items.items():
|
|
125
|
+
store_config_parts.append(f"{key}: {value}")
|
|
126
|
+
store_config = "\n " + "\n ".join(store_config_parts) + "\n"
|
|
127
|
+
else:
|
|
128
|
+
store_config = " {} \n"
|
|
129
|
+
long_term_yaml = (
|
|
130
|
+
'long_term_memory: true\n'
|
|
131
|
+
' long_term_memory_config:\n'
|
|
132
|
+
f' llm_config:{llm_config}'
|
|
133
|
+
f' store_config:{store_config}'
|
|
134
|
+
' '
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
if "long_term_memory:" not in yaml_string:
|
|
138
|
+
yaml_string = re.sub(
|
|
139
|
+
r'(history_policy: # History provider configs.*?\n(\s+max_turns: \d+))',
|
|
140
|
+
lambda m: f'{long_term_yaml}{m.group(1)}',
|
|
141
|
+
yaml_string,
|
|
142
|
+
flags=re.DOTALL
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# Inject type_config under history_policy
|
|
146
|
+
type_config = history_config.get("type_config", {})
|
|
147
|
+
if type_config:
|
|
148
|
+
type_config_yaml = '\n'.join([f' {key}: {value}' for key, value in type_config.items()])
|
|
149
|
+
yaml_string = re.sub(
|
|
150
|
+
r'(history_policy: # History provider configs.*?)\n',
|
|
151
|
+
lambda m: f'{m.group(1)}\n{type_config_yaml}\n',
|
|
152
|
+
yaml_string,
|
|
153
|
+
flags=re.DOTALL
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
return yaml_string
|
|
157
|
+
|
|
37
158
|
def add_gateway_command(name, interfaces):
|
|
38
159
|
"""
|
|
39
160
|
Creates a gateway configuration directory and files based on provided templates.
|
|
@@ -76,7 +197,7 @@ def add_gateway_command(name, interfaces):
|
|
|
76
197
|
def abort():
|
|
77
198
|
sys.exit(1)
|
|
78
199
|
|
|
79
|
-
plugin_gateway_interfaces = get_all_plugin_gateway_interfaces(config, abort)
|
|
200
|
+
plugin_gateway_interfaces = get_all_plugin_gateway_interfaces(config, abort, return_plugin_config=True)
|
|
80
201
|
|
|
81
202
|
# Check if the gateway directory already exists
|
|
82
203
|
if os.path.exists(gateway_directory):
|
|
@@ -91,12 +212,11 @@ def add_gateway_command(name, interfaces):
|
|
|
91
212
|
|
|
92
213
|
# Create the gateway config file from the template directory
|
|
93
214
|
# The file name is gateway-default-config.yaml but write it as gateway.yaml in the gateway_directory
|
|
94
|
-
gateway_config_template = load_template("gateway-default-config.yaml")
|
|
95
215
|
gateway_config_path = os.path.join(gateway_directory, "gateway.yaml")
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
216
|
+
gateway_config_default = load_template("gateway-default-config.yaml")
|
|
217
|
+
gateway_config = gateway_config_default
|
|
218
|
+
gateway_config_interface_default_name = None # the interface name that is used for the default gateway config
|
|
219
|
+
gateway_config_overwritten = False
|
|
100
220
|
|
|
101
221
|
# If the interface list is not empty, create the interface config files
|
|
102
222
|
if interfaces:
|
|
@@ -105,8 +225,17 @@ def add_gateway_command(name, interfaces):
|
|
|
105
225
|
# The name will be {interface}-default-config.yaml
|
|
106
226
|
# Write the file as {interface}.yaml in the gateway_directory
|
|
107
227
|
if interface in plugin_gateway_interfaces:
|
|
228
|
+
interface_gateway_config = plugin_gateway_interfaces[interface][1]
|
|
229
|
+
# Checking if the interface has default values for the gateway.yaml
|
|
230
|
+
if interface_gateway_config:
|
|
231
|
+
# Checking if another interface has already been used to create the gateway.yaml
|
|
232
|
+
if gateway_config_interface_default_name:
|
|
233
|
+
# Overwrite the default gateway config with the current interface config
|
|
234
|
+
gateway_config_overwritten = True
|
|
235
|
+
gateway_config_interface_default_name = interface
|
|
236
|
+
gateway_config = _update_gateway_yaml(gateway_config_default, interface_gateway_config)
|
|
108
237
|
interface_default_path = os.path.join(
|
|
109
|
-
plugin_gateway_interfaces[interface],
|
|
238
|
+
plugin_gateway_interfaces[interface][0],
|
|
110
239
|
f"{interface}-default-config.yaml",
|
|
111
240
|
)
|
|
112
241
|
if not os.path.exists(interface_default_path):
|
|
@@ -149,6 +278,17 @@ def add_gateway_command(name, interfaces):
|
|
|
149
278
|
log_error(f"Error creating gateway, gateway config was created: {e}")
|
|
150
279
|
return 1
|
|
151
280
|
|
|
281
|
+
with open(gateway_config_path, "w", encoding="utf-8") as f:
|
|
282
|
+
f.write(gateway_config)
|
|
283
|
+
|
|
284
|
+
if gateway_config_overwritten:
|
|
285
|
+
log_warning(("Multiple interface configurations found. "
|
|
286
|
+
"Overwriting default gateway configuration with "
|
|
287
|
+
f"{gateway_config_interface_default_name} interface configuration."
|
|
288
|
+
))
|
|
289
|
+
|
|
290
|
+
created_file_names.append(gateway_config_path)
|
|
291
|
+
|
|
152
292
|
temp_file = os.path.join(config_directory, "__TEMPLATES_WILL_BE_HERE__")
|
|
153
293
|
if os.path.exists(temp_file):
|
|
154
294
|
os.remove(temp_file)
|
|
@@ -169,7 +309,8 @@ def add_interface_command(name):
|
|
|
169
309
|
Creates a new gateway interface with the provided name.
|
|
170
310
|
"""
|
|
171
311
|
config = Config.get_plugin_config()
|
|
172
|
-
|
|
312
|
+
plugin_config = config.get("solace_agent_mesh_plugin", {})
|
|
313
|
+
plugin_name = plugin_config.get("name")
|
|
173
314
|
if not plugin_name or plugin_name == "solace-agent-mesh-plugin":
|
|
174
315
|
log_error("Could not find a valid plugin project")
|
|
175
316
|
return 1
|
|
@@ -210,6 +351,18 @@ def add_interface_command(name):
|
|
|
210
351
|
|
|
211
352
|
_add_python_files(modules_directory, template_args, created_file_names)
|
|
212
353
|
|
|
354
|
+
# Update the 'solace-agent-mesh-plugin' configuration file
|
|
355
|
+
plugin_config["includes_gateway_interface"] = True
|
|
356
|
+
plugin_gateway_config_template = load_template("plugin-gateway-default-config.yaml", parser=Config.get_yaml_parser())
|
|
357
|
+
if not plugin_gateway_config_template:
|
|
358
|
+
log_error("Error: Plugin gateway config template not found.")
|
|
359
|
+
else:
|
|
360
|
+
if "interface_gateway_configs" not in plugin_config:
|
|
361
|
+
plugin_config["interface_gateway_configs"] = {}
|
|
362
|
+
plugin_config["interface_gateway_configs"][template_args["HYPHENED_NAME"]] = plugin_gateway_config_template.get("plugin_gateway_default_config", {})
|
|
363
|
+
Config.write_config(config, Config.user_plugin_config_file)
|
|
364
|
+
click.echo(f"Updated {Config.user_plugin_config_file} with default gateway interface configuration for {template_args['HYPHENED_NAME']}")
|
|
365
|
+
|
|
213
366
|
except IOError as e:
|
|
214
367
|
log_error(f"Error creating gateway interface, {e}")
|
|
215
368
|
return 1
|
|
@@ -10,12 +10,7 @@ def builtin_agent_step(options, default_options, none_interactive, abort):
|
|
|
10
10
|
"image_processing": (
|
|
11
11
|
True,
|
|
12
12
|
"generate images from text or convert images to text (The model name should be formatted like provider/model-name)",
|
|
13
|
-
["
|
|
14
|
-
),
|
|
15
|
-
"slack": (
|
|
16
|
-
False,
|
|
17
|
-
"Slack agent, send messages to Slack channels",
|
|
18
|
-
["MONITOR_SLACK_BOT_TOKEN="],
|
|
13
|
+
["IMAGE_GEN_ENDPOINT=", "IMAGE_GEN_API_KEY=", "IMAGE_GEN_MODEL=",],
|
|
19
14
|
),
|
|
20
15
|
}
|
|
21
16
|
|
|
@@ -7,6 +7,11 @@ def create_config_file_step(options, default_options, none_interactive, abort):
|
|
|
7
7
|
"""
|
|
8
8
|
Creates the configuration files.
|
|
9
9
|
"""
|
|
10
|
+
# Populate options dictionary with default values, for non specified options
|
|
11
|
+
for key, value in default_options.items():
|
|
12
|
+
if key not in options or options[key] is None:
|
|
13
|
+
options[key] = value
|
|
14
|
+
|
|
10
15
|
sam_config = Config.get_default_config()
|
|
11
16
|
|
|
12
17
|
# Set up the built-in agents
|
|
@@ -17,6 +17,57 @@ def add_pair_to_file_if_not_exists(file_path, pairs):
|
|
|
17
17
|
f.write(f"{key}{value}\n")
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def update_or_add_pairs_to_file(file_path, pairs):
|
|
21
|
+
"""
|
|
22
|
+
Updates existing key-value pairs in a file or adds them if they don't exist.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
file_path (str): The path to the file to update
|
|
26
|
+
pairs (list): A list of (key, value) tuples to update or add
|
|
27
|
+
"""
|
|
28
|
+
# Check if file exists
|
|
29
|
+
if os.path.exists(file_path):
|
|
30
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
31
|
+
lines = f.readlines()
|
|
32
|
+
else:
|
|
33
|
+
lines = []
|
|
34
|
+
|
|
35
|
+
# Create a dictionary of key-value pairs for quick lookup
|
|
36
|
+
pair_dict = {key: value for key, value in pairs}
|
|
37
|
+
updated_keys = set()
|
|
38
|
+
|
|
39
|
+
# Process each line
|
|
40
|
+
new_lines = []
|
|
41
|
+
for line in lines:
|
|
42
|
+
line = line.rstrip()
|
|
43
|
+
if not line or line.startswith("#"):
|
|
44
|
+
# Keep comments and empty lines
|
|
45
|
+
new_lines.append(line)
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
# Check if line contains any of our keys
|
|
49
|
+
found_key = None
|
|
50
|
+
for key in pair_dict:
|
|
51
|
+
if line.startswith(key + "=") or line.startswith(key + " ="):
|
|
52
|
+
found_key = key
|
|
53
|
+
updated_keys.add(key)
|
|
54
|
+
new_lines.append(f"{key}{pair_dict[key]}")
|
|
55
|
+
break
|
|
56
|
+
|
|
57
|
+
if not found_key:
|
|
58
|
+
# Keep lines that don't match our keys
|
|
59
|
+
new_lines.append(line)
|
|
60
|
+
|
|
61
|
+
# Add any new variables that weren't found
|
|
62
|
+
for key, value in pairs:
|
|
63
|
+
if key not in updated_keys:
|
|
64
|
+
new_lines.append(f"{key}{value}")
|
|
65
|
+
|
|
66
|
+
# Write the updated content back to the file
|
|
67
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
68
|
+
f.write("\n".join(new_lines) + "\n")
|
|
69
|
+
|
|
70
|
+
|
|
20
71
|
def create_other_project_files_step(options, default_options, none_interactive, abort):
|
|
21
72
|
"""
|
|
22
73
|
Creates the other project files. i.e. .gitignore, .env, requirements.txt, etc.
|
|
@@ -92,5 +143,5 @@ def create_other_project_files_step(options, default_options, none_interactive,
|
|
|
92
143
|
required_env_variables.append((key, f"={value}"))
|
|
93
144
|
|
|
94
145
|
create_if_not_exists(options["env_file"], "")
|
|
95
|
-
|
|
146
|
+
update_or_add_pairs_to_file(options["env_file"], required_env_variables)
|
|
96
147
|
add_gateway_command(options["rest_api_gateway_name"],["rest-api"])
|
|
@@ -9,8 +9,6 @@ from .create_config_file_step import create_config_file_step
|
|
|
9
9
|
from .file_service_step import file_service_step
|
|
10
10
|
from .project_structure_step import project_structure_step
|
|
11
11
|
from .create_other_project_files_step import create_other_project_files_step
|
|
12
|
-
from .rest_api_step import rest_api_step
|
|
13
|
-
from .web_ui_step import webui_step
|
|
14
12
|
|
|
15
13
|
from cli.utils import (
|
|
16
14
|
log_error,
|
|
@@ -45,7 +43,7 @@ default_options = {
|
|
|
45
43
|
"rest_api_gateway_name": "rest-api",
|
|
46
44
|
"webui_enabled": True,
|
|
47
45
|
"webui_listen_port": "5001",
|
|
48
|
-
"webui_host": "
|
|
46
|
+
"webui_host": "127.0.0.1"
|
|
49
47
|
}
|
|
50
48
|
"""
|
|
51
49
|
Default options for the init command.
|
|
@@ -76,8 +74,6 @@ def init_command(options={}):
|
|
|
76
74
|
("AI provider setup", ai_provider_step),
|
|
77
75
|
("Builtin agent setup", builtin_agent_step),
|
|
78
76
|
("File service setup", file_service_step),
|
|
79
|
-
("REST API setup", rest_api_step),
|
|
80
|
-
("Web UI setup", webui_step),
|
|
81
77
|
("", create_config_file_step),
|
|
82
78
|
("Setting up project", create_other_project_files_step),
|
|
83
79
|
]
|
|
@@ -14,32 +14,3 @@ def project_structure_step(options, default_options, none_interactive, abort):
|
|
|
14
14
|
)
|
|
15
15
|
if namespace and not namespace.endswith("/"):
|
|
16
16
|
options["namespace"] = f"{namespace}/"
|
|
17
|
-
|
|
18
|
-
ask_if_not_provided(
|
|
19
|
-
options,
|
|
20
|
-
"config_dir",
|
|
21
|
-
"Enter base directory for config files",
|
|
22
|
-
default_options["config_dir"],
|
|
23
|
-
none_interactive,
|
|
24
|
-
)
|
|
25
|
-
ask_if_not_provided(
|
|
26
|
-
options,
|
|
27
|
-
"module_dir",
|
|
28
|
-
"Enter base directory for python modules",
|
|
29
|
-
default_options["module_dir"],
|
|
30
|
-
none_interactive,
|
|
31
|
-
)
|
|
32
|
-
ask_if_not_provided(
|
|
33
|
-
options,
|
|
34
|
-
"build_dir",
|
|
35
|
-
"Enter base directory for the build output",
|
|
36
|
-
default_options["build_dir"],
|
|
37
|
-
none_interactive,
|
|
38
|
-
)
|
|
39
|
-
ask_if_not_provided(
|
|
40
|
-
options,
|
|
41
|
-
"env_file",
|
|
42
|
-
"Enter environment file path",
|
|
43
|
-
default_options["env_file"],
|
|
44
|
-
none_interactive,
|
|
45
|
-
)
|