Commit Graph

1 Commits

Author SHA1 Message Date
Dragan Spiridonov 79c9a99f9c fix(hooks): use bridge.agent as action_key in Q-learning when --agent is unavailable (#460)
The post-task hook command passes `--agent "$TOOL_RESULT_agent_id"`, but
Claude Code does not expose that env var in PostToolUse context — so
`options.agent` arrives empty, the local `agent` falls back to 'unknown',
and every rl_q_values row used `action_key='unknown'`. The Q-learning
router could never learn per-agent differentiation.

The pre-task bridge payload already carries
`agent: routing.recommendedAgent`, which is the right action key. Compute
an `effectiveAgent` after persistTaskOutcome returns: prefer an explicit
--agent value (user override), otherwise fall back to bridge.agent, and
only land on 'unknown' when neither is available. Use it for both
`updateHookRouterQValue` and `updateRoutingOutcomeQuality` (the latter
uses agent as a tiebreaker in the routing-outcome sentinel match, so it
benefits from the same correction).

4 regression tests cover: bridge fallback when --agent absent, bridge
fallback for explicit empty --agent, explicit user override wins, and
falls through to 'unknown' when neither source is available.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 11:16:05 +00:00