Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

no attribute 'Agent' Error 'in 'google.cloud.aiplatform'

Hi,

I am facing above runtime error when trying to deploy an agent using google.cloud.aiplatform'.

aiplatform version: 1.82.0, Python 3.12.3. my python script is below.

any help appreciated,

Brian

 

from google.cloud import aiplatform
import google.auth
import json
import os

def create_vertex_agent(project_id, location, agent_name, display_name, description😞
    """
    Creates a Vertex AI Agent based on the provided configuration.

    Args:
        project_id: The ID of your Google Cloud project.
        location: The location for the Agent.
        agent_name: The name of the Agent.
        display_name: The display name of the Agent.
        description: A description of the Agent.

    Returns:
        The created Agent object.
    """
   
    try:
        # Authenticate with Google Cloud
        credentials, project = google.auth.default()
    except Exception as e:
        print(f"Error getting credentials: {e}")
        return None

    # Initialize Vertex AI SDK
    aiplatform.init(project=project_id, location=location, credentials=credentials)

    # Agent Configuration
    agent_config = {
        "default_language_code": "en",
        "time_zone": "UTC",
        # Add other agent configuration settings here
    }

    # Knowledge Resources
    knowledge_resources = [
        {
            "display_name": "SysML2 Knowledge",
            "source": "URL Removed by Staff" ,
        }
    ]

    # Tool Configuration
    tool_config = {
        "type": "function_calling",
        "function_calling_config": {
            "function_calling_model": "gemini-pro"
        }
    }

    # Intent Configuration
    intent_config = {
        "training_phrases": [
            "Create a new element",
            "Display the model",
            "Add a child element"
        ]
    }

    # Action Configuration
    action_config = {
        "actions": [
            {
                "name": "create_element",
                "handler": "create_element_handler"
            },
            {
                "name": "display_model",
                "handler": "display_model_handler"
            },
            {
                "name": "add_child_element",
                "handler": "add_child_element_handler"
            }
        ]
    }

    # Function Calling Configuration
    function_calling_config = {
        "function_calling_definitions": [
            {
                "name": "call_agent_2",
                "description": "Calls Agent 2 to collect data for a specific SysML element type.",
                "parameters": [
                    {
                        "name": "element_type",
                        "type": "string",
                        "description": "The type of SysML element to create.",
                        "required": True
                    }
                ],
                "return_type": "string"
            },
            {
                "name": "call_agent_3",
                "description": "Calls Agent 3 to query the requirement database.",
                "parameters": [
                    {
                        "name": "query",
                        "type": "string",
                        "description": "The query to execute against the requirement database.",
                        "required": True
                    }
                ],
                "return_type": "string"
            }
        ]
    }

    try:

        # Create the Agent
        agent = aiplatform.Agent.create(
            display_name=display_name,
            #name=agent_name, # Agent name is autogenerated, do not provide
            description=description,
            agent_config=agent_config,
            knowledge_resources=knowledge_resources,
            tool_config=tool_config,
            intent_config=intent_config,
            action_config=action_config,
            function_calling_config=function_calling_config
        )


        print(f"Agent created: {agent.name}")
        return agent

    except Exception as e:
        print(f"Error creating agent: {e}")
        return None


if __name__ == "__main__":

    credentials_path = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")

    if credentials_path:
        print(f"GOOGLE_APPLICATION_CREDENTIALS is set to: {credentials_path}")
    else:
        print("GOOGLE_APPLICATION_CREDENTIALS is not set.")
            # Replace with your actual project ID and location

    print("aiplatform version: ", aiplatform.__version__)

    PROJECT_ID = "sysengcopilot"
    LOCATION = "europe-west6"

    # Agent details from Terraform
    AGENT_NAME = "agent-mbse-autosar-model-orchestrator"  # Needs to be lowercase and hyphenated
    DISPLAY_NAME = "Agent MBSE Autosar Model Orchestrator"
    DESCRIPTION = "Orchestrates the MBSE design process using SysML2 and Autosar."


    # Create the Vertex AI Agent
    agent = create_vertex_agent(PROJECT_ID, LOCATION, AGENT_NAME, DISPLAY_NAME, DESCRIPTION)

    if agent:
        print(f"Agent Name: {agent.name}")
0 1 126
1 REPLY 1