Conversation
- BaseAgenticOptimizer: add `_invoke_agent` helper that times the agent
invocation and captures Strands metrics (tokens, cycles, tool calls,
latency) onto `last_wall_clock_s` / `last_metrics`. ContrastiveReflectionOptimizer
routes through it so callers can read step cost without subclassing.
- AgentCoreRolloutEngine: the engine still builds the canonical
`{"data_sample": ..., "params": ...}` payload. New `payload_mapper:
Callable[[dict], dict]` init kwarg is a transform applied to that
canonical payload before the HTTP call, so deployments expecting a
different shape (flat fields, renamed keys, nested envelopes) can remap
without subclassing the engine. Default is None (no transform), fully
backward-compatible.
- New built-in templates `contrastive_reflection_v2/{system_prompt,task_message_system_prompt}.jinja`:
forbids the "Learned Behaviors" appendix, requires holistic integration
of insights, adds a safety invariant (require user confirmation before
consequential actions), and a length guardrail (<= max(1.1x original,
original + 500 chars)). Submission flow still uses the existing
`submit_optimized_params` tool contract.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jnzs1836
approved these changes
Jun 1, 2026
jnzs1836
marked this pull request as draft
June 9, 2026 02:19
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.
Summary
Three small, independent additions to the agentic optimization pipeline:
BaseAgenticOptimizer._invoke_agent— wraps the inner Strandsagent(...)call to record wall-clock time and accumulated metrics (tokens, cycles, tool calls, latency) ontoself.last_wall_clock_s/self.last_metrics. Lets callers read step cost/latency without subclassing.ContrastiveReflectionOptimizer._run_reflectionroutes through it.AgentCoreRolloutEngine.payload_mapper— the engine still builds the canonical{"data_sample": ..., "params": ...}payload. Newpayload_mapper: Callable[[dict], dict]init kwarg is a transform applied to that canonical dict before the HTTP call, so deployments expecting a different shape (flat fields, renamed keys, nested envelopes) can remap without subclassing the engine. Default isNone(identity), fully backward-compatible.New built-in templates at
harness_optimizer/templates/contrastive_reflection_v2/. Differences from v1:## Learned Behaviorsappendix; requires holistic integration of insights into the original prompt's existing structure.<= max(1.1 × original, original + 500 chars)).submit_optimized_paramstool contract.Test plan
pytest tests/rollout_engines/ tests/optimizers/passes locally (excludingtests/optimizers/test_multi_agent.py, which is broken onmainindependently of this PR — it importscontext_alchemy.datamodels).load_builtin_template("contrastive_reflection_v2/...")loads + renders both new templates.AgentCoreRolloutEngine(..., payload_mapper=fn)stores the mapper; default constructor leaves_payload_mapper = None.ContrastiveReflectionOptimizerexposeslast_metrics,last_wall_clock_s,_invoke_agent.🤖 Generated with Claude Code