Add LLM agent fallback for unmapped tracker patterns

When both pattern matching and domain matching fail to identify a
tracker, an opt-in LLM agent can now attempt identification using
internal database searches and optional web search. The agent returns
structured output (third party name, category, description, confidence)
and the worker auto-creates CommonThirdParty records when needed.

The feature is gated behind the `llm.tracker-mapping.provider` config
field; when unset the worker behaves exactly as before.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-15 15:57:06 +04:00
parent 80237eb39c
commit 0cc2b62cf2
9 changed files with 683 additions and 1 deletions

View File

@@ -179,6 +179,34 @@ LIMIT 1;
return &commonThirdPartyID, nil
}
func (dts *DetectedTrackers) LoadInitiatorDomainsByTrackerPatternID(
ctx context.Context,
conn pg.Querier,
trackerPatternID gid.GID,
) ([]string, error) {
q := `
SELECT DISTINCT initiator_domain
FROM detected_trackers
WHERE tracker_pattern_id = @tracker_pattern_id
AND initiator_domain IS NOT NULL
LIMIT 5;
`
args := pgx.StrictNamedArgs{"tracker_pattern_id": trackerPatternID}
rows, err := conn.Query(ctx, q, args)
if err != nil {
return nil, fmt.Errorf("cannot load initiator domains: %w", err)
}
domains, err := pgx.CollectRows(rows, pgx.RowTo[string])
if err != nil {
return nil, fmt.Errorf("cannot collect initiator domains: %w", err)
}
return domains, nil
}
func (dts *DetectedTrackers) RelinkByTrackerPatternID(
ctx context.Context,
tx pg.Tx,