Skip to content

feat(eventarc): Support Context callables and correct OMIT behavior - #6600

Open
milenvk wants to merge 3 commits into
google:mainfrom
milenvk:main
Open

feat(eventarc): Support Context callables and correct OMIT behavior#6600
milenvk wants to merge 3 commits into
google:mainfrom
milenvk:main

Conversation

@milenvk

@milenvk milenvk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:

  1. Callable attribute bindings in CloudEventAttributesBinding were always evaluated against the event payload. This prevented developers from correlating CloudEvents with ADK runtime telemetry (such as session IDs or invocation IDs from Context).
  2. Setting time=OMIT or datacontenttype=OMIT in CloudEventAttributesBinding skipped adding keyword arguments when calling publish_message. Because publish_message auto-generates default UTC timestamps and content types when arguments are None or omitted, time=OMIT generated a timestamp instead of omitting the header.
  3. Sample READMEs omitted the required pip install "google-adk[gcp]" prerequisite step needed for Eventarc publishing.

Solution:

  1. Added automatic signature inspection (0-arg, 1-arg, and 2-arg callables) to CloudEventAttributesBinding so callables can receive the event payload, the runtime Context (tool_context), or both, while preserving full backward compatibility with existing payload callbacks.
  2. Setting time=OMIT or datacontenttype=OMIT now explicitly passes empty string ("") to publish_message so attributes are omitted from published CloudEvents. Explicitly setting required CloudEvent specification headers (id=OMIT, specversion=OMIT) now raises a TypeError at tool build time.
  3. Updated sample agents and sample READMEs (domain_specific_agent and generic_agent) to demonstrate Context callables, time=OMIT, and GCP extra prerequisites.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of passed pytest results:

uv run --all-extras pytest tests/unittests/integrations/eventarc -v

======================== 63 passed, 4 warnings, 13 subtests passed in 3.14s ========================
  • Added test_runtime_execution_with_context_and_payload_lambdas to verify 1-parameter (payload or Context) and 2-parameter callables.
  • Added test_time_and_datacontenttype_omit_pass_empty_string to verify omission of time and datacontenttype.
  • Added test_id_and_specversion_omit_raise_typeerror to verify static validation against omitting mandatory CloudEvent specification headers.

Manual End-to-End (E2E) Tests:

  • Verified that sample agent tools in contributing/samples/integrations/eventarc/domain_specific_agent/agent.py build and run correctly.
  • Confirmed that complete_outreach_lambda_tool correctly injects Context.session_id into the event source and that ping_system_tool emits events without a timestamp header when configured with time=OMIT.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Addresses the technical verification report on google/adk-docs#2045 comment.

milenvk added 2 commits August 5, 2026 16:22
Previously, callable bindings in CloudEventAttributesBinding were always
evaluated against the event payload. This prevented developers from
correlating CloudEvents with ADK runtime telemetry such as session IDs.

Callable attribute bindings can now inspect the event payload, the agent
runtime Context (tool_context), or both. Callables are inspected by
signature to support 0-arg, 1-arg (payload or Context), and 2-arg
functions while maintaining full backward compatibility with existing
payload callbacks.

Example usage:
  CloudEventAttributesBinding(
      type=lambda p: f"action.{p.action}",
      source=lambda ctx: f"//agent/{ctx.session_id}",
      subject=lambda payload, ctx: f"{payload.user_id}-{ctx.session_id}",
  )

Addresses feedback on google/adk-docs#2045
Previously, passing OMIT for optional CloudEvent headers like time and
datacontenttype skipped adding them to keyword arguments. Because
publish_message auto-generates timestamps and content types when
arguments are skipped, time=OMIT generated a UTC timestamp instead
of omitting the header.

Setting time=OMIT or datacontenttype=OMIT now explicitly passes empty
string ("") to publish_message so attributes are omitted from the
published CloudEvent. In addition, id=OMIT and specversion=OMIT now
raise a TypeError at tool build time since id and specversion are
mandatory CloudEvent specification headers.

Also updates sample READMEs to include google-adk[gcp] prerequisites.

Addresses feedback on google/adk-docs#2045
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants