|
| 1 | +# Documentation: DatabaseAgent Module |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `DatabaseAgent` module is designed to facilitate interaction with a database by generating and executing appropriate SQL queries. It uses machine learning to understand and interpret user tasks and generates an execution plan to gather and process necessary data from a database using the specified database dialect (e.g., SQL). |
| 6 | + |
| 7 | +The main functionality is encapsulated within a class called `DatabaseAgent`, which leverages the `AgenticStrategyV2` to dynamically generate responses to user tasks. This agent uses the `AioLlmClient` and `DatabaseQueryTool` to perform its operations, geared towards summarizing conversations and fetching data based on user prompts. |
| 8 | + |
| 9 | +## Inputs |
| 10 | + |
| 11 | +### DatabaseAgent Inputs Class |
| 12 | + |
| 13 | +In the file `typed.py`, the `DatabaseAgentInputs` class defines the input structure that the `DatabaseAgent` expects: |
| 14 | + |
| 15 | +- **task (str):** A string describing the task that needs completion. |
| 16 | +- **db_dialect (str):** Specifies the type of SQL dialect the database uses (e.g., MySQL, PostgreSQL). |
| 17 | +- **db_driver (str):** The database driver used for connections. |
| 18 | +- **db_username (str):** Username for database authentication. |
| 19 | +- **db_password (str):** Password for database authentication. |
| 20 | +- **db_host (str):** Host address of the database. |
| 21 | +- **db_port (int):** Port number for database connection. |
| 22 | +- **db_name (str):** Name of the database. |
| 23 | +- **db_params (dict):** Additional connection parameters. |
| 24 | +- **db_driver_args (dict):** Additional driver-specific arguments. |
| 25 | +- **prompt_value (Dict[str, Any]):** Dictionary holding values for prompt customization. |
| 26 | +- **max_llm_calls (int):** Configures the maximum number of large language model calls. |
| 27 | +- **openai_api_key (str):** API key for OpenAI services. |
| 28 | +- **anthropic_api_key (str):** API key for Anthropic services. |
| 29 | +- **google_api_key (str):** API key for Google services. |
| 30 | +- **example_json (str):** A JSON example to guide response structure. |
| 31 | + |
| 32 | +## Outputs |
| 33 | + |
| 34 | +### DatabaseAgent Outputs Class |
| 35 | + |
| 36 | +Within `typed.py`, the `DatabaseAgentOutputs` class is introduced to outline the expected output format: |
| 37 | + |
| 38 | +- **request_tokens (int):** Number of tokens used in the request. |
| 39 | +- **response_tokens (int):** Number of tokens received in the response. |
| 40 | + |
| 41 | +## DatabaseAgent Implementation |
| 42 | + |
| 43 | +### Core Functionality |
| 44 | + |
| 45 | +In `DatabaseAgent.py`, the `DatabaseAgent` class derives from the `Step` class and uses both `DatabaseAgentInputs` and `DatabaseAgentOutputs`. The class: |
| 46 | + |
| 47 | +- Initializes an agentic strategy to process user-provided tasks and database information. |
| 48 | +- Sets up database query configurations through the `DatabaseQueryTool`. |
| 49 | +- Employs the `mustache_render` utility to tailor command-line interactions and strategy prompts. |
| 50 | +- Executes the task, restricting output operation to a maximum of ten results (`limit=10`). |
| 51 | + |
| 52 | +### `run` Method |
| 53 | + |
| 54 | +The `run` function executes the agent's strategy to fetch requested data and append execution usage metrics from the `AgenticStrategyV2`. |
| 55 | + |
| 56 | +By employing this module, users can expect an automated task execution environment, where high-level natural language prompts can seamlessly translate into concrete database operations. This setup is particularly useful for data analysis and management tasks that require flexible and interactive database querying capabilities. |
0 commit comments