fix(agents): make the sub-agent learning subsystem actually work#80
Merged
Conversation
The Reflector → Skillbook → prompt-injection loop was fully built but dead: the Reflector read `context.transcript` and `context.taskPrompt`, neither of which the context manager ever set. Reflection threw on every non-trivial run and the error was silently swallowed as "Learning failed", so no skills were ever persisted or injected. - context-manager: populate `context.taskPrompt` and an in-memory `context.transcript`, kept in sync in `recordToolCall`. - reflector: fix error-recovery detection (sliced by a ms timestamp instead of the entry's index, always yielding []); make `_inferTaskType` null-safe so reflection can never throw. - executor/coordinator/index: thread the definition loader through so newly learned skills re-inject into agent prompts live (not only after restart); loader injection rebuilds from the original prompt, so it stays idempotent. - loader: add periodic pruning of proven-unhelpful skills on a hardcoded 6h unref'd timer (only when agents are enabled). - add test/agent-learning.test.js covering the full loop and pruning. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
toAnthropicResponse() built the response `model` from the client request (falling back to a hardcoded default) and never looked at the provider's actual model, so tool-call responses reported a stale/aliased model. Usage also silently zeroed when the provider used input_tokens/output_tokens naming, and the prompt-cache-hit path returned without _routingMeta so downstream model-name resolution couldn't correct it. - model: prefer openai.model, fall back to requestedModel (mirrors the direct non-tool path `databricksResponse.json.model || requestedModel`). - usage: accept both prompt_tokens/completion_tokens and input_tokens/output_tokens shapes. - attach _routingMeta on the cache-hit return path, matching the live loop. - export toAnthropicResponse and add test/tool-call-response-metadata.test.js. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
The Reflector → Skillbook → prompt-injection loop was fully built but dead. The
Reflectorreadcontext.transcriptandcontext.taskPrompt, neither of which the context manager ever set, so reflection threw on every non-trivial run and the error was silently swallowed as "Learning failed" — no skills were ever persisted or injected.This wires the loop up end to end and adds the missing self-maintenance.
Changes
context.taskPromptand an in-memorycontext.transcript, kept in sync insiderecordToolCall(JSONL file remains the durable record).[]; make_inferTaskTypenull-safe so reflection can never throw.useCount >= 3 && confidence < 0.2) on a hardcoded 6hunref'd timer, started only when the agents subsystem is enabled.Tests
Adds
test/agent-learning.test.js(wired intotest:unit) covering: context field population, transcript mirroring, Reflector pattern extraction, the recovery-index fix, null-prompt safety, skillbook formatting, live idempotent re-injection, and pruning (proven-bad removed, fresh/good kept; timer idempotency + clean stop; non-positive interval disabled).All 11 new tests pass; neighboring suites (tier-fallback, telemetry-routing) remain green.
🤖 Generated with Claude Code