Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/5113.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- description: Added AgentixAgent to test tools.
type: internal
pr_number: 5113
46 changes: 46 additions & 0 deletions TestSuite/agentix_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from pathlib import Path
from typing import Optional

from TestSuite.yml import YAML, yaml


class AgentixAgent(YAML):
def __init__(self, tmpdir: Path, name: str, repo):
# Save entities
self.name = name
self._repo = repo
self.repo_path = repo.path
self.path = str(tmpdir)
super().__init__(tmp_path=tmpdir / f"{self.name}.yml", repo_path=str(repo.path))

@property
def yml(self):
# for backward compatible
return self

def build(
self,
yml: Optional[dict] = None,
):
"""Writes not None objects to files."""
if yml is not None:
self.write_dict(yml)

def create_default_agentix_agent(
self,
name: str = "sample_agentix_agent",
agent_id: str = "sample_agentix_agent_id",
):
"""Creates a new agentix agent with basic data.
Args:
name: The name of the new agentix agent, default is "sample_agentix_agent".
agent_id: The ID of the new agentix agent, default is "sample_agentix_agent_id".
"""
default_agentix_agent_dir = (
Path(__file__).parent / "assets" / "default_agentix_agent"
)
with open(default_agentix_agent_dir / "agentix_agent-sample.yml") as yml_file:
yml = yaml.load(yml_file)
yml["id"] = agent_id
yml["name"] = name
self.build(yml=yml)
20 changes: 20 additions & 0 deletions TestSuite/assets/default_agentix_agent/agentix_agent-sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
commonfields:
id: sample_agentix_agent
version: -1
display: Sample Agentix Agent
name: Sample Agentix Agent
tags:
- gpt
- llm
category: AI & Machine Learning
description: |-
A sample agent for testing purposes.
color: "#FF0000"
conversationstarters:
- "What can you do?"
actionids:
- SampleAction
marketplaces:
- platform
supportedModules:
- agentix
20 changes: 20 additions & 0 deletions TestSuite/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from demisto_sdk.commands.common.constants import (
AGENTIX_ACTIONS_DIR,
AGENTIX_AGENTS_DIR,
ASSETS_MODELING_RULES_DIR,
CASE_FIELDS_DIR,
CASE_LAYOUT_RULES_DIR,
Expand All @@ -18,6 +19,7 @@
XSIAM_REPORTS_DIR,
)
from TestSuite.agentix_action import AgentixAction
from TestSuite.agentix_agent import AgentixAgent
from TestSuite.case_field import CaseField
from TestSuite.case_layout import CaseLayout
from TestSuite.case_layout_rule import CaseLayoutRule
Expand Down Expand Up @@ -121,6 +123,7 @@ def __init__(self, packs_dir: Path, name: str, repo):
self.case_layout_rules: List[CaseLayoutRule] = list()

self.agentix_actions: List[AgentixAction] = list()
self.agentix_agents: List[AgentixAgent] = list()

# Create base pack
self._pack_path = packs_dir / self.name
Expand Down Expand Up @@ -264,6 +267,9 @@ def __init__(self, packs_dir: Path, name: str, repo):
self._agentix_actions_path = self._pack_path / AGENTIX_ACTIONS_DIR
self._agentix_actions_path.mkdir(exist_ok=True)

self._agentix_agents_path = self._pack_path / AGENTIX_AGENTS_DIR
self._agentix_agents_path.mkdir(exist_ok=True)

super().__init__(self._pack_path)

def create_integration(
Expand Down Expand Up @@ -843,3 +849,17 @@ def create_agentix_action(
)
self.agentix_actions.append(agentix_action)
return agentix_action

def create_agentix_agent(
self,
name: Optional[str] = None,
yml: Optional[dict] = None,
) -> AgentixAgent:
if name is None:
name = f"agentix_agent-{len(self.agentix_agents)}"
agentix_agent = AgentixAgent(self._agentix_agents_path, name, self._repo)
agentix_agent.build(
yml,
)
self.agentix_agents.append(agentix_agent)
return agentix_agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
commonfields:
id: TestAgentixAgent
version: -1
display: Test Agentix Agent
name: TestAgentixAgent
tags:
- gpt
- llm
- generative-ai
category: AI & Machine Learning
description: |-
Test Agentix Agent for unit tests.
color: "#FF0000"
conversationstarters:
- "What can you do?"
- "Tell me about your capabilities."
actionids:
- TestAgentixAction
marketplaces:
- platform
supportedModules:
- agentix
30 changes: 30 additions & 0 deletions demisto_sdk/commands/validate/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json
from demisto_sdk.commands.common.tools import set_value
from demisto_sdk.commands.content_graph.objects.agentix_action import AgentixAction
from demisto_sdk.commands.content_graph.objects.agentix_agent import AgentixAgent
from demisto_sdk.commands.content_graph.objects.assets_modeling_rule import (
AssetsModelingRule,
)
Expand Down Expand Up @@ -50,6 +51,7 @@
from demisto_sdk.commands.content_graph.parsers.agentix_action import (
AgentixActionParser,
)
from demisto_sdk.commands.content_graph.parsers.agentix_agent import AgentixAgentParser
from demisto_sdk.commands.content_graph.parsers.pack import PackParser
from demisto_sdk.commands.content_graph.parsers.parsing_rule import (
ParsingRuleParser,
Expand Down Expand Up @@ -966,3 +968,31 @@ def create_agentix_action_object(
Path(agentix_action.path), list(MarketplaceVersions), pack_supported_modules=[]
)
return AgentixAction.from_orm(parser)


def create_agentix_agent_object(
paths: Optional[List[str]] = None,
values: Optional[List[Any]] = None,
pack_info: Optional[Dict[str, Any]] = None,
agent_name: Optional[str] = None,
) -> AgentixAgent:
"""Creating an agentix agent object with altered fields from a default agentix agent yml structure.
Returns:
The agentix agent object.
"""
yml_content = load_yaml("agentix_agent.yml")
update_keys(yml_content, paths, values)
pack = REPO.create_pack()
if pack_info:
pack.set_data(**pack_info)
additional_params = {}
if agent_name:
additional_params["name"] = agent_name

agentix_agent = pack.create_agentix_agent(**additional_params)
agentix_agent.create_default_agentix_agent()
agentix_agent.yml.update(yml_content)
parser = AgentixAgentParser(
Path(agentix_agent.path), list(MarketplaceVersions), pack_supported_modules=[]
)
return AgentixAgent.from_orm(parser)