Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ services: Integrations with external services, like databases, vector stores, or

tools: Standalone tools that can be used by agents.

models: Model adapters for third-party model APIs.

deployment: Scripts and configurations to help you deploy your ADK agents to various platforms.

# We Welcome Your Contributions!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.adk/
__pycache__/
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Hello World with Azure OpenAI Responses

## Overview

This sample is a manual end-to-end test for the community Azure OpenAI
Responses API model client. It validates that ADK can run an agent with
`AzureOpenAIResponsesLlm`, execute a custom function tool, preserve multi-turn
context through the runner, and directly chain Responses API calls with
`previous_response_id`.

## Sample Inputs

- `Reply with exactly: AZURE_RESPONSES_TEXT_OK`

Verifies basic text generation through `Runner.run_async`.

- `Use the weather tool for Tokyo and report the result.`

Verifies Responses API function calling and function result handling.

- `What manual E2E code phrase did I ask you to remember?`

Verifies multi-turn runner context after a previous turn stores the phrase
`cobalt otter`.

- `Using the previous response context, what direct Responses code phrase did I ask you to remember?`

Verifies direct model-level `previous_response_id` chaining after a prior
Responses API call stores the phrase `amber swan`.

## Graph

```mermaid
graph TD
User --> Runner
Runner --> Agent[azure_openai_responses_agent]
Agent --> Model[AzureOpenAIResponsesLlm]
Agent --> Tool[get_current_weather]
Model --> Responses[Azure OpenAI Responses API]
```

## How To

Create a `.env` file in this directory or export the variables in your shell:

```bash
export AZURE_OPENAI_API_KEY="your-api-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"
export AZURE_OPENAI_RESPONSES_DEPLOYMENT="your-model-deployment"
```

Install this repository with the OpenAI extra before running the sample:

```bash
uv sync --extra openai
```

Run the manual E2E test from this sample directory:

```bash
cd contributing/samples/models/hello_world_azure_openai_responses
python main.py
```

The test prints the runner setup, tool calls, tool responses, interaction IDs,
and pass/fail status for each scenario.

Expected output shape:

```text
Azure OpenAI Responses manual E2E
Endpoint: https://your-resource.openai.azure.com
Deployment: your-model-deployment

========================================================================
TEST 1: Runner Basic Text Generation
========================================================================
>> User: Reply with exactly: AZURE_RESPONSES_TEXT_OK
<< Agent: AZURE_RESPONSES_TEXT_OK
PASSED: Runner basic text generation works

========================================================================
TEST 2: Runner Function Calling
========================================================================
>> User: Use the weather tool for Tokyo and report the result.
[Tool Call] get_current_weather({'city': 'Tokyo'})
[Tool Result] get_current_weather: {'city': 'Tokyo', ...}
<< Agent: Tokyo ... 68 ... Partly Cloudy
PASSED: Runner function calling works

========================================================================
TEST 3: Runner Multi-Turn Context
========================================================================
PASSED: Runner multi-turn context works

========================================================================
TEST 4: Direct Responses previous_response_id Chaining
========================================================================
First response id: resp_...
<< Direct model: amber swan
Second response id: resp_...
PASSED: Direct previous_response_id chaining works

========================================================================
ALL MANUAL E2E TESTS PASSED
```

## Manual E2E PR Evidence

For PR validation, include the exact command and relevant console output:

```bash
cd contributing/samples/models/hello_world_azure_openai_responses
python main.py
```

Highlight these log sections in the PR description:

- `TEST 1: Runner Basic Text Generation`
- `TEST 2: Runner Function Calling`, including `[Tool Call]` and `[Tool Result]`
- `TEST 3: Runner Multi-Turn Context`
- `TEST 4: Direct Responses previous_response_id Chaining`, including response IDs
- `ALL MANUAL E2E TESTS PASSED`

## Code Structure

```text
hello_world_azure_openai_responses/
├── __init__.py
├── agent.py
├── main.py
└── README.md
```

## Notes

- This is a manual E2E sample and requires a live Azure OpenAI deployment that
supports the Responses API.
- `AZURE_OPENAI_RESPONSES_DEPLOYMENT` must be the Azure deployment name, not
necessarily the base model name.
- The sample sets `store=True` on `AzureOpenAIResponsesLlm` so the direct
`previous_response_id` check can chain server-side Responses API state.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from . import agent

__all__ = [
'agent',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Azure OpenAI Responses API sample agent."""

from __future__ import annotations

import os

from google.adk.agents.llm_agent import Agent
from google.genai import types
from google.genai.types import GenerateContentConfig

from google.adk_community.models.openai_responses import AzureOpenAIResponsesLlm


def get_current_weather(city: str) -> dict:
"""Get deterministic weather for a city.

Args:
city: The city to look up.

Returns:
A dictionary containing weather information for the requested city.
"""
weather_data = {
'london': {'temperature_f': 59, 'condition': 'Cloudy'},
'paris': {'temperature_f': 64, 'condition': 'Rainy'},
'san francisco': {'temperature_f': 70, 'condition': 'Sunny'},
'tokyo': {'temperature_f': 68, 'condition': 'Partly Cloudy'},
}
data = weather_data.get(
city.lower(), {'temperature_f': 72, 'condition': 'Unknown'}
)
return {
'city': city,
'temperature_f': data['temperature_f'],
'condition': data['condition'],
}


def get_azure_openai_responses_model() -> AzureOpenAIResponsesLlm:
"""Builds the Azure OpenAI Responses model from environment variables."""
return AzureOpenAIResponsesLlm(
model=os.environ.get('AZURE_OPENAI_RESPONSES_DEPLOYMENT', 'gpt-5.5'),
azure_endpoint=os.environ.get('AZURE_OPENAI_ENDPOINT'),
api_key=os.environ.get('AZURE_OPENAI_API_KEY'),
store=True,
reasoning={'effort': 'medium', 'summary': 'concise'},
)


root_agent = Agent(
model=get_azure_openai_responses_model(),
name='azure_openai_responses_agent',
description=(
'Manual E2E sample agent for the Azure OpenAI Responses API community'
' model.'
),
instruction="""
You are a concise test assistant for ADK manual E2E validation.

Rules:
- For exact-response prompts, return only the requested text.
- When the user asks about weather, call get_current_weather.
- When reporting weather, include the city, temperature_f, and condition from
the tool result.
- If the user asks what they told you earlier, answer from conversation context.
""",
tools=[get_current_weather],
generate_content_config=GenerateContentConfig(
max_output_tokens=11512,
),
)
Loading