Skip to content

Model information

Tool for get model information.

GetModelInfoInput

Bases: BaseModel

Input schema for the GetModelInfo tool.

Source code in aiagents4pharma/talk2biomodels/tools/get_modelinfo.py
35
36
37
38
39
40
41
42
class GetModelInfoInput(BaseModel):
    """
    Input schema for the GetModelInfo tool.
    """
    requested_model_info: RequestedModelInfo = Field(description="requested model information")
    sys_bio_model: ModelData = Field(description="model data")
    tool_call_id: Annotated[str, InjectedToolCallId]
    state: Annotated[dict, InjectedState]

GetModelInfoTool

Bases: BaseTool

This tool ise used extract model information.

Source code in aiagents4pharma/talk2biomodels/tools/get_modelinfo.py
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class GetModelInfoTool(BaseTool):
    """
    This tool ise used extract model information.
    """
    name: str = "get_modelinfo"
    description: str = """A tool for extracting name,
                    description, species, parameters,
                    compartments, and units from a model."""
    args_schema: Type[BaseModel] = GetModelInfoInput

    def _run(self,
            requested_model_info: RequestedModelInfo,
            tool_call_id: Annotated[str, InjectedToolCallId],
            state: Annotated[dict, InjectedState],
            sys_bio_model: Optional[ModelData] = None,
             ) -> Command:
        """
        Run the tool.

        Args:
            requested_model_info (RequestedModelInfo): The requested model information.
            tool_call_id (str): The tool call ID. This is injected by the system.
            state (dict): The state of the tool.
            sys_bio_model (ModelData): The model data.

        Returns:
            Command: The updated state of the tool.
        """
        logger.log(logging.INFO,
                   "Calling get_modelinfo tool %s, %s",
                     sys_bio_model,
                   requested_model_info)
        # print (state, 'state')
        sbml_file_path = state['sbml_file_path'][-1] if len(state['sbml_file_path']) > 0 else None
        model_obj = load_biomodel(sys_bio_model,
                                  sbml_file_path=sbml_file_path)
        dic_results = {}
        # Extract species from the model
        if requested_model_info.species:
            df_species = basico.model_info.get_species(model=model_obj.copasi_model)
            dic_results['Species'] = df_species['display_name'].tolist()
            dic_results['Species'] = ','.join(dic_results['Species'])

        # Extract parameters from the model
        if requested_model_info.parameters:
            df_parameters = basico.model_info.get_parameters(model=model_obj.copasi_model)
            dic_results['Parameters'] = df_parameters.index.tolist()
            dic_results['Parameters'] = ','.join(dic_results['Parameters'])

        # Extract compartments from the model
        if requested_model_info.compartments:
            df_compartments = basico.model_info.get_compartments(model=model_obj.copasi_model)
            dic_results['Compartments'] = df_compartments.index.tolist()
            dic_results['Compartments'] = ','.join(dic_results['Compartments'])

        # Extract description from the model
        if requested_model_info.description:
            dic_results['Description'] = model_obj.description

        # Extract description from the model
        if requested_model_info.name:
            dic_results['Name'] = model_obj.name

        # Extract time unit from the model
        if requested_model_info.units:
            dic_results['Units'] = basico.model_info.get_model_units(model=model_obj.copasi_model)

        # Prepare the dictionary of updated state for the model
        dic_updated_state_for_model = {}
        for key, value in {
                        "model_id": [sys_bio_model.biomodel_id],
                        "sbml_file_path": [sbml_file_path],
                        }.items():
            if value:
                dic_updated_state_for_model[key] = value

        return Command(
            update=dic_updated_state_for_model|{
                    # update the message history
                    "messages": [
                        ToolMessage(
                            content=dic_results,
                            tool_call_id=tool_call_id
                            )
                        ],
                    }
            )

_run(requested_model_info, tool_call_id, state, sys_bio_model=None)

Run the tool.

Parameters:

Name Type Description Default
requested_model_info RequestedModelInfo

The requested model information.

required
tool_call_id str

The tool call ID. This is injected by the system.

required
state dict

The state of the tool.

required
sys_bio_model ModelData

The model data.

None

Returns:

Name Type Description
Command Command

The updated state of the tool.

Source code in aiagents4pharma/talk2biomodels/tools/get_modelinfo.py
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def _run(self,
        requested_model_info: RequestedModelInfo,
        tool_call_id: Annotated[str, InjectedToolCallId],
        state: Annotated[dict, InjectedState],
        sys_bio_model: Optional[ModelData] = None,
         ) -> Command:
    """
    Run the tool.

    Args:
        requested_model_info (RequestedModelInfo): The requested model information.
        tool_call_id (str): The tool call ID. This is injected by the system.
        state (dict): The state of the tool.
        sys_bio_model (ModelData): The model data.

    Returns:
        Command: The updated state of the tool.
    """
    logger.log(logging.INFO,
               "Calling get_modelinfo tool %s, %s",
                 sys_bio_model,
               requested_model_info)
    # print (state, 'state')
    sbml_file_path = state['sbml_file_path'][-1] if len(state['sbml_file_path']) > 0 else None
    model_obj = load_biomodel(sys_bio_model,
                              sbml_file_path=sbml_file_path)
    dic_results = {}
    # Extract species from the model
    if requested_model_info.species:
        df_species = basico.model_info.get_species(model=model_obj.copasi_model)
        dic_results['Species'] = df_species['display_name'].tolist()
        dic_results['Species'] = ','.join(dic_results['Species'])

    # Extract parameters from the model
    if requested_model_info.parameters:
        df_parameters = basico.model_info.get_parameters(model=model_obj.copasi_model)
        dic_results['Parameters'] = df_parameters.index.tolist()
        dic_results['Parameters'] = ','.join(dic_results['Parameters'])

    # Extract compartments from the model
    if requested_model_info.compartments:
        df_compartments = basico.model_info.get_compartments(model=model_obj.copasi_model)
        dic_results['Compartments'] = df_compartments.index.tolist()
        dic_results['Compartments'] = ','.join(dic_results['Compartments'])

    # Extract description from the model
    if requested_model_info.description:
        dic_results['Description'] = model_obj.description

    # Extract description from the model
    if requested_model_info.name:
        dic_results['Name'] = model_obj.name

    # Extract time unit from the model
    if requested_model_info.units:
        dic_results['Units'] = basico.model_info.get_model_units(model=model_obj.copasi_model)

    # Prepare the dictionary of updated state for the model
    dic_updated_state_for_model = {}
    for key, value in {
                    "model_id": [sys_bio_model.biomodel_id],
                    "sbml_file_path": [sbml_file_path],
                    }.items():
        if value:
            dic_updated_state_for_model[key] = value

    return Command(
        update=dic_updated_state_for_model|{
                # update the message history
                "messages": [
                    ToolMessage(
                        content=dic_results,
                        tool_call_id=tool_call_id
                        )
                    ],
                }
        )

RequestedModelInfo dataclass

Dataclass for storing the requested model information.

Source code in aiagents4pharma/talk2biomodels/tools/get_modelinfo.py
23
24
25
26
27
28
29
30
31
32
33
@dataclass
class RequestedModelInfo:
    """
    Dataclass for storing the requested model information.
    """
    species: bool = Field(description="Get species from the model.", default=False)
    parameters: bool = Field(description="Get parameters from the model.", default=False)
    compartments: bool = Field(description="Get compartments from the model.", default=False)
    units: bool = Field(description="Get units from the model.", default=False)
    description: bool = Field(description="Get description from the model.", default=False)
    name: bool = Field(description="Get name from the model.", default=False)