Mulai 29 April 2025, model Gemini 1.5 Pro dan Gemini 1.5 Flash tidak tersedia di project yang belum pernah menggunakan model ini, termasuk project baru. Untuk mengetahui detailnya, lihat Versi dan siklus proses model.
Autentikasi pengguna untuk mengautentikasi sebagai pengguna untuk membuat kueri agen.
Operasi yang didukung
Operasi berikut didukung untuk AG2Agent:
query: untuk mendapatkan respons kueri secara sinkron.
Metode query mendukung argumen:
input: pesan yang akan dikirim ke agen.
max_turns: jumlah maksimum giliran percakapan yang diizinkan. Saat menggunakan alat, diperlukan minimal max_turns=2: satu giliran untuk membuat argumen alat dan satu giliran lagi untuk menjalankan alat.
Membuat kueri agen
Metode query() menyediakan cara yang disederhanakan untuk berinteraksi dengan agen. Panggilan standar terlihat seperti ini:
response=agent.query(input="What is the exchange rate from US dollars to Swedish currency?",max_turns=2)
Metode ini menangani komunikasi yang mendasarinya dengan agen dan menampilkan respons akhir agen sebagai kamus. Hal ini setara dengan hal berikut (dalam bentuk lengkap):
fromautogenimportConversableAgentimportdataclassesimportjsoninput_message:str="What is the exchange rate from US dollars to Swedish currency?"max_turns:int=2withagent._runnable._create_or_get_executor(tools=agent._ag2_tool_objects,# Use the agent's existing toolsagent_name="user",# Defaultagent_human_input_mode="NEVER",# query() enforces this)asexecutor:chat_result=executor.initiate_chat(agent._runnable,message=input_message,max_turns=max_turns,clear_history=False,# Defaultsummary_method="last_msg"# Default)response=json.loads(json.dumps(dataclasses.asdict(chat_result))# query() does this conversion)
Anda dapat menyesuaikan perilaku agen di luar input dan max_turns dengan meneruskan argumen kata kunci tambahan ke query().
response=agent.query(input="What is the exchange rate from US dollars to Swedish currency?",max_turns=2,msg_to="user"# Start the conversation with the "user" agent)print(response)
Lihat
dokumentasi ConversableAgent.run
untuk mengetahui daftar lengkap parameter yang tersedia. Namun, perlu diingat bahwa
user_input akan selalu diganti dengan False oleh template AG2Agent.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-25 UTC."],[],[],null,["# Use an AG2 agent\n\nIn addition to the general instructions for [using an agent](/vertex-ai/generative-ai/docs/agent-engine/use),\nthis page describes features that are specific to `AG2Agent`.\n\nBefore you begin\n----------------\n\nThis tutorial assumes that you have read and followed the instructions in:\n\n- [Develop an AG2 agent](/vertex-ai/generative-ai/docs/agent-engine/develop/ag2): to develop `agent` as an instance of `AG2Agent`.\n- [User authentication](/vertex-ai/generative-ai/docs/agent-engine/set-up#authentication) to authenticate as a user for querying the agent.\n\nSupported operations\n--------------------\n\nThe following operations are supported for `AG2Agent`:\n\n- [`query`](/vertex-ai/generative-ai/docs/agent-engine/use#query-agent): for getting a response to a query synchronously.\n\nThe `query` method support the arguments:\n\n- `input`: the message to be sent to the agent.\n- `max_turns`: the maximum number of conversation turns allowed. When using tools, a minimum of `max_turns=2` is required: one turn to generate tool arguments and a second to execute the tool.\n\nQuery the agent\n---------------\n\nThe `query()` method provides a simplified way to interact with the agent. A typical call looks like this: \n\n response = agent.query(input=\"What is the exchange rate from US dollars to Swedish currency?\", max_turns=2)\n\nThis method handles the underlying communication with the agent and returns the agent's final response as a dictionary. It is equivalent to the following (in full form): \n\n from autogen import ConversableAgent\n import dataclasses\n import json\n\n input_message: str = \"What is the exchange rate from US dollars to Swedish currency?\"\n max_turns: int = 2\n\n with agent._runnable._create_or_get_executor(\n tools=agent._ag2_tool_objects, # Use the agent's existing tools\n agent_name=\"user\", # Default\n agent_human_input_mode=\"NEVER\", # query() enforces this\n ) as executor:\n chat_result = executor.initiate_chat(\n agent._runnable,\n message=input_message,\n max_turns=max_turns,\n clear_history=False, # Default\n summary_method=\"last_msg\" # Default\n )\n\n response = json.loads(\n json.dumps(dataclasses.asdict(chat_result)) # query() does this conversion\n )\n\nYou can customize the agent's behavior beyond `input` and `max_turns` by passing additional keyword arguments to `query()`. \n\n response = agent.query(\n input=\"What is the exchange rate from US dollars to Swedish currency?\",\n max_turns=2,\n msg_to=\"user\" # Start the conversation with the \"user\" agent\n )\n print(response)\n\nSee the\n[`ConversableAgent.run` documentation](https://docs.ag2.ai/latest/docs/api-reference/autogen/ConversableAgent/)\nfor a complete list of available parameters. However, keep in mind that\n`user_input` will always be overridden to `False` by the AG2Agent template.\n\nWhat's next\n-----------\n\n- [Use an agent](/vertex-ai/generative-ai/docs/agent-engine/use).\n- [Evaluate an agent](/vertex-ai/generative-ai/docs/agent-engine/evaluate).\n- [Manage deployed agents](/vertex-ai/generative-ai/docs/agent-engine/manage).\n- [Get support](/vertex-ai/generative-ai/docs/agent-engine/support)."]]