Skip to content

Commit 1669b3f

Browse files
authored
Merge pull request #108 from Praveenk8051/feat/test-using-operator
feat(operator): enhance OperatorToolBox with AgentSpecification for better validation and configuration
2 parents 7cb321c + 4b8ab03 commit 1669b3f

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

agentic_security/probe_actor/operator.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,79 @@
22
from typing import Any
33

44
from pydantic_ai import Agent, RunContext
5+
from pydantic import BaseModel, Field
6+
from typing import Optional, List, Dict, Any
57

6-
# Define the OperatorToolBox class
78

9+
class AgentSpecification(BaseModel):
10+
name: Optional[str] = Field(None, description="Name of the LLM/agent")
11+
version: Optional[str] = Field(None, description="Version of the LLM/agent")
12+
description: Optional[str] = Field(None, description="Description of the LLM/agent")
13+
capabilities: Optional[List[str]] = Field(None, description="List of capabilities")
14+
configuration: Optional[Dict[str, Any]] = Field(None, description="Configuration settings")
815

16+
# Define the OperatorToolBox class
917
class OperatorToolBox:
10-
def __init__(self, llm_spec: str, datasets: list[dict[str, Any]]):
11-
self.llm_spec = llm_spec
18+
def __init__(self, spec: AgentSpecification, datasets: list[dict[str, Any]]):
19+
self.spec = spec
1220
self.datasets = datasets
21+
self.failures = []
1322

14-
def get_spec(self) -> str:
15-
return self.llm_spec
23+
def get_spec(self) -> AgentSpecification:
24+
return self.spec
1625

1726
def get_datasets(self) -> list[dict[str, Any]]:
1827
return self.datasets
1928

2029
def validate(self) -> bool:
21-
# Validate the tool box
30+
# Validate the tool box based on the specification
31+
if not self.spec.name or not self.spec.version:
32+
self.failures.append("Invalid specification: Name or version is missing.")
33+
return False
34+
if not self.datasets:
35+
self.failures.append("No datasets provided.")
36+
return False
2237
return True
2338

2439
def stop(self) -> None:
2540
# Stop the tool box
26-
pass
41+
print("Stopping the toolbox...")
2742

2843
def run(self) -> None:
2944
# Run the tool box
30-
pass
45+
print("Running the toolbox...")
3146

3247
def get_results(self) -> list[dict[str, Any]]:
3348
# Get the results
3449
return self.datasets
3550

3651
def get_failures(self) -> list[str]:
3752
# Handle failure
38-
return []
53+
return self.failures
3954

4055
def run_operation(self, operation: str) -> str:
41-
# Run an operation
56+
# Run an operation based on the specification
57+
if operation not in ["dataset1", "dataset2", "dataset3"]:
58+
self.failures.append(f"Operation '{operation}' failed: Dataset not found.")
59+
return f"Operation '{operation}' failed: Dataset not found."
4260
return f"Operation '{operation}' executed successfully."
4361

4462

63+
# Initialize OperatorToolBox with AgentSpecification
64+
spec = AgentSpecification(
65+
name="GPT-4",
66+
version="4.0",
67+
description="A powerful language model",
68+
capabilities=["text-generation", "question-answering"],
69+
configuration={"max_tokens": 100}
70+
)
71+
4572
# dataset_manager_agent.py
4673

4774

4875
# Initialize OperatorToolBox
4976
toolbox = OperatorToolBox(
50-
llm_spec="GPT-4", datasets=["dataset1", "dataset2", "dataset3"]
77+
spec=spec, datasets=["dataset1", "dataset2", "dataset3"]
5178
)
5279

5380
# Define the agent with OperatorToolBox as its dependency

0 commit comments

Comments
 (0)