Extract agent and tools from tracker mapping worker into dedicated files

Split tracker_mapping_worker.go: agent construction, prompts, and
structured output type move to tracker_mapping_agent.go; each tool gets
its own *_tool.go file. Update naming conventions (worker, agent, tool
file patterns, AgentResult suffix, RunTyped preference).

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-19 12:06:15 +04:00
parent 10adf2bd4b
commit c4147e6801
7 changed files with 256 additions and 174 deletions

View File

@@ -24,7 +24,17 @@ result.FinalMessage().Text() // final output
result.LastAgent // agent that produced the result
```
Typed output via `RunTyped[T](ctx, agent, messages)` — validates against JSON Schema.
Prefer `RunTyped[T]` over `Run` + manual unmarshalling when the agent declares a
structured output type via `WithOutputType`. `RunTyped` validates the response
against the JSON Schema and returns the typed value directly:
```go
result, err := agent.RunTyped[TrackerIdentification](ctx, ag, messages)
identification := result.Output // already typed, no json.Unmarshal needed
```
Only fall back to `agent.Run` when the agent produces free-form text with no
output schema.
## Tool interface

View File

@@ -27,3 +27,40 @@ Use one of: {{.Categories}}.
For single-placeholder templates, `strings.Replace` is sufficient. For multiple
placeholders, use `text/template`.
## Worker files
Background worker files use the `<name>_worker.go` naming pattern. The file
contains the handler struct, `NewXxxWorker` constructor, and the `Claim`/`Process`
methods. Keep domain-specific helper methods (match, resolve, etc.) in the same
file.
```
pkg/cookiebanner/tracker_mapping_worker.go
pkg/cookiebanner/pattern_analysis_worker.go
```
## Agent files
When a package has a worker that uses an agent, the agent construction logic
goes in `<worker_prefix>_agent.go` alongside `<worker_prefix>_worker.go`. The
worker file stays focused on `Claim`/`Process` and handler methods; the agent
file owns agent construction, prompt building, constants, config, and the
`//go:embed` directive for prompt templates.
```
pkg/cookiebanner/tracker_mapping_worker.go -- worker handler
pkg/cookiebanner/tracker_mapping_agent.go -- agent construction + prompts
```
## Tool files
Each agent tool lives in its own `<tool_name>_tool.go` file, named after the
tool constructor function (without the `Tool` suffix). The file contains the
constructor function plus its param/result types. Avoid grouping multiple tools
in a single file.
```
pkg/cookiebanner/search_tracker_patterns_tool.go -- searchTrackerPatternsTool
pkg/cookiebanner/search_third_parties_tool.go -- searchThirdPartiesTool
```