Call Vertex AI Agents from ABAP environment

This quickstart shows you how to call Vertex AI Agents, built with the Agent Development Kit (ADK), from your ABAP environment.

This guide explains the process of calling an AI agent by using the on-premises or any cloud edition of ABAP SDK for Google Cloud, and does not cover creation or deployment procedures. You create an AI agent using the Agent Development Kit (ADK), which is an open-source framework for designing agents, built on the same framework that powers Google Agentspace and Customer Engagement Suite with Google AI. You then deploy your agent to Vertex AI Agent Engine, which is a fully managed runtime in Vertex AI that helps you deploy your custom agents to production with built-in testing, release, and reliability at a global, secure scale.

Before you begin

Before you run this quickstart, make sure that you or your administrators have completed the following prerequisites:

Deploy agent to Vertex AI Agent Engine

Create, test, and deploy your agent to Vertex AI Agent Engine. For this quickstart, you can create a weather and time agent and deploy the agent to Vertex AI Agent Engine.

For information about how to create, test, and deploy your agent, see the following:

Make sure that you've granted the required permissions for the agent to use managed sessions.

After deployment, you get a resource identifier similar to the following example, which enables agent invocation within your ABAP program:

AgentEngine created. Resource name: projects/project_id/locations/us-central1/reasoningEngines/REASONING_ENGINE_ID

From the resource identifier, make a note of the REASONING_ENGINE_ID, for example, 6384464913570601984. You need this in a later step.

Create a program to call Vertex AI Agents from ABAP environment

  1. In the SAP system, create an executable program in your custom namespace (for example, Z or Y) by using transaction SE38.

    1. In the SAP GUI, enter transaction code SE38.

    2. In the Program field, enter a name for your program, for example, ZDEMO_CALL_AGENT.

    3. Click Create.

    4. Specify the program attributes:

      1. In the Title field, enter a title of your program, for example, Call Vertex AI Agent.

      2. In the Type field, choose Executable Program.

      3. Click Save.

    5. Save the program as a Local Object.

    6. In the ABAP Editor, add the following code:

      REPORTzdemo_call_agent.
      DATAlv_p_projects_idTYPE string.
      DATAlv_p_locations_idTYPE string.
      DATAlv_p_reasoning_engines_idTYPE string.
      DATAls_inputTYPE/goog/cl_aiplatform_v1=>ty_1072.
      TYPES:BEGIN OFty_agent_input,
      messageTYPE string,
      session_idTYPE string,
      user_idTYPE string,
      END OFty_agent_input.
      DATAls_agent_inputTYPE ty_agent_input.
      TYPES:BEGIN OFty_response,
      contentTYPE/goog/cl_aiplatform_v1=>ty_695,
      END OFty_response.
      DATAls_agent_responseTYPE ty_response.
      TRY.
      " Open HTTP Connection
      DATA(lo_client)=NEW/goog/cl_aiplatform_v1(iv_key_name='DEMO_AIPLATFORM').
      DATAlv_agent_response_txtTYPE string.
      " Populate relevant parameters
      lv_p_projects_id=lo_client->gv_project_id.
      lv_p_locations_id='LOCATION_ID'.
      lv_p_reasoning_engines_id='REASONING_ENGINE_ID'.
      ls_agent_input-message='What is the weather in New York'."Prompt
      ls_agent_input-user_id='use-101'.
      ls_input-class_method='stream_query'.
      GET REFERENCE OFls_agent_inputINTOls_input-input.
      lo_client->add_json_name_mapping(iv_abap='CLASS_METHOD'iv_json='class_method').
      lo_client->add_json_name_mapping(iv_abap='SESSION_ID'iv_json='session_id').
      lo_client->add_json_name_mapping(iv_abap='USER_ID'iv_json='user_id').
      " Call API method: aiplatform.projects.locations.reasoningEngines.streamQuery
      lo_client->stream_query_reasoning_engi(EXPORTINGiv_p_projects_id=lv_p_projects_id
      iv_p_locations_id=lv_p_locations_id
      iv_p_reasoning_engines_id=lv_p_reasoning_engines_id
      is_input=ls_input
      IMPORTINGes_raw=lv_agent_response_txt
      ev_ret_code=DATA(lv_ret_code)
      ev_err_text=DATA(lv_err_text)
      es_err_resp=DATA(ls_err_resp)).
      " Handle the output
      IFlo_client->is_success(lv_ret_code).
      SPLITlv_agent_response_txtATcl_abap_char_utilities=>newlineINTOTABLEDATA(lt_result_event_tab).
      " Deserialize to read the final response event from agent
      /goog/cl_json_util=>deserialize_json(EXPORTINGiv_json=lt_result_event_tab[3]
      iv_pretty_name=/ui2/cl_json=>pretty_mode-extended
      IMPORTINGes_data=ls_agent_response).
      cl_demo_output=>display(ls_agent_response-content-parts[1]-text).
      ELSE.
      MESSAGElv_err_textTYPE'E'.
      ENDIF.
      " Close HTTP Connection
      lo_client->close().
      CATCH/goog/cx_sdkINTODATA(lo_exception).
      MESSAGElo_exception->get_text()TYPE'E'.
      ENDTRY.
      

      Replace the following:

      • DEMO_AIPLATFORM: The client key for authentication to Google Cloud.
      • LOCATION_ID: The location where the agent is deployed. You specify the location when you initialize the agent. For more information, see Initialize the agent.
      • REASONING_ENGINE_ID: The resource identifier for the agent that you've noted in the Deploy agent to Vertex AI Agent Engine section.
  2. Run your application in SE38.

  3. Validate that the results are consistent with those observed when the agent was run locally.

    Example response: OK. The weather in New York is sunny with a temperature of 25 degrees Celsius (41 degrees Fahrenheit).
    

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月04日 UTC.