Created
April 29, 2025 11:53
-
-
Save juneira/862422fb7186af407f2418c1fee016ad to your computer and use it in GitHub Desktop.
Sample using ADK + OpenAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from google.adk.agents import Agent | |
| from google.adk.tools.openapi_tool.auth.auth_helpers import token_to_scheme_credential | |
| from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import OpenAPIToolset | |
| with open("/path/to/swagger.json", "r") as f: | |
| swagger_data = f.read() | |
| auth_scheme, auth_credential = token_to_scheme_credential( | |
| "apikey", "header", "Authorization", "JWT_TOKEN" | |
| ) | |
| toolset = OpenAPIToolset( | |
| spec_str=swagger_data, | |
| spec_str_type="json", | |
| auth_scheme=auth_scheme, | |
| auth_credential=auth_credential, | |
| ) | |
| generated_tools_list = toolset.get_tools() | |
| instruction = f"""Você é um ajudante de <DESCRICAO>, e sua tarefa é <FUNCOES>. | |
| Use as funções abaixo abaixo para resolver as requisições do usuário: | |
| {"\n".join([f"{t.name}: {t.description}" for t in generated_tools_list])} | |
| """ | |
| root_agent = Agent( | |
| name="<NOME_AGENTE>", | |
| model="gemini-2.0-flash", | |
| description=( | |
| "Agente para servir os dados de um <DESCRICAO>, respondendo dados <FUNCOES>." | |
| ), | |
| instruction=instruction, | |
| tools=toolset.get_tools(), | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment