aixplain.modules.team_agent.inspector
Pre-defined agent for inspecting the data flow within a team agent. WARNING: This feature is currently in private beta.
WARNING: This feature is currently in private beta.
Example usage:
inspector = Inspector( name="my_inspector", model_id="my_model", model_config={"prompt": "Check if the data is safe to use."}, policy=InspectorPolicy.ADAPTIVE )
team = TeamAgent( name="team" agents=agents, description="team description", llm_id="xyz", use_mentalist=True, inspectors=[inspector], )
AUTO_DEFAULT_MODEL_ID
GPT-4.1 Nano
InspectorAction Objects
class InspectorAction(str, Enum)
Inspector's decision on the next action.
InspectorOutput Objects
class InspectorOutput(BaseModel)
Inspector's output.
InspectorAuto Objects
class InspectorAuto(str, Enum)
A list of keywords for inspectors configured automatically in the backend.
get_name
def get_name() -> Text
Get the standardized name for this inspector type.
This method generates a consistent name for the inspector by prefixing the enum value with "inspector_".
Returns:
Text
- The inspector name in the format "inspector_<type>".
InspectorPolicy Objects
class InspectorPolicy(str, Enum)
Which action to take if the inspector gives negative feedback.
WARN
log only, continue execution
ABORT
stop execution
ADAPTIVE
adjust execution according to feedback
validate_policy_callable
def validate_policy_callable(policy_func: Callable) -> bool
Validate that the policy callable meets the required constraints.
callable_to_code_string
def callable_to_code_string(policy_func: Callable) -> str
Convert a callable policy function to a code string for serialization.
code_string_to_callable
def code_string_to_callable(code_string: str) -> Callable
Convert a code string back to a callable function for deserialization.
get_policy_source
def get_policy_source(func: Callable) -> Optional[str]
Get the source code of a policy function.
This function tries to retrieve the source code of a policy function. It first checks if the function has a stored _source_code attribute (for functions created via code_string_to_callable), then falls back to inspect.getsource().
Arguments:
func
- The function to get source code for
Returns:
The source code string if available, None otherwise
Inspector Objects
class Inspector(ModelWithParams)
Pre-defined agent for inspecting the data flow within a team agent.
The model should be onboarded before using it as an inspector.
Attributes:
name
- The name of the inspector.model_id
- The ID of the model to wrap.model_params
- The configuration for the model.policy
- The policy for the inspector. Can be InspectorPolicy enum or a callable function. If callable, must have name "process_response", arguments "model_response" and "input_content" (both strings), and return InspectorAction. Default is ADAPTIVE.
__init__
def __init__(*args, **kwargs)
Initialize an Inspector instance.
This method initializes an inspector with either a custom model or an automatic configuration. If auto is specified, it uses the default auto model ID.
Arguments:
*args
- Variable length argument list passed to parent class.**kwargs
- Arbitrary keyword arguments. Supported keys:- name (Text): The inspector's name
- model_id (Text): The model ID to use
- model_params (Dict, optional): Model configuration
- auto (InspectorAuto, optional): Auto configuration type
- policy (InspectorPolicy, optional): Inspector policy
Notes:
If auto is specified in kwargs, model_id is automatically set to AUTO_DEFAULT_MODEL_ID.
validate_name
@field_validator("name")
def validate_name(cls, v: Text) -> Text
Validate the inspector name field.
This validator ensures that the inspector's name is not empty.
Arguments:
v
Text - The name value to validate.
Returns:
Text
- The validated name value.
Raises:
ValueError
- If the name is an empty string.
model_dump
def model_dump(by_alias: bool = False, **kwargs) -> Dict
Override model_dump to handle callable policy serialization.
model_validate
@classmethod
def model_validate(cls, data: Union[Dict, "Inspector"]) -> "Inspector"
Override model_validate to handle callable policy deserialization.