Give each tracker agent its own config
The tracker-mapping, common-pattern enrichment, and third-party disambiguation agents were all built from one shared TrackerAgentsConfig fed by a single tracker-mapping config slot. That forced a single AgentTimeout to be reused and patched per worker, and two unrelated max-turns fields to share one struct. Split the in-code config into TrackerMappingAgentConfig, TrackerEnrichmentAgentConfig, and DisambiguationAgentConfig, each with its own timeout and max-turns, and add dedicated tracker-enrichment and third-party-disambiguation provider slots (the latter resolving next to third-party-vetter). Enrichment and disambiguation fall back to the tracker-mapping slot when their own provider is unset, preserving single-config deployments. Drop the shared pkg/agentsbuild package and duplicate its small wiring into probod and proboctl so the two executables stay decoupled. Wire the new env vars, builder test coverage, and Helm values. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -39,35 +39,49 @@ import (
|
||||
// known set of ids (e.g. proboctl). It is enrichment's single source of
|
||||
// truth - the worker is a thin queue poller that delegates here.
|
||||
type CommonPatternEnricher struct {
|
||||
pg *pg.Client
|
||||
logger *log.Logger
|
||||
enrichmentAgent *agent.Agent
|
||||
mappingAgent *agent.Agent
|
||||
agentTimeout time.Duration
|
||||
pg *pg.Client
|
||||
logger *log.Logger
|
||||
enrichmentAgent *agent.Agent
|
||||
mappingAgent *agent.Agent
|
||||
enrichmentTimeout time.Duration
|
||||
mappingTimeout time.Duration
|
||||
}
|
||||
|
||||
// NewCommonPatternEnricher builds the enricher from the shared tracker
|
||||
// agents config. When no LLM client is configured the agents are left nil
|
||||
// and Enabled reports false; callers must gate on Enabled before running.
|
||||
// NewCommonPatternEnricher builds the enricher from the enrichment and
|
||||
// mapping agent configs. It runs the enrichment agent to research a
|
||||
// description and reuses the mapping agent to attribute a vendor first,
|
||||
// so it needs both configs. When the enrichment config has no LLM client
|
||||
// the agents are left nil and Enabled reports false; callers must gate on
|
||||
// Enabled before running.
|
||||
func NewCommonPatternEnricher(
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
cfg TrackerAgentsConfig,
|
||||
enrichmentCfg TrackerEnrichmentAgentConfig,
|
||||
mappingCfg TrackerMappingAgentConfig,
|
||||
) *CommonPatternEnricher {
|
||||
agentTimeout := cfg.AgentTimeout
|
||||
if agentTimeout <= 0 {
|
||||
agentTimeout = defaultAgentTimeout
|
||||
enrichmentTimeout := enrichmentCfg.Timeout
|
||||
if enrichmentTimeout <= 0 {
|
||||
enrichmentTimeout = defaultAgentTimeout
|
||||
}
|
||||
|
||||
mappingTimeout := mappingCfg.Timeout
|
||||
if mappingTimeout <= 0 {
|
||||
mappingTimeout = defaultAgentTimeout
|
||||
}
|
||||
|
||||
e := &CommonPatternEnricher{
|
||||
pg: pgClient,
|
||||
logger: logger,
|
||||
agentTimeout: agentTimeout,
|
||||
pg: pgClient,
|
||||
logger: logger,
|
||||
enrichmentTimeout: enrichmentTimeout,
|
||||
mappingTimeout: mappingTimeout,
|
||||
}
|
||||
|
||||
if cfg.LLMClient != nil {
|
||||
e.enrichmentAgent = buildCommonPatternEnrichmentAgent(cfg, pgClient, logger)
|
||||
e.mappingAgent = buildTrackerMappingAgent(cfg, pgClient, logger)
|
||||
if enrichmentCfg.LLMClient != nil {
|
||||
e.enrichmentAgent = buildCommonPatternEnrichmentAgent(enrichmentCfg, pgClient, logger)
|
||||
}
|
||||
|
||||
if mappingCfg.LLMClient != nil {
|
||||
e.mappingAgent = buildTrackerMappingAgent(mappingCfg, pgClient, logger)
|
||||
}
|
||||
|
||||
return e
|
||||
@@ -251,7 +265,7 @@ func (e *CommonPatternEnricher) research(
|
||||
) (string, error) {
|
||||
prompt := buildEnrichmentPrompt(cp, thirdPartyName)
|
||||
|
||||
agentCtx, cancel := context.WithTimeout(ctx, e.agentTimeout)
|
||||
agentCtx, cancel := context.WithTimeout(ctx, e.enrichmentTimeout)
|
||||
defer cancel()
|
||||
|
||||
result, err := agent.RunTyped[CommonPatternEnrichmentResult](
|
||||
@@ -287,7 +301,7 @@ func (e *CommonPatternEnricher) identifyThirdParty(
|
||||
|
||||
prompt := buildCommonPatternIdentificationPrompt(cp)
|
||||
|
||||
agentCtx, cancel := context.WithTimeout(ctx, e.agentTimeout)
|
||||
agentCtx, cancel := context.WithTimeout(ctx, e.mappingTimeout)
|
||||
defer cancel()
|
||||
|
||||
result, err := agent.RunTyped[TrackerMappingAgentResult](
|
||||
|
||||
@@ -36,7 +36,7 @@ type CommonPatternEnrichmentResult struct {
|
||||
}
|
||||
|
||||
func buildCommonPatternEnrichmentAgent(
|
||||
cfg TrackerAgentsConfig,
|
||||
cfg TrackerEnrichmentAgentConfig,
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
) *agent.Agent {
|
||||
@@ -53,7 +53,7 @@ func buildCommonPatternEnrichmentAgent(
|
||||
panic(fmt.Sprintf("cookiebanner: cannot build tracker enrichment output type: %s", err))
|
||||
}
|
||||
|
||||
maxTurns := cfg.EnrichmentMaxTurns
|
||||
maxTurns := cfg.MaxTurns
|
||||
if maxTurns < 1 {
|
||||
maxTurns = defaultEnrichmentMaxTurns
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ type commonPatternEnrichmentHandler struct {
|
||||
func NewCommonPatternEnrichmentWorker(
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
cfg TrackerAgentsConfig,
|
||||
enrichmentCfg TrackerEnrichmentAgentConfig,
|
||||
mappingCfg TrackerMappingAgentConfig,
|
||||
staleAfter time.Duration,
|
||||
opts ...worker.Option,
|
||||
) *worker.Worker[coredata.CommonTrackerPattern] {
|
||||
@@ -60,7 +61,7 @@ func NewCommonPatternEnrichmentWorker(
|
||||
h := &commonPatternEnrichmentHandler{
|
||||
pg: pgClient,
|
||||
logger: logger,
|
||||
enricher: NewCommonPatternEnricher(pgClient, logger, cfg),
|
||||
enricher: NewCommonPatternEnricher(pgClient, logger, enrichmentCfg, mappingCfg),
|
||||
staleAfter: staleAfter,
|
||||
}
|
||||
|
||||
|
||||
@@ -20,23 +20,38 @@ import (
|
||||
"go.probo.inc/probo/pkg/llm"
|
||||
)
|
||||
|
||||
// TrackerAgentsConfig configures the tracker agents that share one LLM
|
||||
// client, model, and tool surface: the tracker-mapping agent (catalog
|
||||
// identification) and the common-pattern enrichment agent (description
|
||||
// research). Both use DB-backed search tools and may also use Firecrawl
|
||||
// for web search when an API key is supplied.
|
||||
// TrackerMappingAgentConfig configures the tracker-mapping agent
|
||||
// (catalog identification). It uses DB-backed search tools and may also
|
||||
// use Firecrawl for web search when an API key is supplied.
|
||||
//
|
||||
// MaxTokens and Temperature bound and steer each LLM call (both
|
||||
// outputs are tiny structured JSON). AgentTimeout caps a single agent
|
||||
// run, and the per-worker max-turns bound the agent reasoning loop.
|
||||
// Zero-valued tuning fields fall back to package defaults.
|
||||
type TrackerAgentsConfig struct {
|
||||
LLMClient *llm.Client
|
||||
Model string
|
||||
FirecrawlAPIKey string
|
||||
MaxTokens *int
|
||||
Temperature *float64
|
||||
AgentTimeout time.Duration
|
||||
MappingMaxTurns int
|
||||
EnrichmentMaxTurns int
|
||||
// MaxTokens and Temperature bound and steer the LLM call (the output is
|
||||
// tiny structured JSON). Timeout caps a single agent run and MaxTurns
|
||||
// bounds the agent reasoning loop. Zero-valued tuning fields fall back
|
||||
// to package defaults.
|
||||
type TrackerMappingAgentConfig struct {
|
||||
LLMClient *llm.Client
|
||||
Model string
|
||||
FirecrawlAPIKey string
|
||||
MaxTokens *int
|
||||
Temperature *float64
|
||||
Timeout time.Duration
|
||||
MaxTurns int
|
||||
}
|
||||
|
||||
// TrackerEnrichmentAgentConfig configures the common-pattern enrichment
|
||||
// agent (description research). It uses DB-backed search tools and may
|
||||
// also use Firecrawl for web search when an API key is supplied.
|
||||
//
|
||||
// MaxTokens and Temperature bound and steer the LLM call (the output is
|
||||
// tiny structured JSON). Timeout caps a single agent run and MaxTurns
|
||||
// bounds the agent reasoning loop. Zero-valued tuning fields fall back
|
||||
// to package defaults.
|
||||
type TrackerEnrichmentAgentConfig struct {
|
||||
LLMClient *llm.Client
|
||||
Model string
|
||||
FirecrawlAPIKey string
|
||||
MaxTokens *int
|
||||
Temperature *float64
|
||||
Timeout time.Duration
|
||||
MaxTurns int
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ type TrackerMappingAgentResult struct {
|
||||
}
|
||||
|
||||
func buildTrackerMappingAgent(
|
||||
cfg TrackerAgentsConfig,
|
||||
cfg TrackerMappingAgentConfig,
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
) *agent.Agent {
|
||||
@@ -94,7 +94,7 @@ func buildTrackerMappingAgent(
|
||||
panic(fmt.Sprintf("cookiebanner: cannot build tracker identification output type: %s", err))
|
||||
}
|
||||
|
||||
maxTurns := cfg.MappingMaxTurns
|
||||
maxTurns := cfg.MaxTurns
|
||||
if maxTurns < 1 {
|
||||
maxTurns = defaultMappingMaxTurns
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ type trackerMappingHandler struct {
|
||||
func NewTrackerMappingWorker(
|
||||
pgClient *pg.Client,
|
||||
logger *log.Logger,
|
||||
mappingCfg TrackerAgentsConfig,
|
||||
disambiguationCfg thirdparty.DisambiguationConfig,
|
||||
mappingCfg TrackerMappingAgentConfig,
|
||||
disambiguationCfg thirdparty.DisambiguationAgentConfig,
|
||||
staleAfter time.Duration,
|
||||
opts ...worker.Option,
|
||||
) *worker.Worker[coredata.TrackerPattern] {
|
||||
agentTimeout := mappingCfg.AgentTimeout
|
||||
agentTimeout := mappingCfg.Timeout
|
||||
if agentTimeout <= 0 {
|
||||
agentTimeout = defaultAgentTimeout
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user