Commit 26bc5ca
feat(adk): background-task manager with subagent/filesystem/deep wiring (#1107)
* feat(adk): background-task manager with subagent/filesystem/deep wiring
Introduce a shared, domain-agnostic background-task engine and wire it into the
subagent and filesystem middlewares and the deep prebuilt agent.
adk/backgroundtask (engine):
- Manager tracks foreground/background/auto-background runs under one task-ID
space; Run blocks with an optional foreground budget, then either completes,
auto-backgrounds (Config.ShouldAutoBackground), or times out.
- RunStream + StreamWorkFunc forward a run's output to the caller in real time
during the foreground phase, then on auto-background inject a generic notice
and drain the rest into the task result.
- Cancellation records a reason on Task.Error and the foreground caller reports
StatusCanceled (not a StatusFailed ctx error).
- Task ids are TaskType_base62(int64), where the int64 packs a ms timestamp, a
per-ms sequence (spinning to the next ms on overflow), and random low bits —
unique within a process and self-describing by type.
- Optional OutputStore persists completed results (filesystem.Backend satisfies
it directly); WaitForTask/WaitAllDone for lifecycle waits.
adk/middlewares/backgroundtask (control tools):
- Injects task_output/task_stop once, bound to a Config{Manager}. task_output
supports CC-aligned block/timeout inputs.
adk/middlewares/subagent + filesystem:
- subagent agent tool and filesystem execute tool route through a shared Manager
when configured, gaining run_in_background; the streaming execute tool streams
its foreground output via RunStream. filesystem.Shell now documents the
ctx-cancellation contract.
adk/prebuilt/deep:
- deep.New accepts a Manager, wiring it into the top-level subagent + filesystem
middlewares and injecting the control tools once; sub-agents stay
foreground-only. Replaces the old task_tool with the subagent middleware.
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
* feat: adjust background.Manager
* refactor(adk): clarify background task events
* feat: simplify done check
* feat: reduce one goroutine for direct run_in_background
* refactor: enchance background task with direct run_in_background
* refactor(adk): make background task output file worker-owned
The background-task Manager previously declared an output file globally and
wrote it once at completion, which broke its "interim output" promise and made
the file redundant with Task.Result. Move output-file ownership to the launching
adapters (execute / agent tools): the Manager only records RunInput.OutputFile,
while the worker writes — shell runs tee interim output as it streams, sub-agent
runs append their final result.
- backgroundtask: drop Config.OutputStore/OutputDir and persistOutput; add
RunInput.OutputFile (path only, Manager never writes)
- filesystem: add Appender optional interface + AppendRequest (InMemoryBackend
implements it); output files require an Appender, no rewrite fallback
- bundle Manager + output config into a nested BackgroundConfig across the
filesystem, subagent, and deep configs
- name output files after the launching tool-call id (matching Task.ToolUseID),
with a uuid fallback when absent
- task_output's formatTask points at the file when present instead of inlining
the result
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
* feat: support mark output file
* fix: golangci-lint
* refactor(adk): hand WorkFunc a TaskInfo and key output-file failures by id
The launcher needs the Manager-assigned task id at write time to report an
output-file write failure, but the id is generated inside createTask, after the
work closure is already built. Pass a TaskInfo (read-only snapshot of
creation-time identity) as an explicit WorkFunc/StreamWorkFunc parameter so the
work receives the id directly; MarkOutputFileUnreliable then keys by id (O(1)
map lookup) instead of scanning all tasks by output-file path.
Also make the failed-write reporting honest: when a write fails, neither the
partial file nor the in-memory Result is the authoritative complete output
(Result may be empty while the task runs, or a partial projection of the file
for sub-agent runs). formatTask and the OutputFileErr doc no longer claim Result
is always the full copy.
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4 <noreply@anthropic.com>1 parent a77de0d commit 26bc5ca
25 files changed
Lines changed: 5507 additions & 766 deletions
File tree
- adk
- backgroundtask
- filesystem
- middlewares
- backgroundtask
- filesystem
- subagent
- prebuilt/deep
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 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 | + | |
0 commit comments