|
2 | 2 | from typing import Any |
3 | 3 |
|
4 | 4 | from pydantic_ai import Agent, RunContext |
| 5 | +from pydantic import BaseModel, Field |
| 6 | +from typing import Optional, List, Dict, Any |
5 | 7 |
|
6 | | -# Define the OperatorToolBox class |
7 | 8 |
|
| 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") |
8 | 15 |
|
| 16 | +# Define the OperatorToolBox class |
9 | 17 | 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 |
12 | 20 | self.datasets = datasets |
| 21 | + self.failures = [] |
13 | 22 |
|
14 | | - def get_spec(self) -> str: |
15 | | - return self.llm_spec |
| 23 | + def get_spec(self) -> AgentSpecification: |
| 24 | + return self.spec |
16 | 25 |
|
17 | 26 | def get_datasets(self) -> list[dict[str, Any]]: |
18 | 27 | return self.datasets |
19 | 28 |
|
20 | 29 | 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 |
22 | 37 | return True |
23 | 38 |
|
24 | 39 | def stop(self) -> None: |
25 | 40 | # Stop the tool box |
26 | | - pass |
| 41 | + print("Stopping the toolbox...") |
27 | 42 |
|
28 | 43 | def run(self) -> None: |
29 | 44 | # Run the tool box |
30 | | - pass |
| 45 | + print("Running the toolbox...") |
31 | 46 |
|
32 | 47 | def get_results(self) -> list[dict[str, Any]]: |
33 | 48 | # Get the results |
34 | 49 | return self.datasets |
35 | 50 |
|
36 | 51 | def get_failures(self) -> list[str]: |
37 | 52 | # Handle failure |
38 | | - return [] |
| 53 | + return self.failures |
39 | 54 |
|
40 | 55 | 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." |
42 | 60 | return f"Operation '{operation}' executed successfully." |
43 | 61 |
|
44 | 62 |
|
| 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 | + |
45 | 72 | # dataset_manager_agent.py |
46 | 73 |
|
47 | 74 |
|
48 | 75 | # Initialize OperatorToolBox |
49 | 76 | toolbox = OperatorToolBox( |
50 | | - llm_spec="GPT-4", datasets=["dataset1", "dataset2", "dataset3"] |
| 77 | + spec=spec, datasets=["dataset1", "dataset2", "dataset3"] |
51 | 78 | ) |
52 | 79 |
|
53 | 80 | # Define the agent with OperatorToolBox as its dependency |
|
0 commit comments