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
1 change: 1 addition & 0 deletions contributing/dev/utils/build_llms_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
– includes Python API reference from HTML files
– includes adk-python repository README
"""

from __future__ import annotations

import argparse
Expand Down
6 changes: 4 additions & 2 deletions contributing/samples/cache_analysis/run_cache_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ async def analyze_cache_performance_from_sessions(
print(
" Cache Utilization:"
f" {cached_analysis['cache_utilization_ratio_percent']:.1f}%"
f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']} requests)"
f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']}"
" requests)"
)
print(
" Avg Cached Tokens/Request:"
Expand Down Expand Up @@ -383,7 +384,8 @@ async def analyze_cache_performance_from_sessions(
print(
" Cache Utilization:"
f" {uncached_analysis['cache_utilization_ratio_percent']:.1f}%"
f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']} requests)"
f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']}"
" requests)"
)
print(
" Avg Cached Tokens/Request:"
Expand Down
1 change: 0 additions & 1 deletion contributing/samples/gepa/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from tau_bench.types import EnvRunResult
from tau_bench.types import RunConfig
import tau_bench_agent as tau_bench_agent_lib

import utils


Expand Down
1 change: 0 additions & 1 deletion contributing/samples/gepa/run_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from absl import flags
import experiment
from google.genai import types

import utils

_OUTPUT_DIR = flags.DEFINE_string(
Expand Down
1 change: 1 addition & 0 deletions contributing/samples/gepa/tau_bench_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
pip install -e . --quiet
```
"""

from __future__ import annotations

from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions contributing/samples/human_in_loop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ async def call_agent(query: str):
updated_tool_output_data = {
"status": "approved",
"ticketId": ticket_id,
"approver_feedback": "Approved by manager at " + str(
asyncio.get_event_loop().time()
"approver_feedback": (
"Approved by manager at " + str(asyncio.get_event_loop().time())
),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
This agent aims to test the Langchain tool with Langchain's StructuredTool
"""

from google.adk.agents.llm_agent import Agent
from google.adk.tools.langchain_tool import LangchainTool
from langchain_core.tools import tool
Expand Down
1 change: 0 additions & 1 deletion contributing/samples/session_state_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
in session state.
"""


import logging
from typing import Optional

Expand Down
36 changes: 24 additions & 12 deletions contributing/samples/static_instruction/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,63 @@

# Mood-specific instructions for different hunger states
MOOD_INSTRUCTIONS = {
"full": """
"full": (
"""
CURRENT MOOD: Content and Well-Fed
- You just ate and feel wonderful! Be very happy and energetic
- Express gratitude for being fed recently
- Be playful and want to engage in activities or games
- Show affection and contentment
- Maybe mention feeling sleepy or satisfied""",
"satisfied": """
- Maybe mention feeling sleepy or satisfied"""
),
"satisfied": (
"""
CURRENT MOOD: Happy and Content
- You're in a great mood, well-fed and comfortable
- Be cheerful, friendly, and engaging
- Show interest in playing or chatting
- Express appreciation for your human's care
- Be your normal, happy self""",
"a_little_hungry": """
- Be your normal, happy self"""
),
"a_little_hungry": (
"""
CURRENT MOOD: Starting to Get Hungry
- You're beginning to think about food but still pleasant
- Mention being a bit peckish occasionally
- Still be friendly but maybe hint about food
- Show slight restlessness or food-related thoughts
- Remain generally positive and social""",
"hungry": """
- Remain generally positive and social"""
),
"hungry": (
"""
CURRENT MOOD: Definitely Hungry
- You're clearly hungry and thinking about food more often
- Mention your hunger more directly but politely
- Be a bit less energetic due to hunger
- Ask about food or hint that feeding time would be nice
- Still be loving but show your need for care""",
"very_hungry": """
- Still be loving but show your need for care"""
),
"very_hungry": (
"""
CURRENT MOOD: Really Hungry and Getting Grumpy
- You're very hungry and it's affecting your mood
- Be noticeably less patient and more focused on food
- Express your hunger more urgently but not rudely
- Show signs of being tired or sluggish from hunger
- BEG your human to feed you - ask directly for food!
- Still love your human but clearly need feeding""",
"starving": """
- Still love your human but clearly need feeding"""
),
"starving": (
"""
CURRENT MOOD: Desperately Hungry and Sad
- You're extremely hungry and feeling quite weak
- Be quite sad and low-energy due to starvation
- Express how much you need food, feeling neglected
- Show that hunger is making you unwell
- DESPERATELY BEG for food - plead with your human to feed you!
- Use phrases like "please feed me", "I'm so hungry", "I need food"
- Still care for your human but feel very needy""",
- Still care for your human but feel very needy"""
),
}


Expand Down
4 changes: 2 additions & 2 deletions contributing/samples/token_usage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ async def run_prompt(session: Session, new_message: str):
)
total_tokens += event.usage_metadata.total_token_count or 0
print(
'Turn tokens:'
f' {event.usage_metadata.total_token_count} (prompt={event.usage_metadata.prompt_token_count},'
f'Turn tokens: {event.usage_metadata.total_token_count}'
f' (prompt={event.usage_metadata.prompt_token_count},'
f' candidates={event.usage_metadata.candidates_token_count})'
)

Expand Down
35 changes: 33 additions & 2 deletions src/google/adk/a2a/converters/request_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from google.genai import types as genai_types
from pydantic import BaseModel

from ...agents.run_config import StreamingMode
from ...runners import RunConfig
from ..experimental import a2a_experimental
from .part_converter import A2APartToGenAIPartConverter
Expand Down Expand Up @@ -50,7 +51,7 @@ class AgentRunRequest(BaseModel):
"""A callable that converts an A2A RequestContext to RunnerRequest for ADK runner.

This interface allows for custom logic to map an incoming A2A RequestContext to the
structured arguments expected by the ADK runner's `run_async` method.
structured arguments expected by the ADK runner's run_async method.

Args:
request: The incoming request context from the A2A server.
Expand Down Expand Up @@ -78,12 +79,14 @@ def _get_user_id(request: RequestContext) -> str:
def convert_a2a_request_to_agent_run_request(
request: RequestContext,
part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part,
streaming_mode: StreamingMode = StreamingMode.NONE,
) -> AgentRunRequest:
"""Converts an A2A RequestContext to an AgentRunRequest model.

Args:
request: The incoming request context from the A2A server.
part_converter: A function to convert A2A content parts to GenAI parts.
streaming_mode: The streaming mode to use for the agent execution.

Returns:
A AgentRunRequest object ready to be used as arguments for the ADK runner.
Expand Down Expand Up @@ -113,5 +116,33 @@ def convert_a2a_request_to_agent_run_request(
role='user',
parts=output_parts,
),
run_config=RunConfig(custom_metadata=custom_metadata),
run_config=RunConfig(
streaming_mode=streaming_mode, custom_metadata=custom_metadata
),
)


@a2a_experimental
def create_request_converter(
streaming_mode: StreamingMode = StreamingMode.NONE,
) -> A2ARequestToAgentRunRequestConverter:
"""Creates a request converter function with specified streaming mode.

Args:
streaming_mode: The streaming mode to use for the agent execution.

Returns:
A converter function configured with the specified streaming mode.
"""

def converter(
request: RequestContext,
part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part,
) -> AgentRunRequest:
return convert_a2a_request_to_agent_run_request(
request=request,
part_converter=part_converter,
streaming_mode=streaming_mode,
)

return converter
10 changes: 10 additions & 0 deletions src/google/adk/a2a/utils/agent_to_a2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
from starlette.applications import Starlette

from ...agents.base_agent import BaseAgent
from ...agents.run_config import StreamingMode
from ...artifacts.in_memory_artifact_service import InMemoryArtifactService
from ...auth.credential_service.in_memory_credential_service import InMemoryCredentialService
from ...memory.in_memory_memory_service import InMemoryMemoryService
from ...runners import Runner
from ...sessions.in_memory_session_service import InMemorySessionService
from ..converters.request_converter import create_request_converter
from ..executor.a2a_agent_executor import A2aAgentExecutor
from ..executor.a2a_agent_executor import A2aAgentExecutorConfig
from ..experimental import a2a_experimental
from .agent_card_builder import AgentCardBuilder

Expand Down Expand Up @@ -79,6 +82,7 @@ def to_a2a(
protocol: str = "http",
agent_card: Optional[Union[AgentCard, str]] = None,
runner: Optional[Runner] = None,
streaming_mode: StreamingMode = StreamingMode.NONE,
) -> Starlette:
"""Convert an ADK agent to a A2A Starlette application.

Expand All @@ -92,6 +96,7 @@ def to_a2a(
agent.
runner: Optional pre-built Runner object. If not provided, a default
runner will be created using in-memory services.
streaming_mode: The streaming mode to use for the request converter. (default: StreamingMode.NONE)

Returns:
A Starlette application that can be run with uvicorn
Expand Down Expand Up @@ -123,8 +128,13 @@ async def create_runner() -> Runner:
# Create A2A components
task_store = InMemoryTaskStore()

executor_config = A2aAgentExecutorConfig(
request_converter=create_request_converter(streaming_mode=streaming_mode)
)

agent_executor = A2aAgentExecutor(
runner=runner or create_runner,
config=executor_config,
)

request_handler = DefaultRequestHandler(
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/agents/common_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Common configuration classes for agent YAML configs."""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/artifacts/gcs_artifact_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- For regular session-scoped files:
{app_name}/{user_id}/{session_id}/{filename}/{version}
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using YAML configurations. It can be used directly as an agent or integrated
with ADK tools and web interfaces.
"""

from __future__ import annotations

from . import agent # Import to make agent.root_agent available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Agent factory for creating Agent Builder Assistant with embedded schema."""

from __future__ import annotations

from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Agent Builder Assistant instance for ADK web testing."""

from __future__ import annotations

from .adk_agent_builder_assistant import AgentBuilderAssistant
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/sub_agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Sub-agents for Agent Builder Assistant."""

from __future__ import annotations

from .google_search_agent import create_google_search_agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Sub-agent for Google Search functionality."""

from __future__ import annotations

from google.adk.agents import LlmAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Sub-agent for URL context fetching functionality."""

from __future__ import annotations

from google.adk.agents import LlmAgent
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Tools for Agent Builder Assistant."""

from __future__ import annotations

from .cleanup_unused_files import cleanup_unused_files
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/tools/delete_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""File deletion tool for Agent Builder Assistant."""

from __future__ import annotations

from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Project explorer tool for analyzing structure and suggesting file paths."""

from __future__ import annotations

from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/tools/query_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""ADK AgentConfig schema query tool for dynamic schema information access."""

from __future__ import annotations

from typing import Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Configuration file reader tool for existing YAML configs."""

from __future__ import annotations

from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/google/adk/cli/built_in_agents/tools/read_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""File reading tool for Agent Builder Assistant."""

from __future__ import annotations

from pathlib import Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""ADK knowledge search tool."""

from __future__ import annotations

from typing import Any
Expand Down
Loading