Skip to content

feat(tools): environment simulation chaos engineering — call targeting (1/3) - #8474

Open
sadayamuthu wants to merge 5 commits into
google:mainfrom
sadayamuthu:chaos-1-call-targeting
Open

sadayamuthu wants to merge 5 commits into
google:mainfrom
sadayamuthu:chaos-1-call-targeting

Conversation

@sadayamuthu

Copy link
Copy Markdown

Link to Issue or Description of Change

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

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

This is PR 1 of 3 adding chaos engineering for ADK agents to Environment Simulation. It adds call targeting. PR 2 adds real-result corruption and PR 3 adds an injection record.

Problem:
An InjectionConfig applies to every call of a tool that matches its match_args. That cannot express the most common resilience scenario: the first call fails, and the agent's retry should reach the real tool. Users have to approximate this with probabilities, which are not repeatable and can fail every call.

Solution:
Add InjectionConfig.on_calls, a list of 1-based call numbers within one invocation at which the injection may apply.

  • The engine counts calls to each configured tool per session and per invocation. EnvironmentSimulationPlugin.after_run_callback drops the session's counts when the run ends (only if they still belong to that invocation). A run that ends paused on an unanswered interrupt (a tool confirmation or credential request) keeps its counts, detected with the same is_paused_invocation check ReflectAndRetryToolPlugin uses: the answer continues the invocation under the same invocation id, so numbering carries over to the resumed run. A call held for confirmation is counted when first attempted and again when it re-executes on resume. on_run_error_callback drops the counts unconditionally when a run fails. Without the plugin (create_callback), a call from a new invocation replaces the session's counts.
  • Every call to a configured tool is counted, whether or not an injection applied.
  • A config whose on_calls excludes the current call is skipped before match_args comparison and before any draw, so it does not advance a seeded random sequence or start a semantic comparison.
  • on_calls=None (the default) keeps today's behaviour. Existing configs are unaffected.
  • Validation: on_calls must be a non-empty list of distinct positive integers.
  • _draw and _seeded_generators are not touched.

Testing Plan

Unit Tests:

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

pytest tests/unittests/tools/environment_simulation -q: 94 passed. New tests cover first-call failure with a real retry, unlisted calls, counts restarting per invocation, counts per session, combination with match_args, ineligible configs not consuming a seeded draw, on_calls=None unchanged, and MagicMock contexts.

Added in review rounds:

  • test_ineligible_args_matcher_config_starts_no_comparison, test_ineligible_catch_all_does_not_block_later_exact_config, test_ineligible_config_is_not_compared_while_others_wait: on_calls with args_matcher and catch-all ordering.
  • test_release_invocation_drops_call_counts, test_release_invocation_keeps_newer_invocation, test_release_invocation_without_counts_is_noop: releasing counts at the end of an invocation.
  • test_after_run_releases_call_counts: counts are gone after a real Runner run.
  • test_paused_run_keeps_call_counts_for_resume: a call paused for confirmation and resumed with confirmed=True is numbered 2, so on_calls=[2] applies on resume.
  • test_run_error_releases_call_counts: counts are gone after a Runner run that fails.

Multi-version tests: not run locally; relying on CI.

Manual End-to-End (E2E) Tests:

An LlmAgent on gemini-3.7-flash with a real lookup_customer tool runs through Runner with on_calls=[1] and a 503 error.

uv run --project <adk-python checkout> python call_targeting.py | tee call_targeting.log

The run log will be added as a comment on this PR. Expected: the first lookup_customer call returns the 503, the retry returns real data, and the agent answers correctly.

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

1 of 3. PR 2 (real-result corruption) and PR 3 (injection record) are stacked on this branch.

A run that pauses on a tool confirmation or credential request is resumed under the same invocation id, so its call counts are kept and on_calls numbering continues. A run that fails now releases the invocation's call counts through on_run_error_callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant