diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 9286cae1..e1214b24 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,7 +6,7 @@ on: - main # any branch other than main, will use the test key - test - workflow_dispatch: + workflow_dispatch: jobs: setup-and-test: @@ -31,7 +31,8 @@ jobs: 'finetune_v2', 'general_assets', 'apikey', - 'agent_and_team_agent', + 'agent', + 'team_agent', ] include: - test-suite: 'unit' @@ -79,9 +80,13 @@ jobs: - test-suite: 'apikey' path: 'tests/functional/apikey' timeout: 45 - - test-suite: 'agent_and_team_agent' - path: 'tests/functional/agent tests/functional/team_agent' + - test-suite: 'agent' + path: 'tests/functional/agent' timeout: 45 + - test-suite: 'team_agent' + path: 'tests/functional/team_agent' + timeout: 45 + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -91,7 +96,7 @@ jobs: with: python-version: "3.9" cache: 'pip' - + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -112,7 +117,7 @@ jobs: fi echo "SLACK_TOKEN=${{ secrets.SLACK_TOKEN }}" >> $GITHUB_ENV echo "HF_TOKEN=${{ secrets.HF_TOKEN }}" >> $GITHUB_ENV - + - name: Run Tests timeout-minutes: ${{ matrix.timeout }} run: python -m pytest ${{ matrix.path }} diff --git a/aixplain/factories/team_agent_factory/utils.py b/aixplain/factories/team_agent_factory/utils.py index 2441d9db..3d4c15ed 100644 --- a/aixplain/factories/team_agent_factory/utils.py +++ b/aixplain/factories/team_agent_factory/utils.py @@ -10,12 +10,11 @@ from aixplain.modules.agent.agent_task import AgentTask from aixplain.modules.agent.tool.model_tool import ModelTool from aixplain.modules.team_agent import TeamAgent, InspectorTarget -from aixplain.modules.team_agent.inspector import Inspector, InspectorAction, InspectorAuto, InspectorPolicy, InspectorOutput +from aixplain.modules.team_agent.inspector import Inspector from aixplain.factories.agent_factory import AgentFactory from aixplain.factories.model_factory import ModelFactory from aixplain.modules.model.model_parameters import ModelParameters from aixplain.modules.agent.output_format import OutputFormat -from aixplain.modules.model.response import ModelResponse GPT_4o_ID = "6646261c6eb563165658bbb1" SUPPORTED_TOOLS = ["llm", "website_search", "website_scrape", "website_crawl", "serper_search"] @@ -155,51 +154,6 @@ def get_cached_model(model_id: str) -> any: elif tool["description"] == "mentalist": mentalist_llm = llm - resolved_model_id = payload.get("llmId", None) - if not resolved_model_id: - resolved_model_id = GPT_4o_ID - has_quality_check = any( - (getattr(ins, "name", "") or "").lower() == "qualitycheckinspector" - for ins in inspectors - ) - if not has_quality_check: - try: - def process_response(model_response: ModelResponse, input_content: str) -> InspectorOutput: - critiques = model_response.data - action = InspectorAction.RERUN - return InspectorOutput(critiques=critiques, content_edited=input_content, action=action) - - default_inspector = Inspector( - name="QualityCheckInspector", - model_id=resolved_model_id, - model_params={"prompt": "Analyze content to ensure correctness of response"}, - policy=process_response, - auto=InspectorAuto.ALIGNMENT - ) - - inspectors = [default_inspector] + inspectors - inspector_targets = payload.get("inspectorTargets", inspector_targets if 'inspector_targets' in locals() else []) - if isinstance(inspector_targets, (str, InspectorTarget)): - inspector_targets = [inspector_targets] - normalized = [] - for t in inspector_targets: - if isinstance(t, InspectorTarget): - normalized.append(t) - elif isinstance(t, str): - try: - normalized.append(InspectorTarget(t.lower())) - except Exception: - logging.warning(f"Ignoring unknown inspector target: {t!r}") - else: - logging.warning(f"Ignoring inspector target with unexpected type: {type(t)}") - - if InspectorTarget.STEPS not in normalized: - normalized.append(InspectorTarget.STEPS) - - inspector_targets = normalized - - except Exception as e: - logging.warning(f"Failed to add default QualityCheckInspector: {e}") team_agent = TeamAgent( id=payload.get("id", ""), diff --git a/aixplain/modules/agent/__init__.py b/aixplain/modules/agent/__init__.py index 18483076..d76cf381 100644 --- a/aixplain/modules/agent/__init__.py +++ b/aixplain/modules/agent/__init__.py @@ -393,9 +393,6 @@ def _format_agent_progress( if tool: msg = f"⚙️ {agent_name} | {tool} | {status_icon}" - if runtime is not None and runtime > 0 and success is not None: - msg += f" ({runtime:.1f} s)" - if tool_input: msg += f" | Input: {tool_input}" @@ -604,11 +601,11 @@ def run( Dict: parsed output from model """ start = time.time() - + # Extract deprecated parameters from kwargs output_format = kwargs.get("output_format", None) expected_output = kwargs.get("expected_output", None) - + if output_format is not None: warnings.warn( "The 'output_format' parameter is deprecated and will be removed in a future version. " @@ -616,7 +613,7 @@ def run( DeprecationWarning, stacklevel=2, ) - + if expected_output is not None: warnings.warn( "The 'expected_output' parameter is deprecated and will be removed in a future version. " @@ -624,7 +621,7 @@ def run( DeprecationWarning, stacklevel=2, ) - + if session_id is not None and history is not None: raise ValueError("Provide either `session_id` or `history`, not both.") @@ -661,7 +658,7 @@ def run( poll_url, name=name, timeout=timeout, wait_time=wait_time, progress_verbosity=progress_verbosity ) if result.status == ResponseStatus.FAILED: - raise Exception("Model failed to run with error: " + result.error_message) + raise Exception("Model failed to run with error: " + result.error_message) result_data = result.get("data") or {} return AgentResponse( status=ResponseStatus.SUCCESS, diff --git a/aixplain/modules/team_agent/__init__.py b/aixplain/modules/team_agent/__init__.py index 09d444be..4b512ce2 100644 --- a/aixplain/modules/team_agent/__init__.py +++ b/aixplain/modules/team_agent/__init__.py @@ -103,7 +103,7 @@ class TeamAgent(Model, DeployableMixin[Agent]): instructions (Optional[Text]): Instructions to guide the team agent. output_format (OutputFormat): Response format. Defaults to TEXT. expected_output (Optional[Union[BaseModel, Text, dict]]): Expected output format. - + Deprecated Attributes: llm_id (Text): DEPRECATED. Use 'llm' parameter instead. Large language model ID. mentalist_llm (Optional[LLM]): DEPRECATED. LLM for planning. @@ -132,6 +132,32 @@ def __init__( expected_output: Optional[Union[BaseModel, Text, dict]] = None, **additional_info, ) -> None: + """Initialize a TeamAgent instance. + + Args: + id (Text): Unique identifier for the team agent. + name (Text): Name of the team agent. + agents (List[Agent], optional): List of agents in the team. Defaults to []. + description (Text, optional): Description of the team agent. Defaults to "". + llm (Optional[LLM], optional): LLM instance. Defaults to None. + supervisor_llm (Optional[LLM], optional): Supervisor LLM instance. Defaults to None. + api_key (Optional[Text], optional): API key. Defaults to config.TEAM_API_KEY. + supplier (Union[Dict, Text, Supplier, int], optional): Supplier. Defaults to "aiXplain". + version (Optional[Text], optional): Version. Defaults to None. + cost (Optional[Dict], optional): Cost information. Defaults to None. + inspectors (List[Inspector], optional): List of inspectors. Defaults to []. + inspector_targets (List[InspectorTarget], optional): Inspector targets. Defaults to [InspectorTarget.STEPS]. + status (AssetStatus, optional): Status of the team agent. Defaults to AssetStatus.DRAFT. + instructions (Optional[Text], optional): Instructions for the team agent. Defaults to None. + output_format (OutputFormat, optional): Output format. Defaults to OutputFormat.TEXT. + expected_output (Optional[Union[BaseModel, Text, dict]], optional): Expected output format. Defaults to None. + **additional_info: Additional keyword arguments. + + Deprecated Args: + llm_id (Text, optional): DEPRECATED. Use 'llm' parameter instead. ID of the language model. Defaults to "6646261c6eb563165658bbb1". + mentalist_llm (Optional[LLM], optional): DEPRECATED. Mentalist/Planner LLM instance. Defaults to None. + use_mentalist (bool, optional): DEPRECATED. Whether to use mentalist/planner. Defaults to True. + """ # Handle deprecated parameters from kwargs if "llm_id" in additional_info: llm_id = additional_info.pop("llm_id") @@ -143,7 +169,7 @@ def __init__( ) else: llm_id = "6646261c6eb563165658bbb1" - + if "mentalist_llm" in additional_info: mentalist_llm = additional_info.pop("mentalist_llm") warnings.warn( @@ -153,7 +179,7 @@ def __init__( ) else: mentalist_llm = None - + if "use_mentalist" in additional_info: use_mentalist = additional_info.pop("use_mentalist") warnings.warn( @@ -369,9 +395,6 @@ def _format_team_progress( # Full verbosity: detailed info msg = f"{emoji} {context} | {status_icon}" - if runtime is not None and runtime > 0 and success is not None: - msg += f" ({runtime:.1f} s)" - if current_step and total_steps: msg += f" | Step {current_step}/{total_steps}" @@ -576,6 +599,7 @@ def run( max_iterations (int, optional): maximum number of iterations between the agents. Defaults to 30. trace_request (bool, optional): return the request id for tracing the request. Defaults to False. progress_verbosity (Optional[str], optional): Progress display mode - "full" (detailed), "compact" (brief), or None (no progress). Defaults to "compact". + **kwargs: Additional deprecated keyword arguments (output_format, expected_output). Returns: AgentResponse: parsed output from model @@ -589,7 +613,7 @@ def run( DeprecationWarning, stacklevel=2, ) - + expected_output = kwargs.pop("expected_output", None) if expected_output is not None: warnings.warn( @@ -598,7 +622,7 @@ def run( DeprecationWarning, stacklevel=2, ) - + start = time.time() result_data = {} if session_id is not None and history is not None: diff --git a/aixplain/modules/team_agent/inspector.py b/aixplain/modules/team_agent/inspector.py index b518e76e..3c091a02 100644 --- a/aixplain/modules/team_agent/inspector.py +++ b/aixplain/modules/team_agent/inspector.py @@ -380,3 +380,64 @@ def model_validate(cls, data: Union[Dict, "Inspector"]) -> "Inspector": data.pop("policy_type", None) # Remove the type indicator return super().model_validate(data) + + +class VerificationInspector(Inspector): + """Pre-defined inspector that checks output against the plan. + + This inspector is designed to verify that the output aligns with the intended plan + and provides feedback when discrepancies are found. It uses a RERUN policy by default, + meaning it will request re-execution when issues are detected. + + Example usage: + from aixplain.modules.team_agent import VerificationInspector + + # Use with default model (GPT-4o or resolved_model_id) + inspector = VerificationInspector() + + # Or with custom model + inspector = VerificationInspector(model_id="your_model_id") + + team_agent = TeamAgent( + name="my_team", + agents=agents, + inspectors=[VerificationInspector()], + inspector_targets=[InspectorTarget.STEPS] + ) + """ + + def __init__(self, model_id: Optional[Text] = None, **kwargs): + """Initialize VerificationInspector with default configuration. + + Args: + model_id (Optional[Text]): Model ID to use. If not provided, uses auto configuration. + **kwargs: Additional arguments passed to Inspector parent class. + """ + from aixplain.modules.model.response import ModelResponse + + # Replicate resolved_model_id logic from old implementation + resolved_model_id = model_id + if not resolved_model_id: + resolved_model_id = "6646261c6eb563165658bbb1" # GPT_4o_ID + + def process_response(model_response: ModelResponse, input_content: str) -> InspectorOutput: + """Default policy that always requests rerun for verification.""" + critiques = model_response.data + action = InspectorAction.RERUN + return InspectorOutput(critiques=critiques, content_edited=input_content, action=action) + + # Exact same default inspector configuration as old implementation + # Note: When auto=InspectorAuto.ALIGNMENT is set, Inspector.__init__ will override + # model_id with AUTO_DEFAULT_MODEL_ID + defaults = { + "name": "VerificationInspector", + "model_id": resolved_model_id, + "model_params": {"prompt": "Check the output against the plan"}, + "policy": process_response, + "auto": InspectorAuto.ALIGNMENT + } + + # Override defaults with any provided kwargs + defaults.update(kwargs) + + super().__init__(**defaults) diff --git a/docs/api-reference/python/aixplain/decorators/api_key_checker.md b/docs/api-reference/python/aixplain/decorators/api_key_checker.md index 5c6e27c3..fa74b59f 100644 --- a/docs/api-reference/python/aixplain/decorators/api_key_checker.md +++ b/docs/api-reference/python/aixplain/decorators/api_key_checker.md @@ -3,18 +3,20 @@ sidebar_label: api_key_checker title: aixplain.decorators.api_key_checker --- +API key validation decorator for aiXplain SDK. + #### check\_api\_key ```python def check_api_key(method) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/decorators/api_key_checker.py#L4) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/decorators/api_key_checker.py#L6) Decorator to verify that an API key is set before executing the method. -This decorator checks if either TEAM_API_KEY or AIXPLAIN_API_KEY is set in the -configuration. If neither key is set, it raises an exception. +This decorator uses the centralized API key validation logic from config.py +to ensure consistent behavior across the entire SDK. **Arguments**: diff --git a/docs/api-reference/python/aixplain/exceptions/init.md b/docs/api-reference/python/aixplain/exceptions/init.md index 67f62e9d..faf1aa5a 100644 --- a/docs/api-reference/python/aixplain/exceptions/init.md +++ b/docs/api-reference/python/aixplain/exceptions/init.md @@ -16,14 +16,14 @@ def get_error_from_status_code(status_code: int, ) -> AixplainBaseException ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/__init__.py#L21) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/__init__.py#L35) Map HTTP status codes to appropriate exception types. **Arguments**: - `status_code` _int_ - The HTTP status code to map. -- `default_message` _str, optional_ - The default message to use if no specific message is available. +- `error_details` _str, optional_ - Additional error details to include in the message. **Returns**: diff --git a/docs/api-reference/python/aixplain/exceptions/types.md b/docs/api-reference/python/aixplain/exceptions/types.md index ee386c4e..6bd46a47 100644 --- a/docs/api-reference/python/aixplain/exceptions/types.md +++ b/docs/api-reference/python/aixplain/exceptions/types.md @@ -3,13 +3,15 @@ sidebar_label: types title: aixplain.exceptions.types --- +Exception types and error handling for the aiXplain SDK. + ### ErrorSeverity Objects ```python class ErrorSeverity(str, Enum) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L5) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L7) Enumeration of error severity levels in the aiXplain system. @@ -45,7 +47,7 @@ System stability might be compromised class ErrorCategory(Enum) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L24) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L26) Enumeration of error categories in the aiXplain system. @@ -111,7 +113,7 @@ Uncategorized errors class ErrorCode(str, Enum) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L55) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L57) Standard error codes for aiXplain exceptions. @@ -173,7 +175,7 @@ General internal error. Use for unexpected server-side errors that are not cover def __str__() -> str ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L88) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L90) Return the string representation of the error code. @@ -187,7 +189,7 @@ Return the string representation of the error code. class AixplainBaseException(Exception) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L97) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L99) Base exception class for all aiXplain exceptions. @@ -205,13 +207,39 @@ severity, and additional context. - `retry_recommended` _bool_ - Whether retrying the operation might succeed. - `error_code` _Optional[ErrorCode]_ - Standardized error code. +#### \_\_init\_\_ + +```python +def __init__(message: str, + category: ErrorCategory = ErrorCategory.UNKNOWN, + severity: ErrorSeverity = ErrorSeverity.ERROR, + status_code: Optional[int] = None, + details: Optional[Dict[str, Any]] = None, + retry_recommended: bool = False, + error_code: Optional[ErrorCode] = None) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L116) + +Initialize the base exception with structured error information. + +**Arguments**: + +- `message` - Error message describing the issue. +- `category` - Category of the error (default: UNKNOWN). +- `severity` - Severity level of the error (default: ERROR). +- `status_code` - HTTP status code if applicable. +- `details` - Additional error context and details. +- `retry_recommended` - Whether retrying the operation might succeed. +- `error_code` - Standardized error code for the exception. + #### \_\_str\_\_ ```python def __str__() -> str ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L133) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L146) Return a string representation of the exception. @@ -226,7 +254,7 @@ Return a string representation of the exception. def to_dict() -> Dict[str, Any] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L143) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L156) Convert the exception to a dictionary for serialization. @@ -242,77 +270,232 @@ Convert the exception to a dictionary for serialization. class AuthenticationError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L162) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L175) Raised when authentication fails. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L178) + +Initialize authentication error. + +**Arguments**: + +- `message` - Error message describing the authentication issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### ValidationError Objects ```python class ValidationError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L176) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L195) Raised when input validation fails. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L198) + +Initialize validation error. + +**Arguments**: + +- `message` - Error message describing the validation issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + +### AlreadyDeployedError Objects + +```python +class AlreadyDeployedError(AixplainBaseException) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L215) + +Raised when attempting to deploy an asset that is already deployed. + +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L218) + +Initialize already deployed error. + +**Arguments**: + +- `message` - Error message describing the deployment state conflict. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### ResourceError Objects ```python class ResourceError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L190) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L233) Raised when a resource is unavailable. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L236) + +Initialize resource error. + +**Arguments**: + +- `message` - Error message describing the resource issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### BillingError Objects ```python class BillingError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L204) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L253) Raised when there are billing issues. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L256) + +Initialize billing error. + +**Arguments**: + +- `message` - Error message describing the billing issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### SupplierError Objects ```python class SupplierError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L218) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L273) Raised when there are issues with external suppliers. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L276) + +Initialize supplier error. + +**Arguments**: + +- `message` - Error message describing the supplier issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### NetworkError Objects ```python class NetworkError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L232) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L293) Raised when there are network connectivity issues. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L296) + +Initialize network error. + +**Arguments**: + +- `message` - Error message describing the network issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### ServiceError Objects ```python class ServiceError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L246) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L313) Raised when a service is unavailable. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L316) + +Initialize service error. + +**Arguments**: + +- `message` - Error message describing the service issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + ### InternalError Objects ```python class InternalError(AixplainBaseException) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L260) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L333) Raised when there is an internal system error. +#### \_\_init\_\_ + +```python +def __init__(message: str, **kwargs) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L336) + +Initialize internal error. + +**Arguments**: + +- `message` - Error message describing the internal issue. +- `**kwargs` - Additional keyword arguments passed to parent class. + +### AlreadyDeployedError Objects + +```python +class AlreadyDeployedError(AixplainBaseException) +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/exceptions/types.py#L359) + +Raised when an asset is already deployed. + diff --git a/docs/api-reference/python/aixplain/factories/agent_factory/init.md b/docs/api-reference/python/aixplain/factories/agent_factory/init.md index 8eabbaa8..9219f4c3 100644 --- a/docs/api-reference/python/aixplain/factories/agent_factory/init.md +++ b/docs/api-reference/python/aixplain/factories/agent_factory/init.md @@ -30,7 +30,7 @@ Description: class AgentFactory() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L51) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L52) Factory class for creating and managing agents in the aiXplain system. @@ -48,18 +48,18 @@ def create( instructions: Optional[Text] = None, llm: Optional[Union[LLM, Text]] = None, llm_id: Optional[Text] = None, - tools: List[Union[Tool, Model]] = [], + tools: Optional[List[Union[Tool, Model]]] = None, api_key: Text = config.TEAM_API_KEY, supplier: Union[Dict, Text, Supplier, int] = "aiXplain", version: Optional[Text] = None, tasks: List[WorkflowTask] = None, - workflow_tasks: List[WorkflowTask] = [], + workflow_tasks: Optional[List[WorkflowTask]] = None, output_format: Optional[OutputFormat] = None, expected_output: Optional[Union[BaseModel, Text, dict]] = None) -> Agent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L59) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L60) Create a new agent in the platform. @@ -96,7 +96,7 @@ Create a new agent in the platform. def create_from_dict(cls, dict: Dict) -> Agent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L202) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L206) Create an agent instance from a dictionary representation. @@ -127,7 +127,7 @@ def create_model_tool(cls, name: Optional[Text] = None) -> ModelTool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L245) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L250) Create a new model tool for use with an agent. @@ -160,7 +160,7 @@ def create_pipeline_tool(cls, name: Optional[Text] = None) -> PipelineTool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L293) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L298) Create a new pipeline tool for use with an agent. @@ -182,7 +182,7 @@ Create a new pipeline tool for use with an agent. def create_python_interpreter_tool(cls) -> PythonInterpreterTool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L312) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L317) Create a new Python interpreter tool for use with an agent. @@ -203,7 +203,7 @@ def create_custom_python_code_tool( description: Text = "") -> CustomPythonCodeTool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L323) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L328) Create a new custom Python code tool for use with an agent. @@ -232,7 +232,7 @@ def create_sql_tool(cls, enable_commit: bool = False) -> SQLTool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L339) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L344) Create a new SQL tool @@ -276,7 +276,7 @@ Create a new SQL tool def list(cls) -> Dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L472) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L477) List all agents available in the platform. @@ -297,16 +297,20 @@ List all agents available in the platform. ```python @classmethod -def get(cls, agent_id: Text, api_key: Optional[Text] = None) -> Agent +def get(cls, + agent_id: Optional[Text] = None, + name: Optional[Text] = None, + api_key: Optional[Text] = None) -> Agent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L522) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/agent_factory/__init__.py#L531) -Retrieve an agent by its ID. +Retrieve an agent by its ID or name. **Arguments**: -- `agent_id` _Text_ - ID of the agent to retrieve. +- `agent_id` _Optional[Text], optional_ - ID of the agent to retrieve. +- `name` _Optional[Text], optional_ - Name of the agent to retrieve. - `api_key` _Optional[Text], optional_ - API key for authentication. Defaults to None, using the configured TEAM_API_KEY. @@ -319,4 +323,5 @@ Retrieve an agent by its ID. **Raises**: - `Exception` - If the agent cannot be retrieved or doesn't exist. +- `ValueError` - If neither agent_id nor name is provided, or if both are provided. diff --git a/docs/api-reference/python/aixplain/factories/team_agent_factory/init.md b/docs/api-reference/python/aixplain/factories/team_agent_factory/init.md index f8519895..c6ab0fe9 100644 --- a/docs/api-reference/python/aixplain/factories/team_agent_factory/init.md +++ b/docs/api-reference/python/aixplain/factories/team_agent_factory/init.md @@ -30,7 +30,7 @@ Description: class TeamAgentFactory() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L42) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L43) Factory class for creating and managing team agents. @@ -64,7 +64,7 @@ def create(cls, **kwargs) -> TeamAgent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L52) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L53) Create a new team agent in the platform. @@ -99,7 +99,7 @@ Create a new team agent in the platform. def create_from_dict(cls, dict: Dict) -> TeamAgent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L263) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L264) Create a team agent from a dictionary representation. @@ -133,7 +133,7 @@ the agent's configuration. def list(cls) -> Dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L290) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L291) List all team agents available in the platform. @@ -158,19 +158,23 @@ using the configured API key. ```python @classmethod -def get(cls, agent_id: Text, api_key: Optional[Text] = None) -> TeamAgent +def get(cls, + agent_id: Optional[Text] = None, + name: Optional[Text] = None, + api_key: Optional[Text] = None) -> TeamAgent ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L337) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/__init__.py#L343) -Retrieve a team agent by its ID. +Retrieve a team agent by its ID or name. This method fetches a specific team agent from the platform using its -unique identifier. +unique identifier or name. **Arguments**: -- `agent_id` _Text_ - Unique identifier of the team agent to retrieve. +- `agent_id` _Optional[Text], optional_ - Unique identifier of the team agent to retrieve. +- `name` _Optional[Text], optional_ - Name of the team agent to retrieve. - `api_key` _Optional[Text], optional_ - API key for authentication. Defaults to None, using the configured TEAM_API_KEY. @@ -183,8 +187,9 @@ unique identifier. **Raises**: - `Exception` - If: - - Team agent ID is invalid + - Team agent ID/name is invalid - Authentication fails - Service is unavailable - Other API errors occur +- `ValueError` - If neither agent_id nor name is provided, or if both are provided. diff --git a/docs/api-reference/python/aixplain/factories/team_agent_factory/utils.md b/docs/api-reference/python/aixplain/factories/team_agent_factory/utils.md index 1696b4ee..5ca990c9 100644 --- a/docs/api-reference/python/aixplain/factories/team_agent_factory/utils.md +++ b/docs/api-reference/python/aixplain/factories/team_agent_factory/utils.md @@ -58,7 +58,7 @@ handling the setup of agents, LLMs, inspectors, and task dependencies. def is_yaml_formatted(text) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/utils.py#L212) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/factories/team_agent_factory/utils.py#L231) Check if a string is valid YAML format with additional validation. diff --git a/docs/api-reference/python/aixplain/modules/agent/agent_task.md b/docs/api-reference/python/aixplain/modules/agent/agent_task.md index f5de2bfd..911f3a71 100644 --- a/docs/api-reference/python/aixplain/modules/agent/agent_task.md +++ b/docs/api-reference/python/aixplain/modules/agent/agent_task.md @@ -9,7 +9,7 @@ title: aixplain.modules.agent.agent_task class WorkflowTask() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L4) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L5) A task definition for an AI agent to execute. @@ -33,7 +33,7 @@ def __init__(name: Text, dependencies: Optional[List[Union[Text, "WorkflowTask"]]] = []) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L18) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L19) Initialize a new WorkflowTask instance. @@ -52,7 +52,7 @@ Initialize a new WorkflowTask instance. def to_dict() -> dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L40) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L41) Convert the task to a dictionary representation. @@ -74,7 +74,7 @@ to their name strings. def from_dict(cls, data: dict) -> "WorkflowTask" ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L67) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/agent_task.py#L68) Create an WorkflowTask instance from a dictionary representation. diff --git a/docs/api-reference/python/aixplain/modules/agent/init.md b/docs/api-reference/python/aixplain/modules/agent/init.md index ff43c8fa..cbf2cae9 100644 --- a/docs/api-reference/python/aixplain/modules/agent/init.md +++ b/docs/api-reference/python/aixplain/modules/agent/init.md @@ -3,7 +3,10 @@ sidebar_label: agent title: aixplain.modules.agent --- -#### \_\_author\_\_ +Agent module for aiXplain SDK. + +This module provides the Agent class and related functionality for creating and managing +AI agents that can execute tasks using various tools and models. Copyright 2024 The aiXplain SDK authors @@ -27,10 +30,10 @@ Description: ### Agent Objects ```python -class Agent(Model, DeployableMixin[Tool]) +class Agent(Model, DeployableMixin[Union[Tool, DeployableTool]]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L51) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L56) An advanced AI system that performs tasks using specialized tools from the aiXplain marketplace. @@ -83,7 +86,7 @@ def __init__(id: Text, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L83) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L88) Initialize a new Agent instance. @@ -110,9 +113,11 @@ Initialize a new Agent instance. Defaults to AssetStatus.DRAFT. - `name`2 _List[AgentTask], optional_ - List of tasks the Agent can perform. Defaults to empty list. -- `name`3 _OutputFormat, optional_ - default output format for agent responses. Defaults to OutputFormat.TEXT. -- `name`4 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. -- `name`5 - Additional configuration parameters. +- `name`3 _List[WorkflowTask], optional_ - List of workflow tasks + the Agent can execute. Defaults to empty list. +- `name`4 _OutputFormat, optional_ - default output format for agent responses. Defaults to OutputFormat.TEXT. +- `name`5 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. +- `name`6 - Additional configuration parameters. #### validate @@ -120,7 +125,7 @@ Initialize a new Agent instance. def validate(raise_exception: bool = False) -> bool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L207) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L215) Validate the Agent's configuration and mark its validity status. @@ -142,27 +147,45 @@ If validation fails, it can either raise an exception or log warnings. - `Exception` - If validation fails and raise_exception is True. +#### generate\_session\_id + +```python +def generate_session_id(history: list = None) -> str +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L243) + +Generate a unique session ID for agent conversations. + +**Arguments**: + +- `history` _list, optional_ - Previous conversation history. Defaults to None. + + +**Returns**: + +- `str` - A unique session identifier based on timestamp and random components. + #### run ```python -def run( - data: Optional[Union[Dict, Text]] = None, - query: Optional[Text] = None, - session_id: Optional[Text] = None, - history: Optional[List[Dict]] = None, - name: Text = "model_process", - timeout: float = 300, - parameters: Dict = {}, - wait_time: float = 0.5, - content: Optional[Union[Dict[Text, Text], List[Text]]] = None, - max_tokens: int = 4096, - max_iterations: int = 5, - output_format: Optional[OutputFormat] = None, - expected_output: Optional[Union[BaseModel, Text, dict]] = None -) -> AgentResponse +def run(data: Optional[Union[Dict, Text]] = None, + query: Optional[Text] = None, + session_id: Optional[Text] = None, + history: Optional[List[Dict]] = None, + name: Text = "model_process", + timeout: float = 300, + parameters: Dict = {}, + wait_time: float = 0.5, + content: Optional[Union[Dict[Text, Text], List[Text]]] = None, + max_tokens: int = 4096, + max_iterations: int = 5, + output_format: Optional[OutputFormat] = None, + expected_output: Optional[Union[BaseModel, Text, dict]] = None, + trace_request: bool = False) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L278) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L294) Runs an agent call. @@ -181,31 +204,31 @@ Runs an agent call. - `query`0 _int, optional_ - maximum number of iterations between the agent and the tools. Defaults to 10. - `query`1 _OutputFormat, optional_ - response format. If not provided, uses the format set during initialization. - `query`2 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. +- `query`3 _bool, optional_ - return the request id for tracing the request. Defaults to False. **Returns**: -- `query`3 - parsed output from model +- `query`4 - parsed output from model #### run\_async ```python -def run_async( - data: Optional[Union[Dict, Text]] = None, - query: Optional[Text] = None, - session_id: Optional[Text] = None, - history: Optional[List[Dict]] = None, - name: Text = "model_process", - parameters: Dict = {}, - content: Optional[Union[Dict[Text, Text], List[Text]]] = None, - max_tokens: int = 2048, - max_iterations: int = 5, - output_format: Optional[OutputFormat] = None, - expected_output: Optional[Union[BaseModel, Text, dict]] = None, - evolve: Union[Dict[str, Any], EvolveParam, - None] = None) -> AgentResponse +def run_async(data: Optional[Union[Dict, Text]] = None, + query: Optional[Text] = None, + session_id: Optional[Text] = None, + history: Optional[List[Dict]] = None, + name: Text = "model_process", + parameters: Dict = {}, + content: Optional[Union[Dict[Text, Text], List[Text]]] = None, + max_tokens: int = 2048, + max_iterations: int = 5, + output_format: Optional[OutputFormat] = None, + expected_output: Optional[Union[BaseModel, Text, dict]] = None, + evolve: Union[Dict[str, Any], EvolveParam, None] = None, + trace_request: bool = False) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L378) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L397) Runs asynchronously an agent call. @@ -224,10 +247,25 @@ Runs asynchronously an agent call. - `query`0 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. - `output_format` _ResponseFormat, optional_ - response format. Defaults to TEXT. - `query`2 _Union[Dict[str, Any], EvolveParam, None], optional_ - evolve the agent configuration. Can be a dictionary, EvolveParam instance, or None. +- `query`3 _bool, optional_ - return the request id for tracing the request. Defaults to False. + +**Returns**: + +- `query`4 - polling URL in response + +#### to\_dict + +```python +def to_dict() -> Dict +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L540) + +Convert the Agent instance to a dictionary representation. **Returns**: -- `query`3 - polling URL in response +- `Dict` - Dictionary containing the agent's configuration and metadata. #### from\_dict @@ -236,7 +274,7 @@ Runs asynchronously an agent call. def from_dict(cls, data: Dict) -> "Agent" ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L545) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L577) Create an Agent instance from a dictionary representation. @@ -255,7 +293,7 @@ Create an Agent instance from a dictionary representation. def delete() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L620) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L652) Delete this Agent from the aiXplain platform. @@ -276,7 +314,7 @@ Agent is being used by any team agents. def update() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L683) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L715) Update the Agent's configuration on the aiXplain platform. @@ -300,7 +338,7 @@ in favor of the save() method. def save() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L730) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L762) Save the Agent's current configuration to the aiXplain platform. @@ -317,7 +355,7 @@ It is the preferred method for updating an Agent's settings. def __repr__() -> str ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L741) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L773) Return a string representation of the Agent. @@ -336,7 +374,7 @@ def evolve_async(evolve_type: Union[EvolveType, str] = EvolveType.TEAM_TUNING, llm: Optional[Union[Text, LLM]] = None) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L749) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L781) Asynchronously evolve the Agent and return a polling URL in the AgentResponse. @@ -365,7 +403,7 @@ def evolve(evolve_type: Union[EvolveType, str] = EvolveType.TEAM_TUNING, llm: Optional[Union[Text, LLM]] = None) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L788) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/__init__.py#L820) Synchronously evolve the Agent and poll for the result. diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/custom_python_code_tool.md b/docs/api-reference/python/aixplain/modules/agent/tool/custom_python_code_tool.md index 53070926..c9d91712 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/custom_python_code_tool.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/custom_python_code_tool.md @@ -3,7 +3,10 @@ sidebar_label: custom_python_code_tool title: aixplain.modules.agent.tool.custom_python_code_tool --- -#### \_\_author\_\_ +Custom Python code tool for aiXplain SDK agents. + +This module provides a tool that allows agents to execute custom Python code +in a controlled environment. Copyright 2024 The aiXplain SDK authors @@ -30,7 +33,7 @@ Description: class CustomPythonCodeTool(Tool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L31) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L35) A tool for executing custom Python code in the aiXplain platform. @@ -52,7 +55,7 @@ def __init__(code: Union[Text, Callable], **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L43) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L47) Initialize a new CustomPythonCodeTool instance. @@ -75,7 +78,7 @@ Initialize a new CustomPythonCodeTool instance. def to_dict() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L65) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L69) Convert the tool instance to a dictionary representation. @@ -95,7 +98,7 @@ Convert the tool instance to a dictionary representation. def validate() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L86) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L90) Validate the tool's configuration and code. @@ -115,7 +118,7 @@ This method performs several checks: def __repr__() -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L123) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L127) Return a string representation of the tool. @@ -123,16 +126,3 @@ Return a string representation of the tool. - `Text` - A string in the format "CustomPythonCodeTool(name=<tool_name>)". -#### deploy - -```python -def deploy() -``` - -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/custom_python_code_tool.py#L131) - -Deploy the custom Python code tool. - -This is a placeholder method as custom Python code tools are automatically -deployed when created. - diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/init.md b/docs/api-reference/python/aixplain/modules/agent/tool/init.md index 07adbd16..8071b496 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/init.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/init.md @@ -3,7 +3,10 @@ sidebar_label: tool title: aixplain.modules.agent.tool --- -#### \_\_author\_\_ +Agent tool module for aiXplain SDK. + +This module provides tool classes and functionality for agents to interact with +various services, models, and data sources. Copyright 2024 The aiXplain SDK authors @@ -30,7 +33,7 @@ Description: class Tool(ABC) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L29) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L33) Specialized software or resource designed to assist the AI in executing specific tasks or functions based on user commands. @@ -51,7 +54,7 @@ def __init__(name: Text, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L38) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L42) Initialize a new Tool instance. @@ -70,7 +73,7 @@ Initialize a new Tool instance. def to_dict() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L64) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L68) Converts the tool instance to a dictionary representation. @@ -89,7 +92,7 @@ Converts the tool instance to a dictionary representation. def validate() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L75) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L79) Validates the tool's configuration and settings. @@ -100,20 +103,23 @@ if the tool's configuration is valid. - `NotImplementedError` - This is an abstract method that must be implemented by subclasses. -#### deploy +### DeployableTool Objects ```python -def deploy() -> None +class DeployableTool(Tool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L86) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L91) -Deploys the tool to make it available for use. +Tool that can be deployed. -This method should handle any necessary setup or deployment steps -required to make the tool operational. +#### deploy -**Raises**: +```python +def deploy() -> None +``` -- `NotImplementedError` - This is an abstract method that must be implemented by subclasses. +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/__init__.py#L94) + +Deploy the tool. diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/model_tool.md b/docs/api-reference/python/aixplain/modules/agent/tool/model_tool.md index 771b9f87..e678d93d 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/model_tool.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/model_tool.md @@ -3,7 +3,10 @@ sidebar_label: model_tool title: aixplain.modules.agent.tool.model_tool --- -#### \_\_author\_\_ +Model tool for aiXplain SDK agents. + +This module provides a tool that allows agents to interact with AI models +and execute model-based tasks. Copyright 2024 The aiXplain SDK authors @@ -32,7 +35,7 @@ def set_tool_name(function: Function, model: Model = None) -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L30) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L35) Sets the name of the tool based on the function, supplier, and model. @@ -53,7 +56,7 @@ Sets the name of the tool based on the function, supplier, and model. class ModelTool(Tool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L54) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L59) A tool that wraps AI models to execute specific tasks or functions based on user commands. @@ -82,7 +85,7 @@ def __init__(function: Optional[Union[Function, Text]] = None, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L70) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L75) Initialize a new ModelTool instance. @@ -112,7 +115,7 @@ Initialize a new ModelTool instance. def to_dict() -> Dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L125) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L130) Convert the tool instance to a dictionary representation. @@ -138,7 +141,7 @@ into their serializable forms. def validate() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L164) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L169) Validates the tool. @@ -157,7 +160,7 @@ Validates the tool. def get_parameters() -> Dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L217) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L223) Get the tool's parameters, either from explicit settings or the model object. @@ -174,7 +177,7 @@ def validate_parameters( ) -> Optional[List[Dict]] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L252) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L258) Validates and formats the parameters for the tool. @@ -198,7 +201,7 @@ Validates and formats the parameters for the tool. def __repr__() -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L307) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L315) Return a string representation of the tool. @@ -207,16 +210,3 @@ Return a string representation of the tool. - `Text` - A string in the format "ModelTool(name=<name>, function=<function>, supplier=<supplier>, model=<model>)". -#### deploy - -```python -def deploy() -``` - -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/model_tool.py#L318) - -Deploy the model tool. - -This is a placeholder method as model tools are managed through the aiXplain platform -and don't require explicit deployment. - diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/pipeline_tool.md b/docs/api-reference/python/aixplain/modules/agent/tool/pipeline_tool.md index 698a9137..af608c66 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/pipeline_tool.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/pipeline_tool.md @@ -3,7 +3,10 @@ sidebar_label: pipeline_tool title: aixplain.modules.agent.tool.pipeline_tool --- -#### \_\_author\_\_ +Pipeline tool for aiXplain SDK agents. + +This module provides a tool that allows agents to execute AI pipelines +and chain multiple AI operations together. Copyright 2024 The aiXplain SDK authors @@ -30,7 +33,7 @@ Description: class PipelineTool(Tool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L30) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L35) A tool that wraps aiXplain pipelines to execute complex workflows based on user commands. @@ -55,7 +58,7 @@ def __init__(description: Text, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L45) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L50) Initialize a new PipelineTool instance. @@ -79,7 +82,7 @@ Initialize a new PipelineTool instance. def to_dict() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L73) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L78) Convert the tool instance to a dictionary representation. @@ -98,7 +101,7 @@ Convert the tool instance to a dictionary representation. def __repr__() -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L92) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L97) Return a string representation of the tool. @@ -112,7 +115,7 @@ Return a string representation of the tool. def validate() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L100) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L105) Validate the pipeline tool's configuration. @@ -125,16 +128,3 @@ This method performs several checks: - `Exception` - If the pipeline doesn't exist or is inaccessible. -#### deploy - -```python -def deploy() -``` - -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/pipeline_tool.py#L127) - -Deploy the pipeline tool. - -This is a placeholder method as pipeline tools are managed through the aiXplain platform -and don't require explicit deployment. - diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/python_interpreter_tool.md b/docs/api-reference/python/aixplain/modules/agent/tool/python_interpreter_tool.md index 83ad430d..b755c6f0 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/python_interpreter_tool.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/python_interpreter_tool.md @@ -3,7 +3,10 @@ sidebar_label: python_interpreter_tool title: aixplain.modules.agent.tool.python_interpreter_tool --- -#### \_\_author\_\_ +Python interpreter tool for aiXplain SDK agents. + +This module provides a tool that allows agents to execute Python code +using an interpreter in a controlled environment. Copyright 2024 The aiXplain SDK authors @@ -30,7 +33,7 @@ Description: class PythonInterpreterTool(Tool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L30) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L34) A tool that provides a Python shell for executing Python commands. @@ -50,7 +53,7 @@ and computation. def __init__(**additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L43) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L47) Initialize a new PythonInterpreterTool instance. @@ -67,7 +70,7 @@ The tool is set to ONBOARDED status by default. def to_dict() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L56) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L60) Convert the tool instance to a dictionary representation. @@ -84,7 +87,7 @@ Convert the tool instance to a dictionary representation. def validate() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L71) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L75) Validate the tool's configuration. @@ -97,7 +100,7 @@ configuration that doesn't require validation. def __repr__() -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L79) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L83) Return a string representation of the tool. @@ -105,16 +108,3 @@ Return a string representation of the tool. - `Text` - A string in the format "PythonInterpreterTool()". -#### deploy - -```python -def deploy() -``` - -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/python_interpreter_tool.py#L87) - -Deploy the Python interpreter tool. - -This is a placeholder method as the Python interpreter tool is automatically -available and doesn't require explicit deployment. - diff --git a/docs/api-reference/python/aixplain/modules/agent/tool/sql_tool.md b/docs/api-reference/python/aixplain/modules/agent/tool/sql_tool.md index 200a0e6a..99691dff 100644 --- a/docs/api-reference/python/aixplain/modules/agent/tool/sql_tool.md +++ b/docs/api-reference/python/aixplain/modules/agent/tool/sql_tool.md @@ -3,7 +3,10 @@ sidebar_label: sql_tool title: aixplain.modules.agent.tool.sql_tool --- -#### \_\_author\_\_ +SQL tool for aiXplain SDK agents. + +This module provides a tool that allows agents to execute SQL queries +against databases and CSV files. Copyright 2024 The aiXplain SDK authors @@ -30,9 +33,9 @@ Description: class SQLToolError(Exception) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L34) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L39) -Base exception for SQL Tool errors +Base exception for SQL Tool errors. ### CSVError Objects @@ -40,9 +43,9 @@ Base exception for SQL Tool errors class CSVError(SQLToolError) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L40) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L45) -Exception for CSV-related errors +Exception for CSV-related errors. ### DatabaseError Objects @@ -50,9 +53,9 @@ Exception for CSV-related errors class DatabaseError(SQLToolError) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L46) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L51) -Exception for database-related errors +Exception for database-related errors. #### clean\_column\_name @@ -60,7 +63,7 @@ Exception for database-related errors def clean_column_name(col: Text) -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L52) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L57) Clean column names by replacing spaces and special characters with underscores. @@ -85,7 +88,7 @@ This function makes column names SQLite-compatible by: def check_duplicate_columns(df: pd.DataFrame) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L83) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L88) Check for duplicate column names in DataFrame after cleaning. @@ -107,7 +110,7 @@ cleaned for SQLite compatibility. def infer_sqlite_type(dtype) -> Text ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L113) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L118) Infer SQLite type from pandas dtype. @@ -138,7 +141,7 @@ This function maps pandas data types to appropriate SQLite types: def get_table_schema(database_path: str) -> str ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L145) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L150) Get the schema of all tables in the SQLite database. @@ -171,7 +174,7 @@ def create_database_from_csv(csv_path: str, table_name: str = None) -> str ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L185) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L190) Create SQLite database from CSV file and return the schema. @@ -209,7 +212,7 @@ It handles column name cleaning, data type inference, and data conversion. def get_table_names_from_schema(schema: str) -> List[str] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L311) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L318) Extract table names from a database schema string. @@ -228,10 +231,10 @@ This function parses CREATE TABLE statements to extract table names. ### SQLTool Objects ```python -class SQLTool(Tool) +class SQLTool(DeployableTool) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L336) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L343) A tool for executing SQL commands in an SQLite database. @@ -262,7 +265,7 @@ def __init__(name: Text, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L354) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L361) Initialize a new SQLTool instance. @@ -293,7 +296,7 @@ Initialize a new SQLTool instance. def to_dict() -> Dict[str, Text] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L394) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L400) Convert the tool instance to a dictionary representation. @@ -315,7 +318,7 @@ Convert the tool instance to a dictionary representation. def validate() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L420) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L426) Validate the SQL tool's configuration. @@ -337,7 +340,7 @@ This method performs several checks: def deploy() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L472) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/agent/tool/sql_tool.py#L478) Deploy the SQL tool by downloading and preparing the database. diff --git a/docs/api-reference/python/aixplain/modules/mixins.md b/docs/api-reference/python/aixplain/modules/mixins.md index 5ac4e4bf..27903cc4 100644 --- a/docs/api-reference/python/aixplain/modules/mixins.md +++ b/docs/api-reference/python/aixplain/modules/mixins.md @@ -3,6 +3,8 @@ sidebar_label: mixins title: aixplain.modules.mixins --- +Mixins for common functionality across different asset types. + Copyright 2024 The aiXplain SDK authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +30,7 @@ Description: class DeployableMixin(ABC, Generic[T]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/mixins.py#L28) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/mixins.py#L31) A mixin that provides common deployment-related functionality for assets. @@ -47,7 +49,7 @@ Classes that inherit from this mixin should: def deploy() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/mixins.py#L58) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/mixins.py#L62) Deploy the asset. @@ -56,5 +58,6 @@ Classes that need special deployment handling should override this method. **Raises**: +- `AlreadyDeployedError` - If the asset is already deployed - `ValueError` - If the asset is not ready to be deployed diff --git a/docs/api-reference/python/aixplain/modules/model/connection.md b/docs/api-reference/python/aixplain/modules/model/connection.md index 68f7de4b..39244039 100644 --- a/docs/api-reference/python/aixplain/modules/model/connection.md +++ b/docs/api-reference/python/aixplain/modules/model/connection.md @@ -3,13 +3,32 @@ sidebar_label: connection title: aixplain.modules.model.connection --- +Copyright 2025 The aiXplain SDK authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Author: Ahmet Gündüz +Date: September 10th 2025 +Description: + Connection Tool Class. + ### ConnectAction Objects ```python class ConnectAction() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L7) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L27) A class representing an action that can be performed by a connection. @@ -32,7 +51,7 @@ def __init__(name: Text, inputs: Optional[Dict] = None) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L25) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L45) Initialize a new ConnectAction instance. @@ -49,7 +68,7 @@ Initialize a new ConnectAction instance. def __repr__() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L45) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L65) Return a string representation of the ConnectAction instance. @@ -63,7 +82,16 @@ Return a string representation of the ConnectAction instance. class ConnectionTool(Model) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L54) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L74) + +A class representing a connection tool. + +This class defines the structure of a connection tool with its actions and action scope. + +**Attributes**: + +- `actions` _List[ConnectAction]_ - A list of available actions for this connection. +- `action_scope` _Optional[List[ConnectAction]]_ - The scope of actions for this connection. #### \_\_init\_\_ @@ -81,7 +109,7 @@ def __init__(id: Text, **additional_info) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L58) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L87) Initialize a new ConnectionTool instance. @@ -105,7 +133,7 @@ Initialize a new ConnectionTool instance. def get_action_inputs(action: Union[ConnectAction, Text]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L131) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L160) Retrieve the input parameters required for a specific action. @@ -130,7 +158,7 @@ Retrieve the input parameters required for a specific action. def run(action: Union[ConnectAction, Text], inputs: Dict) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L165) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L194) Execute a specific action with the provided inputs. @@ -151,7 +179,7 @@ Execute a specific action with the provided inputs. def get_parameters() -> List[Dict] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L180) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L209) Get the parameters for all actions in the current action scope. @@ -172,7 +200,7 @@ Get the parameters for all actions in the current action scope. def __repr__() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L205) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/model/connection.py#L234) Return a string representation of the ConnectionTool instance. diff --git a/docs/api-reference/python/aixplain/modules/team_agent/init.md b/docs/api-reference/python/aixplain/modules/team_agent/init.md index 2a3ba120..a46472d4 100644 --- a/docs/api-reference/python/aixplain/modules/team_agent/init.md +++ b/docs/api-reference/python/aixplain/modules/team_agent/init.md @@ -30,7 +30,7 @@ Description: class InspectorTarget(str, Enum) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L55) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L56) Target stages for inspector validation in the team agent pipeline. @@ -49,7 +49,7 @@ validate and ensure quality of the team agent's operation. def __str__() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L71) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L72) Return the string value of the enum member. @@ -63,7 +63,7 @@ Return the string value of the enum member. class TeamAgent(Model, DeployableMixin[Agent]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L80) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L81) Advanced AI system capable of using multiple agents to perform a variety of tasks. @@ -85,24 +85,23 @@ Advanced AI system capable of using multiple agents to perform a variety of task #### run ```python -def run( - data: Optional[Union[Dict, Text]] = None, - query: Optional[Text] = None, - session_id: Optional[Text] = None, - history: Optional[List[Dict]] = None, - name: Text = "model_process", - timeout: float = 300, - parameters: Dict = {}, - wait_time: float = 0.5, - content: Optional[Union[Dict[Text, Text], List[Text]]] = None, - max_tokens: int = 2048, - max_iterations: int = 30, - output_format: Optional[OutputFormat] = None, - expected_output: Optional[Union[BaseModel, Text, dict]] = None -) -> AgentResponse +def run(data: Optional[Union[Dict, Text]] = None, + query: Optional[Text] = None, + session_id: Optional[Text] = None, + history: Optional[List[Dict]] = None, + name: Text = "model_process", + timeout: float = 300, + parameters: Dict = {}, + wait_time: float = 0.5, + content: Optional[Union[Dict[Text, Text], List[Text]]] = None, + max_tokens: int = 2048, + max_iterations: int = 30, + output_format: Optional[OutputFormat] = None, + expected_output: Optional[Union[BaseModel, Text, dict]] = None, + trace_request: bool = False) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L187) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L188) Runs a team agent call. @@ -121,31 +120,31 @@ Runs a team agent call. - `query`0 _int, optional_ - maximum number of iterations between the agents. Defaults to 30. - `query`1 _OutputFormat, optional_ - response format. If not provided, uses the format set during initialization. - `query`2 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. +- `query`3 _bool, optional_ - return the request id for tracing the request. Defaults to False. **Returns**: -- `query`3 - parsed output from model +- `query`4 - parsed output from model #### run\_async ```python -def run_async( - data: Optional[Union[Dict, Text]] = None, - query: Optional[Text] = None, - session_id: Optional[Text] = None, - history: Optional[List[Dict]] = None, - name: Text = "model_process", - parameters: Dict = {}, - content: Optional[Union[Dict[Text, Text], List[Text]]] = None, - max_tokens: int = 2048, - max_iterations: int = 30, - output_format: Optional[OutputFormat] = None, - expected_output: Optional[Union[BaseModel, Text, dict]] = None, - evolve: Union[Dict[str, Any], EvolveParam, - None] = None) -> AgentResponse +def run_async(data: Optional[Union[Dict, Text]] = None, + query: Optional[Text] = None, + session_id: Optional[Text] = None, + history: Optional[List[Dict]] = None, + name: Text = "model_process", + parameters: Dict = {}, + content: Optional[Union[Dict[Text, Text], List[Text]]] = None, + max_tokens: int = 2048, + max_iterations: int = 30, + output_format: Optional[OutputFormat] = None, + expected_output: Optional[Union[BaseModel, Text, dict]] = None, + evolve: Union[Dict[str, Any], EvolveParam, None] = None, + trace_request: bool = False) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L277) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L281) Runs asynchronously a Team Agent call. @@ -163,10 +162,11 @@ Runs asynchronously a Team Agent call. - `output_format` _OutputFormat, optional_ - response format. If not provided, uses the format set during initialization. - `query`0 _Union[BaseModel, Text, dict], optional_ - expected output. Defaults to None. - `query`1 _Union[Dict[str, Any], EvolveParam, None], optional_ - evolve the team agent configuration. Can be a dictionary, EvolveParam instance, or None. +- `query`2 _bool, optional_ - return the request id for tracing the request. Defaults to False. **Returns**: -- `query`2 - polling URL in response +- `query`3 - polling URL in response #### delete @@ -174,7 +174,7 @@ Runs asynchronously a Team Agent call. def delete() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L472) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L478) Delete Corpus service @@ -184,7 +184,7 @@ Delete Corpus service def to_dict() -> Dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L531) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L537) Convert the TeamAgent instance to a dictionary representation. @@ -217,7 +217,7 @@ or transmission. def from_dict(cls, data: Dict) -> "TeamAgent" ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L579) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L585) Create a TeamAgent instance from a dictionary representation. @@ -236,7 +236,7 @@ Create a TeamAgent instance from a dictionary representation. def validate(raise_exception: bool = False) -> bool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L704) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L710) Validate the TeamAgent configuration. @@ -273,7 +273,7 @@ including name format, LLM compatibility, and agent validity. def update() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L740) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L746) Update the TeamAgent in the backend. @@ -302,7 +302,7 @@ backend system. It is deprecated in favor of the save() method. def save() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L792) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L798) Save the Agent. @@ -312,7 +312,7 @@ Save the Agent. def __repr__() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L796) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L802) Return a string representation of the TeamAgent. @@ -331,7 +331,7 @@ def evolve_async(evolve_type: Union[EvolveType, str] = EvolveType.TEAM_TUNING, llm: Optional[Union[Text, LLM]] = None) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L804) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L810) Asynchronously evolve the Team Agent and return a polling URL in the AgentResponse. @@ -360,7 +360,7 @@ def evolve(evolve_type: Union[EvolveType, str] = EvolveType.TEAM_TUNING, llm: Optional[Union[Text, LLM]] = None) -> AgentResponse ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L844) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/modules/team_agent/__init__.py#L850) Synchronously evolve the Team Agent and poll for the result. diff --git a/docs/api-reference/python/aixplain/utils/asset_cache.md b/docs/api-reference/python/aixplain/utils/asset_cache.md index ea25d996..058b2e03 100644 --- a/docs/api-reference/python/aixplain/utils/asset_cache.md +++ b/docs/api-reference/python/aixplain/utils/asset_cache.md @@ -10,7 +10,7 @@ title: aixplain.utils.asset_cache class Store(Generic[T]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L24) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L25) A generic data store for cached assets with expiration time. @@ -28,7 +28,7 @@ It is used internally by AssetCache to store the cached assets. class AssetCache(Generic[T]) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L38) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L40) A modular caching system for aiXplain assets with file-based persistence. @@ -59,7 +59,7 @@ expiration time. def __init__(cls: Type[T], cache_filename: Optional[str] = None) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L60) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L62) Initialize a new AssetCache instance. @@ -76,7 +76,7 @@ Initialize a new AssetCache instance. def compute_expiry() -> int ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L86) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L92) Calculate the expiration timestamp for cached data. @@ -100,7 +100,7 @@ plus the duration. def invalidate() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L113) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L116) Clear the cache and remove cache files. @@ -115,7 +115,7 @@ This method: def load() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L128) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L134) Load cached data from the cache file. @@ -138,7 +138,7 @@ the in-memory store. It performs the following: def save() -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L174) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L182) Save the current cache state to the cache file. @@ -161,7 +161,7 @@ to the cache file. It performs the following: def get(asset_id: str) -> Optional[T] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L207) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L231) Retrieve a cached asset by its ID. @@ -180,7 +180,7 @@ Retrieve a cached asset by its ID. def add(asset: T) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L218) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L247) Add a single asset to the cache. @@ -201,7 +201,7 @@ Add a single asset to the cache. def add_list(assets: List[T]) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L232) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L262) Add multiple assets to the cache at once. @@ -224,7 +224,7 @@ This method replaces all existing cached assets with the new list. def get_all() -> List[T] ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L248) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L279) Retrieve all cached assets. @@ -239,7 +239,7 @@ Retrieve all cached assets. def has_valid_cache() -> bool ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L257) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L288) Check if the cache is valid and not expired. @@ -254,7 +254,7 @@ Check if the cache is valid and not expired. def serialize(obj: Any) -> Any ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L266) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/asset_cache.py#L302) Convert a Python object into a JSON-serializable format. diff --git a/docs/api-reference/python/aixplain/utils/cache_utils.md b/docs/api-reference/python/aixplain/utils/cache_utils.md index f2c0e276..fb5089b5 100644 --- a/docs/api-reference/python/aixplain/utils/cache_utils.md +++ b/docs/api-reference/python/aixplain/utils/cache_utils.md @@ -9,7 +9,7 @@ title: aixplain.utils.cache_utils def get_cache_expiry() -> int ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L13) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L17) Get the cache expiration duration in seconds. @@ -26,7 +26,7 @@ environment variable. If not set, falls back to the default CACHE_DURATION. def save_to_cache(cache_file: str, data: dict, lock_file: str) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L25) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L29) Save data to a cache file with thread-safe file locking. @@ -52,7 +52,7 @@ timestamp. It uses file locking to ensure thread safety during writing. def load_from_cache(cache_file: str, lock_file: str) -> dict ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L50) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/cache_utils.py#L59) Load data from a cache file with expiration checking. diff --git a/docs/api-reference/python/aixplain/utils/config.md b/docs/api-reference/python/aixplain/utils/config.md index 25dc82ae..a8eb4d65 100644 --- a/docs/api-reference/python/aixplain/utils/config.md +++ b/docs/api-reference/python/aixplain/utils/config.md @@ -3,7 +3,7 @@ sidebar_label: config title: aixplain.utils.config --- -Copyright 2022 The aiXplain SDK authors +Copyright 2022 The aiXplain SDK authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,3 +17,39 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +#### validate\_api\_keys + +```python +def validate_api_keys() +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/config.py#L31) + +Centralized API key validation function - single source of truth. + +This function handles all API key validation logic: +1. Ensures at least one API key is provided +2. Prevents conflicting API keys +3. Auto-normalizes AIXPLAIN_API_KEY to TEAM_API_KEY if needed + +**Raises**: + +- `Exception` - If no API keys are provided or if conflicting keys are detected + +#### check\_api\_keys\_available + +```python +def check_api_keys_available() +``` + +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/config.py#L58) + +Runtime check to ensure API keys are available. + +This is used by decorators and other runtime validation. +Uses the same validation logic as the module-level check. + +**Raises**: + +- `Exception` - If no valid API keys are available + diff --git a/docs/api-reference/python/aixplain/utils/convert_datatype_utils.md b/docs/api-reference/python/aixplain/utils/convert_datatype_utils.md index db57c54d..834bd527 100644 --- a/docs/api-reference/python/aixplain/utils/convert_datatype_utils.md +++ b/docs/api-reference/python/aixplain/utils/convert_datatype_utils.md @@ -23,7 +23,7 @@ limitations under the License. def dict_to_metadata(metadatas: List[Union[Dict, MetaData]]) -> None ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/convert_datatype_utils.py#L21) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/convert_datatype_utils.py#L22) Convert all the Dicts to MetaData diff --git a/docs/api-reference/python/aixplain/utils/llm_utils.md b/docs/api-reference/python/aixplain/utils/llm_utils.md index 90458345..15176fa2 100644 --- a/docs/api-reference/python/aixplain/utils/llm_utils.md +++ b/docs/api-reference/python/aixplain/utils/llm_utils.md @@ -6,7 +6,9 @@ title: aixplain.utils.llm_utils #### get\_llm\_instance ```python -def get_llm_instance(llm_id: Text, api_key: Optional[Text] = None) -> LLM +def get_llm_instance(llm_id: Text, + api_key: Optional[Text] = None, + use_cache: bool = True) -> LLM ``` [[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/utils/llm_utils.py#L6) @@ -17,6 +19,7 @@ Get an LLM instance with specific configuration. - `llm_id` _Text_ - ID of the LLM model to use. - `api_key` _Optional[Text], optional_ - API key to use. Defaults to None. +- `use_cache` _bool, optional_ - Whether to use caching for model retrieval. Defaults to True. **Returns**: diff --git a/docs/api-reference/python/aixplain/v2/core.md b/docs/api-reference/python/aixplain/v2/core.md index a31d0639..be1feff2 100644 --- a/docs/api-reference/python/aixplain/v2/core.md +++ b/docs/api-reference/python/aixplain/v2/core.md @@ -3,13 +3,15 @@ sidebar_label: core title: aixplain.v2.core --- +Core module for aiXplain v2 API. + ### Aixplain Objects ```python class Aixplain() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L37) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L39) Main class for the Aixplain API. @@ -33,9 +35,10 @@ Main class for the Aixplain API. def __new__(cls, *args, **kwargs) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L100) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L102) Singleton pattern for the Aixplain class. + Otherwise, the environment variables will be overwritten in multiple instances. TODO: This should be removed once the factory classes are removed. @@ -49,7 +52,7 @@ def __init__(api_key: str = None, model_url: str = None) ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L112) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L114) Initialize the Aixplain class. @@ -66,7 +69,7 @@ Initialize the Aixplain class. def init_client() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L140) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L148) Initialize the client. @@ -76,7 +79,7 @@ Initialize the client. def init_env() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L147) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L155) Initialize the environment variables. @@ -88,7 +91,7 @@ This is required for the legacy use of the factory classes. def init_resources() ``` -[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L157) +[[view_source]](https://github.com/aixplain/aiXplain/blob/main/aixplain/v2/core.py#L165) Initialize the resources. diff --git a/pyproject.toml b/pyproject.toml index 30c04f26..62211397 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ namespaces = true [project] name = "aiXplain" -version = "0.2.36" +version = "0.2.37" description = "aiXplain SDK adds AI functions to software." readme = "README.md" requires-python = ">=3.9, <4" diff --git a/tests/unit/agent/agent_test.py b/tests/unit/agent/agent_test.py index 540fb734..81b6debf 100644 --- a/tests/unit/agent/agent_test.py +++ b/tests/unit/agent/agent_test.py @@ -476,26 +476,34 @@ def test_run_success(): assert response["url"] == ref_response["data"] -def test_run_variable_error(): +def test_run_variable_missing(): + """Test that agent runs successfully even when variables are missing from data/parameters.""" agent = Agent( "123", "Test Agent", "Agent description", instructions="Translate the input data into {target_language}", ) - agent = Agent( - "123", - "Test Agent", - "Agent description", - instructions="Translate the input data into {target_language}", - ) - with pytest.raises(Exception) as exc_info: - agent.run_async(data={"query": "Hello, how are you?"}, output_format=OutputFormat.MARKDOWN) - assert str(exc_info.value) == ( - "Variable 'target_language' not found in data or parameters. " - "This variable is required by the agent according to its description " - "('Translate the input data into {target_language}')." - ) + + # Mock the agent URL and response + url = urljoin(config.BACKEND_URL, f"sdk/agents/{agent.id}/run") + agent.url = url + + with requests_mock.Mocker() as mock: + headers = { + "x-api-key": config.AIXPLAIN_API_KEY, + "Content-Type": "application/json", + } + ref_response = {"data": "www.aixplain.com", "status": "IN_PROGRESS"} + mock.post(url, headers=headers, json=ref_response) + + # This should not raise an exception anymore - missing variables are silently ignored + response = agent.run_async(data={"query": "Hello, how are you?"}, output_format=OutputFormat.MARKDOWN) + + # Verify the response is successful + assert isinstance(response, AgentResponse) + assert response["status"] == "IN_PROGRESS" + assert response["url"] == ref_response["data"] def test_process_variables(): diff --git a/tests/unit/team_agent/team_agent_test.py b/tests/unit/team_agent/team_agent_test.py index e63355a8..24098665 100644 --- a/tests/unit/team_agent/team_agent_test.py +++ b/tests/unit/team_agent/team_agent_test.py @@ -741,8 +741,8 @@ def test_save_success(mock_model_factory_get): # Call the save method team_agent.save() - # Assert no warnings were triggered - assert len(w) == 0, f"Warnings were raised: {[str(warning.message) for warning in w]}" + # Assert the correct number of warnings were raised + assert len(w) == 3, f"Warnings were raised: {[str(warning.message) for warning in w]}" assert team_agent.id == ref_response["id"] assert team_agent.name == ref_response["name"]