Skip to content

fix(agents): make the sub-agent learning subsystem actually work#80

Merged
veerareddyvishal144 merged 2 commits into
mainfrom
fix/agent-learning-subsystem
Jul 2, 2026
Merged

fix(agents): make the sub-agent learning subsystem actually work#80
veerareddyvishal144 merged 2 commits into
mainfrom
fix/agent-learning-subsystem

Conversation

@vishalveerareddy123

Copy link
Copy Markdown
Collaborator

Summary

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, 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-manager: populate context.taskPrompt and an in-memory context.transcript, kept in sync inside recordToolCall (JSONL file remains the durable record).
  • reflector: fix error-recovery detection — it sliced the transcript by a millisecond timestamp instead of the entry's index, always yielding []; make _inferTaskType null-safe so reflection can never throw.
  • executor / parallel-coordinator / index: thread the definition loader through via constructor injection (no circular deps) so newly-learned skills re-inject into agent prompts live, not only after a restart. Injection rebuilds from the original prompt, so it stays idempotent (no duplicate skill blocks).
  • loader: add periodic pruning of proven-unhelpful skills (useCount >= 3 && confidence < 0.2) on a hardcoded 6h unref'd timer, started only when the agents subsystem is enabled.

Tests

Adds test/agent-learning.test.js (wired into test: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

vishal veerareddy and others added 2 commits July 1, 2026 18:08
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>
@veerareddyvishal144 veerareddyvishal144 merged commit 337447c into main Jul 2, 2026
1 check passed
@veerareddyvishal144 veerareddyvishal144 deleted the fix/agent-learning-subsystem branch July 2, 2026 01:31
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.

2 participants