adk_compat
zocrates.agents.common.adk_compat ¶
Compatibility patches for Google ADK runtime and workflow execution.
_adk_active_task_scope_rewind_patched
module-attribute
¶
_adk_request_input_context_filter_patched
module-attribute
¶
_compaction_subagent_isolation_patched
module-attribute
¶
_has_compaction_for_active_turn ¶
Check if a compaction event has already been recorded for the currently active turn.
Source code in zocrates/agents/common/adk_compat.py
patch_adk_active_task_scope_rewind ¶
Patch ADK _find_active_task_scope to filter out rewound events before checking active scopes.
When an in-flight subagent pipeline (which stamps events with an isolation_scope, e.g. 'search_library_pipeline:xyz' or 'search_online_pipeline:xyz') is rewound via rewind_before_invocation_id, its unfinished isolation scope remains in session.events. ADK's native _find_active_task_scope walks session.events directly without taking rewinds into account, causing subsequent user turns to mistakenly be stamped with the dead subagent's isolation scope.
This patch ensures _find_active_task_scope evaluates active task scopes against the live events filtered by _apply_rewinds(session.events).
Source code in zocrates/agents/common/adk_compat.py
patch_adk_request_input_context_filter ¶
Patch ADK contents filter to exclude adk_request_input function calls/responses from agent LLM context.
In dynamic workflows with Human-In-The-Loop (HITL), RequestInput emits an Event
with a function call named 'adk_request_input' and the user resume response emits
a function response named 'adk_request_input'. While ADK natively filters out
internal framework events like 'adk_framework' and 'adk_request_credential' from
being included in an agent's LLM context, it omits 'adk_request_input'. This causes
ADK's _fencing module to wrap the checkpoint call and response in cross-agent
fencing (<<
This patch ensures 'adk_request_input' events are filtered out from LLM context generation, preserving clean continuation prompts for subagents.
Source code in zocrates/agents/common/adk_compat.py
patch_compaction_subagent_isolation ¶
Ensure token compaction only executes for the root coordinator agent, never for subagents, and eliminate duplicate post-invocation compaction runs.
In multi-agent systems, subagents (e.g. library_search_agent, online_search_agent) execute inside isolated pipelines. If token-threshold compaction runs inside subagents, it mistakenly compacts the parent session's history before every internal tool call, causing massive latency overhead and redundant compaction cycles.
Additionally, Google ADK 2.8.0 contains an upstream context propagation bug where
BaseAgent._create_invocation_context performs a shallow model_copy() of InvocationContext,
causing token_compaction_checked = True to only be set on the child context and never reaching
the root context in runners.py. This causes runners.py to pass skip_token_compaction=False to
_run_post_invocation_compaction, triggering a second, completely redundant compaction cycle.
This patch links parent contexts and guards _run_compaction_for_token_threshold so compaction
never executes more than once per turn.
Source code in zocrates/agents/common/adk_compat.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |