feat(eventarc): Support Context callables and correct OMIT behavior - #6600
Open
milenvk wants to merge 3 commits into
Open
feat(eventarc): Support Context callables and correct OMIT behavior#6600milenvk wants to merge 3 commits into
milenvk wants to merge 3 commits into
Conversation
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
CloudEventAttributesBindingwere always evaluated against the eventpayload. This prevented developers from correlating CloudEvents with ADK runtime telemetry (such as session IDs or invocation IDs fromContext).time=OMITordatacontenttype=OMITinCloudEventAttributesBindingskipped adding keyword arguments when callingpublish_message. Becausepublish_messageauto-generates default UTC timestamps and content types when arguments areNoneor omitted,time=OMITgenerated a timestamp instead of omitting the header.pip install "google-adk[gcp]"prerequisite step needed for Eventarc publishing.Solution:
0-arg,1-arg, and2-argcallables) toCloudEventAttributesBindingso callables can receive the eventpayload, the runtimeContext(tool_context), or both, while preserving full backward compatibility with existing payload callbacks.time=OMITordatacontenttype=OMITnow explicitly passes empty string ("") topublish_messageso attributes are omitted from published CloudEvents. Explicitly setting required CloudEvent specification headers (id=OMIT,specversion=OMIT) now raises aTypeErrorat tool build time.domain_specific_agentandgeneric_agent) to demonstrateContextcallables,time=OMIT, and GCP extra prerequisites.Testing Plan
Unit Tests:
Summary of passed
pytestresults:test_runtime_execution_with_context_and_payload_lambdasto verify 1-parameter (payloadorContext) and 2-parameter callables.test_time_and_datacontenttype_omit_pass_empty_stringto verify omission oftimeanddatacontenttype.test_id_and_specversion_omit_raise_typeerrorto verify static validation against omitting mandatory CloudEvent specification headers.Manual End-to-End (E2E) Tests:
contributing/samples/integrations/eventarc/domain_specific_agent/agent.pybuild and run correctly.complete_outreach_lambda_toolcorrectly injectsContext.session_idinto the event source and thatping_system_toolemits events without a timestamp header when configured withtime=OMIT.Checklist
Additional context
Addresses the technical verification report on google/adk-docs#2045 comment.