Repository navigation
Expand file tree
/
Copy pathagents.py
More file actions
237 lines (227 loc) · 9.98 KB
/
Copy pathagents.py
File metadata and controls
237 lines (227 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import json
from collections.abc import Callable
from dataclasses import dataclass
from pydantic import BaseModel
from app.schemas import (
AgentInputs,
AutowebcompatDiagnosisInputs,
AutowebcompatInterventionInputs,
AutowebcompatReproInputs,
BugFixInputs,
BuildRepairInputs,
DatasetEvalInputs,
FrontendTriageInputs,
GeckoTriageInputs,
PerfTriageInputs,
TestPlanGeneratorInputs,
TestRepairFixInputs,
TestRepairInputs,
UpliftInputs,
)
# Shared run fields are not forwarded to the agent environment.
_PLATFORM_FIELDS = frozenset(AgentInputs.model_fields)
@dataclass(frozen=True)
class AgentSpec:
name: str
description: str
job_name: str
input_schema: type[BaseModel]
# Optional override for the rare agent whose env vars don't map 1:1 from
# its input schema. Defaults to ``model_to_env`` (field -> UPPER_SNAKE env).
build_env: Callable[[BaseModel], dict[str, str]] | None = None
# Whether this agent's recorded actions are applied AUTOMATICALLY when a run
# succeeds. Off by default: actions are still recorded and can always be
# applied manually from the UI; only opted-in agents auto-apply.
auto_apply_actions: bool = False
# Whether auto-apply additionally needs the run's own say-so: `findings.auto_apply`
# must be True, or the actions are recorded and held. Set this for agents that
# judge their results one run at a time, since only the agent knows how sure it
# was; this is where that verdict is honored. Fails closed, so a run that reports
# no verdict never qualifies.
auto_apply_requires_consent: bool = False
# Per-action overrides for the agent-level auto-apply policy.
always_apply_actions: frozenset[str] = frozenset()
never_apply_actions: frozenset[str] = frozenset()
# Whether a successful run is expected to deliver its result as recorded actions.
# When set, a run that records none, or leaves a patch without a patch action, is
# reported as an error. Agents that may legitimately finish without acting (or
# without Phabricator submission tools) must not set it.
expects_actions: bool = False
# How long an execution may run; the API-wide default when unset.
execution_timeout_seconds: int | None = None
# The one GitHub repository ("owner/repo") this agent's `github.submit_patch`
# actions may open pull requests on; unset, they are refused. It is set here,
# not taken from the run, because the run's artifact is agent-written. It must
# be the repository of the agent's `[source].repo_url`, since its commit is
# built on that checkout.
github_repository: str | None = None
def model_to_env(inputs: BaseModel) -> dict[str, str]:
"""Serialise validated inputs into Cloud Run Job env overrides.
Each schema field maps to an upper-cased env var (``bug_id`` -> ``BUG_ID``);
``None`` fields are skipped, and the agent reads them back via
``pydantic_settings.BaseSettings`` (which upper-cases field names by
default). Lists/dicts are JSON-encoded. Deploy-time constants (e.g. the
broker loopback URL) are NOT inputs — they belong in the Job's static env
config, not here. Shared run fields are skipped.
"""
env: dict[str, str] = {}
for name, value in inputs.model_dump(mode="json").items():
if value is None or name in _PLATFORM_FIELDS:
continue
if isinstance(value, str):
env[name.upper()] = value
elif isinstance(value, (list, dict)):
env[name.upper()] = json.dumps(value)
else:
env[name.upper()] = str(value)
return env
AGENT_REGISTRY: dict[str, AgentSpec] = {
"bug-fix": AgentSpec(
name="bug-fix",
description="Investigate a Bugzilla bug and produce a candidate fix patch against the Firefox source tree.",
job_name="hackbot-agent-bug-fix",
input_schema=BugFixInputs,
auto_apply_actions=True,
expects_actions=True,
),
"autowebcompat-repro": AgentSpec(
name="autowebcompat-repro",
description=(
"Reproduce a Firefox web-compatibility issue in headless Firefox "
"(from inline report text or a Bugzilla bug id) and return findings."
),
job_name="hackbot-agent-autowebcompat-repro",
input_schema=AutowebcompatReproInputs,
),
"autowebcompat-diagnosis": AgentSpec(
name="autowebcompat-diagnosis",
description=(
"Diagnose the root cause of a Firefox web-compatibility "
"issue by comparing Firefox and Chrome, and "
"produce a reduced HTML testcase."
),
job_name="hackbot-agent-autowebcompat-diagnosis",
input_schema=AutowebcompatDiagnosisInputs,
),
"build-repair": AgentSpec(
name="build-repair",
description="Analyze a Firefox build failure at a specific commit and produce a candidate fix patch.",
job_name="hackbot-agent-build-repair",
input_schema=BuildRepairInputs,
auto_apply_actions=False,
always_apply_actions=frozenset({"email.send"}),
),
"frontend-triage": AgentSpec(
name="frontend-triage",
description=(
"Triage a user-facing Firefox bug (read-only): desktop frontend, "
"Firefox for Android, the Windows installer, or the application "
"updater. Produce a root-cause analysis and proposed fix plan."
),
job_name="hackbot-agent-frontend-triage",
input_schema=FrontendTriageInputs,
# Triage results reach a real bug unattended, so only the ones the agent
# marked `auto_apply` qualify. Everything else stays for manual apply.
auto_apply_actions=True,
auto_apply_requires_consent=True,
# Except the Slack notification: for a held run it is the only signal that
# an analysis is waiting, so holding it with the comment hides the run.
always_apply_actions=frozenset({"slack.post_message"}),
),
"gecko-triage": AgentSpec(
name="gecko-triage",
description=(
"Triage a Gecko bug. Each team can add its own rules. With no "
"team, the run uses the shared rules for the bug's component. Inventory "
"what the report contains and read its "
"profiles and logs. Ask the reporter for what is missing, or set severity "
"and priority. Come back when the bug changes."
),
job_name="hackbot-agent-gecko-triage",
input_schema=GeckoTriageInputs,
# Human-gated while the agent is checked by hand: every run waits in the UI.
# Set `auto_apply_actions=True` to let vouched runs (`findings.auto_apply`)
# reach the bug with nobody in between.
auto_apply_actions=False,
auto_apply_requires_consent=True,
),
"perf-triage": AgentSpec(
name="perf-triage",
description=(
"Rate a Firefox performance bug with the Performance Impact "
"Calculator, analysing a linked profile, and set Performance Impact."
),
job_name="hackbot-agent-perf-triage",
input_schema=PerfTriageInputs,
# Writes cf_performance_impact unattended, but only for runs whose rating
# held under every value of the inputs the bug left open (findings.auto_apply).
auto_apply_actions=True,
auto_apply_requires_consent=True,
),
"test-repair": AgentSpec(
name="test-repair",
description=(
"Analyze a Firefox CI test failure: classify it as a regression or an "
"intermittent, blame the culprit commit, and propose a fix patch for "
"regressions."
),
job_name="hackbot-agent-test-repair",
input_schema=TestRepairInputs,
auto_apply_actions=False,
always_apply_actions=frozenset(
{"email.send", "slack.post_message", "agents.start_run"}
),
),
"test-repair-fix": AgentSpec(
name="test-repair-fix",
description=(
"Propose a patch for the regression a test-repair run blamed, for the "
"culprit's author to squash into their patch and reland."
),
job_name="hackbot-agent-test-repair-fix",
input_schema=TestRepairFixInputs,
auto_apply_actions=False,
always_apply_actions=frozenset({"email.send"}),
),
"test-plan-generator": AgentSpec(
name="test-plan-generator",
description=(
"Generate Firefox QA test cases from feature details (up to 20 test cases), "
"run them in Firefox through DevTools MCP, and report pass/fail/unsuitable results."
),
job_name="hackbot-agent-test-plan-generator",
input_schema=TestPlanGeneratorInputs,
),
"uplift-resolve": AgentSpec(
name="uplift-resolve",
description=(
"Resolve the merge conflicts from cherry-picking patches (git commits "
"and/or Phabricator revisions) onto a stable uplift branch, and return "
"the resolved patch with a confidence level for human review."
),
job_name="hackbot-agent-uplift-resolve",
input_schema=UpliftInputs,
),
"autowebcompat-intervention": AgentSpec(
name="autowebcompat-intervention",
description=(
"Write a Firefox webcompat intervention for a broken-site bug: "
"confirm the breakage reproduces, write the intervention and a "
"test, verify that it fixes the site, and submit a patch. Also "
"follows up on review comments on revisions it filed."
),
job_name="hackbot-agent-autowebcompat-intervention",
input_schema=AutowebcompatInterventionInputs,
auto_apply_actions=True,
),
"dataset-eval": AgentSpec(
name="dataset-eval",
description=(
"Run an agent over an eval dataset, grade every example, and log the "
"evaluation to Weave."
),
job_name="hackbot-agent-dataset-eval",
input_schema=DatasetEvalInputs,
execution_timeout_seconds=48 * 60 * 60,
),
}