|
| 1 | +# Operator Module |
| 2 | + |
| 3 | +The `operator.py` module provides tools for managing and operating on datasets using an agent-based approach. It is designed to facilitate the execution of operations on datasets through a structured and validated process. |
| 4 | + |
| 5 | +## Classes |
| 6 | + |
| 7 | +### AgentSpecification |
| 8 | + |
| 9 | +Defines the specification for an LLM/agent: |
| 10 | + |
| 11 | +- `name`: Name of the LLM/agent |
| 12 | +- `version`: Version of the LLM/agent |
| 13 | +- `description`: Description of the LLM/agent |
| 14 | +- `capabilities`: List of capabilities |
| 15 | +- `configuration`: Configuration settings |
| 16 | + |
| 17 | +### OperatorToolBox |
| 18 | + |
| 19 | +Main class for dataset operations: |
| 20 | + |
| 21 | +- `__init__(spec: AgentSpecification, datasets: list[dict[str, Any]])`: Initialize with agent spec and datasets. This sets up the toolbox with the necessary specifications and datasets for operation. |
| 22 | +- `get_spec()`: Get the agent specification. Returns the `AgentSpecification` object associated with the toolbox. |
| 23 | +- `get_datasets()`: Get the datasets. Returns a list of datasets that the toolbox operates on. |
| 24 | +- `validate()`: Validate the toolbox. Checks if the toolbox is correctly set up with valid specifications and datasets. |
| 25 | +- `stop()`: Stop the toolbox. Halts any ongoing operations within the toolbox. |
| 26 | +- `run()`: Run the toolbox. Initiates the execution of operations as defined in the toolbox. |
| 27 | +- `get_results()`: Get operation results. Retrieves the results of operations performed by the toolbox. |
| 28 | +- `get_failures()`: Get failures. Provides a list of any failures encountered during operations. |
| 29 | +- `run_operation(operation: str)`: Run a specific operation. Executes a given operation on the datasets, returning the result or failure message. |
| 30 | + |
| 31 | +## Agent Tools |
| 32 | + |
| 33 | +The `dataset_manager_agent` provides these tools: |
| 34 | + |
| 35 | +### validate_toolbox |
| 36 | + |
| 37 | +Validates the OperatorToolBox: |
| 38 | + |
| 39 | +```python |
| 40 | +@dataset_manager_agent.tool |
| 41 | +async def validate_toolbox(ctx: RunContext[OperatorToolBox]) -> str |
| 42 | +``` |
| 43 | + |
| 44 | +### execute_operation |
| 45 | + |
| 46 | +Executes an operation on a dataset: |
| 47 | + |
| 48 | +```python |
| 49 | +@dataset_manager_agent.tool |
| 50 | +async def execute_operation(ctx: RunContext[OperatorToolBox], operation: str) -> str |
| 51 | +``` |
| 52 | + |
| 53 | +### retrieve_results |
| 54 | + |
| 55 | +Retrieves operation results: |
| 56 | + |
| 57 | +```python |
| 58 | +@dataset_manager_agent.tool |
| 59 | +async def retrieve_results(ctx: RunContext[OperatorToolBox]) -> str |
| 60 | +``` |
| 61 | + |
| 62 | +### retrieve_failures |
| 63 | + |
| 64 | +Retrieves failures: |
| 65 | + |
| 66 | +```python |
| 67 | +@dataset_manager_agent.tool |
| 68 | +async def retrieve_failures(ctx: RunContext[OperatorToolBox]) -> str |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage Examples |
| 72 | + |
| 73 | +### Initializing the OperatorToolBox |
| 74 | + |
| 75 | +To initialize the `OperatorToolBox`, you need to provide an `AgentSpecification` and a list of datasets: |
| 76 | + |
| 77 | +```python |
| 78 | +spec = AgentSpecification( |
| 79 | + name="GPT-4", |
| 80 | + version="4.0", |
| 81 | + description="A powerful language model", |
| 82 | + capabilities=["text-generation", "question-answering"], |
| 83 | + configuration={"max_tokens": 100}, |
| 84 | +) |
| 85 | + |
| 86 | +datasets = [{"name": "dataset1"}, {"name": "dataset2"}] |
| 87 | + |
| 88 | +toolbox = OperatorToolBox(spec=spec, datasets=datasets) |
| 89 | +``` |
| 90 | + |
| 91 | +### Synchronous Usage |
| 92 | + |
| 93 | +```python |
| 94 | +def run_dataset_manager_agent_sync(): |
| 95 | + prompts = [ |
| 96 | + "Validate the toolbox.", |
| 97 | + "Execute operation on 'dataset2'.", |
| 98 | + "Retrieve the results.", |
| 99 | + "Retrieve any failures." |
| 100 | + ] |
| 101 | + |
| 102 | + for prompt in prompts: |
| 103 | + result = dataset_manager_agent.run_sync(prompt, deps=toolbox) |
| 104 | + print(f"Response: {result.data}") |
| 105 | +``` |
| 106 | + |
| 107 | +### Asynchronous Usage |
| 108 | + |
| 109 | +```python |
| 110 | +async def run_dataset_manager_agent_async(): |
| 111 | + prompts = [ |
| 112 | + "Validate the toolbox.", |
| 113 | + "Execute operation on 'dataset2'.", |
| 114 | + "Retrieve the results.", |
| 115 | + "Retrieve any failures." |
| 116 | + ] |
| 117 | + |
| 118 | + for prompt in prompts: |
| 119 | + result = await dataset_manager_agent.run(prompt, deps=toolbox) |
| 120 | + print(f"Response: {result.data}") |
| 121 | +``` |
| 122 | + |
| 123 | +These updates provide a more detailed and comprehensive understanding of the `operator.py` module, its classes, and its usage. |
0 commit comments