coder-agent 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coder_agent-0.1.0.dist-info/METADATA +262 -0
- coder_agent-0.1.0.dist-info/RECORD +163 -0
- coder_agent-0.1.0.dist-info/WHEEL +5 -0
- coder_agent-0.1.0.dist-info/entry_points.txt +2 -0
- coder_agent-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- coder_agent-0.1.0.dist-info/top_level.txt +1 -0
- coderagent/__init__.py +20 -0
- coderagent/compat/__init__.py +27 -0
- coderagent/compat/cache_control.py +69 -0
- coderagent/compat/config_spec.py +60 -0
- coderagent/compat/exceptions.py +20 -0
- coderagent/compat/retry.py +27 -0
- coderagent/compat/serialize.py +31 -0
- coderagent/config/__init__.py +1 -0
- coderagent/config/defaults.yaml +103 -0
- coderagent/config/loader.py +264 -0
- coderagent/config/schema.py +548 -0
- coderagent/config/writer.py +218 -0
- coderagent/core/__init__.py +1 -0
- coderagent/core/budget.py +47 -0
- coderagent/core/capabilities.py +136 -0
- coderagent/core/checkpoint.py +164 -0
- coderagent/core/content.py +156 -0
- coderagent/core/context.py +618 -0
- coderagent/core/events.py +83 -0
- coderagent/core/history.py +56 -0
- coderagent/core/instructions.py +99 -0
- coderagent/core/loop.py +702 -0
- coderagent/core/memory.py +56 -0
- coderagent/core/mentions.py +81 -0
- coderagent/core/os_sandbox.py +191 -0
- coderagent/core/otel.py +214 -0
- coderagent/core/protocols.py +38 -0
- coderagent/core/redact.py +49 -0
- coderagent/core/sandbox.py +82 -0
- coderagent/core/schema.py +107 -0
- coderagent/core/session.py +344 -0
- coderagent/core/shell_env.py +74 -0
- coderagent/core/subagent.py +474 -0
- coderagent/core/summarize.py +312 -0
- coderagent/core/telemetry.py +209 -0
- coderagent/core/tokens.py +132 -0
- coderagent/core/trust.py +301 -0
- coderagent/environments/__init__.py +11 -0
- coderagent/environments/bubblewrap.py +150 -0
- coderagent/environments/contree.py +146 -0
- coderagent/environments/docker.py +160 -0
- coderagent/environments/local.py +110 -0
- coderagent/environments/singularity.py +138 -0
- coderagent/environments/swerex_docker.py +79 -0
- coderagent/environments/swerex_modal.py +123 -0
- coderagent/eval/__init__.py +1 -0
- coderagent/eval/compare.py +190 -0
- coderagent/eval/report.py +141 -0
- coderagent/eval/runner.py +368 -0
- coderagent/eval/task.py +194 -0
- coderagent/extensions/__init__.py +1 -0
- coderagent/extensions/hooks.py +121 -0
- coderagent/extensions/plugins.py +217 -0
- coderagent/extensions/reflect.py +342 -0
- coderagent/models/__init__.py +33 -0
- coderagent/models/backends.py +218 -0
- coderagent/models/call.py +18 -0
- coderagent/models/check.py +139 -0
- coderagent/models/gateway.py +60 -0
- coderagent/models/litellm_config.py +70 -0
- coderagent/models/provider.py +98 -0
- coderagent/models/reasoning.py +28 -0
- coderagent/models/router.py +136 -0
- coderagent/models/settings.py +172 -0
- coderagent/models/streaming.py +122 -0
- coderagent/models/verbosity.py +14 -0
- coderagent/paths.py +31 -0
- coderagent/run.py +454 -0
- coderagent/skills/__init__.py +119 -0
- coderagent/skills/errors.py +11 -0
- coderagent/skills/install.py +340 -0
- coderagent/skills/presets/code-review/SKILL.md +35 -0
- coderagent/skills/presets/codebase-onboarding/SKILL.md +33 -0
- coderagent/skills/presets/data-analysis/SKILL.md +35 -0
- coderagent/skills/presets/deep-research/SKILL.md +38 -0
- coderagent/skills/presets/frontend-dev/SKILL.md +32 -0
- coderagent/skills/presets/long-document/SKILL.md +37 -0
- coderagent/skills/presets/long-document/scripts/pdf_text.py +37 -0
- coderagent/skills/presets/office-docx/SKILL.md +36 -0
- coderagent/skills/presets/office-docx/scripts/docx_text.py +36 -0
- coderagent/skills/presets/office-pptx/SKILL.md +32 -0
- coderagent/skills/presets/office-xlsx/SKILL.md +34 -0
- coderagent/skills/presets/office-xlsx/scripts/xlsx_text.py +72 -0
- coderagent/skills/presets/writing/SKILL.md +31 -0
- coderagent/skills/sandbox.py +269 -0
- coderagent/skills/sites.py +177 -0
- coderagent/skills/source.py +404 -0
- coderagent/testing/__init__.py +5 -0
- coderagent/testing/factory.py +59 -0
- coderagent/testing/scripted_model.py +54 -0
- coderagent/tools/__init__.py +1 -0
- coderagent/tools/base.py +54 -0
- coderagent/tools/bash_policy.py +486 -0
- coderagent/tools/builtin/__init__.py +35 -0
- coderagent/tools/builtin/fs.py +283 -0
- coderagent/tools/builtin/patch.py +279 -0
- coderagent/tools/builtin/search.py +242 -0
- coderagent/tools/builtin/shell.py +336 -0
- coderagent/tools/builtin/skill.py +41 -0
- coderagent/tools/builtin/task.py +53 -0
- coderagent/tools/builtin/todo.py +63 -0
- coderagent/tools/executor.py +243 -0
- coderagent/tools/mcp.py +317 -0
- coderagent/tools/permissions.py +472 -0
- coderagent/tools/registry.py +83 -0
- coderagent/tools/rules.py +138 -0
- coderagent/ui/__init__.py +1 -0
- coderagent/ui/cli.py +498 -0
- coderagent/ui/commands/__init__.py +109 -0
- coderagent/ui/commands/builtin.py +778 -0
- coderagent/ui/commands/compact.py +12 -0
- coderagent/ui/commands/resume.py +26 -0
- coderagent/ui/commands/review.py +73 -0
- coderagent/ui/commands/rewind.py +28 -0
- coderagent/ui/custom_commands.py +179 -0
- coderagent/ui/notify.py +46 -0
- coderagent/ui/open_file.py +48 -0
- coderagent/ui/render.py +62 -0
- coderagent/ui/spinner.py +68 -0
- coderagent/ui/tui.py +610 -0
- coderagent/ui/widgets/__init__.py +29 -0
- coderagent/ui/widgets/approval_prompt.py +129 -0
- coderagent/ui/widgets/diff_view.py +97 -0
- coderagent/ui/widgets/file_tree.py +105 -0
- coderagent/ui/widgets/markdown_message.py +44 -0
- coderagent/ui/widgets/markup.py +10 -0
- coderagent/ui/widgets/message_block.py +61 -0
- coderagent/ui/widgets/path_suggester.py +66 -0
- coderagent/ui/widgets/session_picker.py +49 -0
- coderagent/ui/widgets/status_bar.py +44 -0
- coderagent/ui/widgets/todo_panel.py +40 -0
- coderagent/ui/widgets/tool_card.py +104 -0
- coderagent/ui/widgets/working_dots.py +26 -0
- coderagent/version.py +7 -0
- coderagent/web/__init__.py +5 -0
- coderagent/web/api.py +449 -0
- coderagent/web/app.py +113 -0
- coderagent/web/approver.py +73 -0
- coderagent/web/config_api.py +53 -0
- coderagent/web/events.py +159 -0
- coderagent/web/files.py +115 -0
- coderagent/web/i18n.py +346 -0
- coderagent/web/server.py +100 -0
- coderagent/web/sessions.py +404 -0
- coderagent/web/skills_api.py +376 -0
- coderagent/web/static/app.css +283 -0
- coderagent/web/static/app.js +1466 -0
- coderagent/web/templates/en/base.html +31 -0
- coderagent/web/templates/en/chat.html +60 -0
- coderagent/web/templates/en/macros.html +9 -0
- coderagent/web/templates/en/settings.html +80 -0
- coderagent/web/templates/en/skills.html +64 -0
- coderagent/web/templates/zh/base.html +31 -0
- coderagent/web/templates/zh/chat.html +60 -0
- coderagent/web/templates/zh/macros.html +9 -0
- coderagent/web/templates/zh/settings.html +77 -0
- coderagent/web/templates/zh/skills.html +61 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""The comparison of two eval reports: did the change of the harness make the agent worse?
|
|
2
|
+
|
|
3
|
+
Two runs of the same suite are only comparable when they ran the same tasks. The
|
|
4
|
+
comparison therefore looks at the tasks that both runs have, and it says what
|
|
5
|
+
changed: a task that used to pass and does not pass any more is a regression.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Comparison:
|
|
14
|
+
before_label: str
|
|
15
|
+
after_label: str
|
|
16
|
+
before_fingerprint: str
|
|
17
|
+
after_fingerprint: str
|
|
18
|
+
compared: list[str] = field(default_factory=list)
|
|
19
|
+
"""The tasks both runs have."""
|
|
20
|
+
graded: list[str] = field(default_factory=list)
|
|
21
|
+
"""The tasks of both runs that are a rate, the guards excluded."""
|
|
22
|
+
regressions: list[str] = field(default_factory=list)
|
|
23
|
+
"""The tasks that passed before and do not pass any more."""
|
|
24
|
+
improvements: list[str] = field(default_factory=list)
|
|
25
|
+
"""The tasks that did not pass before and pass now."""
|
|
26
|
+
only_before: list[str] = field(default_factory=list)
|
|
27
|
+
only_after: list[str] = field(default_factory=list)
|
|
28
|
+
before_pass_rate: float = 0.0
|
|
29
|
+
after_pass_rate: float = 0.0
|
|
30
|
+
before_summary: dict[str, Any] = field(default_factory=dict)
|
|
31
|
+
after_summary: dict[str, Any] = field(default_factory=dict)
|
|
32
|
+
unexpected: list[str] = field(default_factory=list)
|
|
33
|
+
"""The tasks of the second run that did not do what they were supposed to do."""
|
|
34
|
+
broken_guards: list[str] = field(default_factory=list)
|
|
35
|
+
"""The guards that let a task through: their check was supposed to fail."""
|
|
36
|
+
ungraded: list[str] = field(default_factory=list)
|
|
37
|
+
"""The tasks the harness could not grade."""
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def config_changed(self) -> bool:
|
|
41
|
+
"""Whether the two runs ran a different configuration."""
|
|
42
|
+
return self.before_fingerprint != self.after_fingerprint
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def drop(self) -> float:
|
|
46
|
+
"""How much the pass rate fell."""
|
|
47
|
+
return round(self.before_pass_rate - self.after_pass_rate, 4)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def compare(before: dict[str, Any], after: dict[str, Any]) -> Comparison:
|
|
51
|
+
"""The comparison of two reports."""
|
|
52
|
+
old = {task["id"]: task for task in before.get("tasks") or []}
|
|
53
|
+
new = {task["id"]: task for task in after.get("tasks") or []}
|
|
54
|
+
comparison = Comparison(
|
|
55
|
+
before_label=str(before.get("label") or ""),
|
|
56
|
+
after_label=str(after.get("label") or ""),
|
|
57
|
+
before_fingerprint=str(before.get("fingerprint") or ""),
|
|
58
|
+
after_fingerprint=str(after.get("fingerprint") or ""),
|
|
59
|
+
before_summary=dict(before.get("summary") or {}),
|
|
60
|
+
after_summary=dict(after.get("summary") or {}),
|
|
61
|
+
)
|
|
62
|
+
for task_id in sorted(set(old) | set(new)):
|
|
63
|
+
if task_id not in new:
|
|
64
|
+
comparison.only_before.append(task_id)
|
|
65
|
+
elif task_id not in old:
|
|
66
|
+
comparison.only_after.append(task_id)
|
|
67
|
+
else:
|
|
68
|
+
comparison.compared.append(task_id)
|
|
69
|
+
graded = [task_id for task_id in comparison.compared if _expectation(old[task_id], new[task_id]) == "pass"]
|
|
70
|
+
comparison.graded = graded
|
|
71
|
+
comparison.before_pass_rate = _rate(old, graded)
|
|
72
|
+
comparison.after_pass_rate = _rate(new, graded)
|
|
73
|
+
for task_id in comparison.compared:
|
|
74
|
+
if _expectation(old[task_id], new[task_id]) != "pass":
|
|
75
|
+
"""A task that must fail keeps the suite honest, its result is not a rate."""
|
|
76
|
+
continue
|
|
77
|
+
was, now = bool(old[task_id].get("passed")), bool(new[task_id].get("passed"))
|
|
78
|
+
if was and not now:
|
|
79
|
+
comparison.regressions.append(task_id)
|
|
80
|
+
elif now and not was:
|
|
81
|
+
comparison.improvements.append(task_id)
|
|
82
|
+
comparison.unexpected = [task["id"] for task in new.values() if not task.get("as_expected", True)]
|
|
83
|
+
comparison.broken_guards = [
|
|
84
|
+
task_id
|
|
85
|
+
for task_id in new
|
|
86
|
+
if _expectation(old.get(task_id, {}), new[task_id]) == "fail" and new[task_id].get("passed")
|
|
87
|
+
]
|
|
88
|
+
comparison.ungraded = [task["id"] for task in new.values() if task.get("error_kind")]
|
|
89
|
+
return comparison
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _expectation(old: dict[str, Any], new: dict[str, Any]) -> str:
|
|
93
|
+
"""What the task was supposed to do.
|
|
94
|
+
|
|
95
|
+
The reports of the old harness have no field, so the other run decides.
|
|
96
|
+
"""
|
|
97
|
+
return str(new.get("expect") or old.get("expect") or "pass")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _rate(tasks: dict[str, dict[str, Any]], ids: list[str]) -> float:
|
|
101
|
+
if not ids:
|
|
102
|
+
return 0.0
|
|
103
|
+
return round(sum(1 for task_id in ids if tasks[task_id].get("passed")) / len(ids), 4)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def check(report: dict[str, Any]) -> list[str]:
|
|
107
|
+
"""The problems of a single run: the tasks that did not do what they were supposed to."""
|
|
108
|
+
problems = []
|
|
109
|
+
unexpected = [task["id"] for task in report.get("tasks") or [] if not task.get("as_expected", True)]
|
|
110
|
+
if unexpected:
|
|
111
|
+
problems.append(
|
|
112
|
+
f"{len(unexpected)} of the tasks did not do what they were supposed to do: {', '.join(unexpected)}"
|
|
113
|
+
)
|
|
114
|
+
errors = [task["id"] for task in report.get("tasks") or [] if task.get("error_kind")]
|
|
115
|
+
if errors:
|
|
116
|
+
problems.append(f"{len(errors)} of the tasks the harness could not grade: {', '.join(errors)}")
|
|
117
|
+
return problems
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def verdict(comparison: Comparison, max_regressions: int = 0, max_drop: float = 0.0) -> list[str]:
|
|
121
|
+
"""The problems of the change: what the agent cannot do any more.
|
|
122
|
+
|
|
123
|
+
The margin forgives a regression, so the tasks that regressed are not
|
|
124
|
+
reported twice: only what the margin does not forgive is a problem.
|
|
125
|
+
"""
|
|
126
|
+
problems = []
|
|
127
|
+
if len(comparison.regressions) > max_regressions:
|
|
128
|
+
problems.append(
|
|
129
|
+
f"{len(comparison.regressions)} regressions (at most {max_regressions} allowed): "
|
|
130
|
+
f"{', '.join(comparison.regressions)}"
|
|
131
|
+
)
|
|
132
|
+
if comparison.drop > max_drop:
|
|
133
|
+
problems.append(
|
|
134
|
+
f"the pass rate fell from {comparison.before_pass_rate:.3f} to {comparison.after_pass_rate:.3f} "
|
|
135
|
+
f"(a drop of {comparison.drop:.3f}, at most {max_drop:.3f} allowed)"
|
|
136
|
+
)
|
|
137
|
+
if comparison.broken_guards:
|
|
138
|
+
problems.append(f"the guards of the suite let a task through: {', '.join(comparison.broken_guards)}")
|
|
139
|
+
if comparison.ungraded:
|
|
140
|
+
problems.append(
|
|
141
|
+
f"{len(comparison.ungraded)} of the tasks the harness could not grade: {', '.join(comparison.ungraded)}"
|
|
142
|
+
)
|
|
143
|
+
return problems
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def render(comparison: Comparison) -> str:
|
|
147
|
+
"""The comparison, as a text a human reads."""
|
|
148
|
+
lines = [
|
|
149
|
+
f"before: {comparison.before_label or '-'} fingerprint: {comparison.before_fingerprint or '-'}",
|
|
150
|
+
f"after: {comparison.after_label or '-'} fingerprint: {comparison.after_fingerprint or '-'}",
|
|
151
|
+
]
|
|
152
|
+
if comparison.before_fingerprint:
|
|
153
|
+
if comparison.config_changed:
|
|
154
|
+
lines.append("the configuration changed between the two runs")
|
|
155
|
+
else:
|
|
156
|
+
lines.append("the two runs ran the same configuration")
|
|
157
|
+
if comparison.compared:
|
|
158
|
+
lines.append(
|
|
159
|
+
f"pass rate: {comparison.before_pass_rate:.3f} -> {comparison.after_pass_rate:.3f} "
|
|
160
|
+
f"over {len(comparison.graded)} tasks of both runs"
|
|
161
|
+
)
|
|
162
|
+
for title, ids in (
|
|
163
|
+
("regressions", comparison.regressions),
|
|
164
|
+
("improvements", comparison.improvements),
|
|
165
|
+
("guards", [task_id for task_id in comparison.compared if task_id not in comparison.graded]),
|
|
166
|
+
("only in the first run", comparison.only_before),
|
|
167
|
+
("only in the second run", comparison.only_after),
|
|
168
|
+
):
|
|
169
|
+
lines.append(f"{title}: {', '.join(ids) if ids else '-'}")
|
|
170
|
+
if comparison.before_summary.get("total_tool_calls") is not None:
|
|
171
|
+
lines.append(
|
|
172
|
+
f"tool calls: {comparison.before_summary.get('total_tool_calls', 0)} "
|
|
173
|
+
f"-> {comparison.after_summary.get('total_tool_calls', 0)}"
|
|
174
|
+
)
|
|
175
|
+
else:
|
|
176
|
+
lines.append("there is no run to compare with, only the report of the second run")
|
|
177
|
+
lines.append(_summary_line(comparison.after_summary))
|
|
178
|
+
lines.append(f"unexpected: {', '.join(comparison.unexpected) if comparison.unexpected else '-'}")
|
|
179
|
+
return "\n".join(lines)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _summary_line(summary: dict[str, Any]) -> str:
|
|
183
|
+
"""The numbers of a run, as one line."""
|
|
184
|
+
if not summary:
|
|
185
|
+
return "no numbers"
|
|
186
|
+
return (
|
|
187
|
+
f"{summary.get('tasks', 0)} tasks: {summary.get('passed', 0)} passed, "
|
|
188
|
+
f"{summary.get('failed', 0)} failed, {summary.get('errors', 0)} errors, "
|
|
189
|
+
f"{summary.get('unexpected', 0)} unexpected"
|
|
190
|
+
)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""The report of an eval run: the numbers, the fingerprint and the text.
|
|
2
|
+
|
|
3
|
+
The report is the deliverable of a run: two reports of the same suite can be
|
|
4
|
+
compared, as long as their fingerprint is the same. The fingerprint is a hash of
|
|
5
|
+
the configuration the agent ran with, so that a change of the harness is visible
|
|
6
|
+
instead of being silently mixed into the numbers.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from coderagent.config.schema import Config
|
|
15
|
+
from coderagent.core.telemetry import money
|
|
16
|
+
from coderagent.eval.runner import TaskResult
|
|
17
|
+
from coderagent.eval.task import task_overrides
|
|
18
|
+
|
|
19
|
+
FORMAT = "coder-eval-1.0"
|
|
20
|
+
"""The format of the report. The external tools read it."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Report:
|
|
25
|
+
label: str
|
|
26
|
+
suite: str
|
|
27
|
+
model: str
|
|
28
|
+
fingerprint: str
|
|
29
|
+
config: dict[str, Any]
|
|
30
|
+
"""The input of the fingerprint, as it was. A diff of it shows what changed."""
|
|
31
|
+
started_at: float
|
|
32
|
+
duration_seconds: float
|
|
33
|
+
tasks: list[TaskResult] = field(default_factory=list)
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def summary(self) -> dict[str, Any]:
|
|
37
|
+
"""The numbers of the whole run."""
|
|
38
|
+
errors = [task for task in self.tasks if task.error_kind]
|
|
39
|
+
graded = [task for task in self.tasks if not task.error_kind]
|
|
40
|
+
passed = [task for task in graded if task.passed]
|
|
41
|
+
unexpected = [task for task in self.tasks if not task.as_expected]
|
|
42
|
+
ratios = [ratio for task in self.tasks for ratio in task.summary_ratios]
|
|
43
|
+
return {
|
|
44
|
+
"tasks": len(self.tasks),
|
|
45
|
+
"passed": len(passed),
|
|
46
|
+
"failed": len(graded) - len(passed),
|
|
47
|
+
"errors": len(errors),
|
|
48
|
+
"unexpected": len(unexpected),
|
|
49
|
+
"pass_rate": round(len(passed) / len(graded), 4) if graded else 0.0,
|
|
50
|
+
"total_cost": round(sum(task.cost for task in self.tasks), 6),
|
|
51
|
+
"total_tokens_in": sum(task.tokens_in for task in self.tasks),
|
|
52
|
+
"total_tokens_out": sum(task.tokens_out for task in self.tasks),
|
|
53
|
+
"total_model_calls": sum(task.model_calls for task in self.tasks),
|
|
54
|
+
"total_tool_calls": sum(task.tool_calls for task in self.tasks),
|
|
55
|
+
"compactions": sum(task.compactions for task in self.tasks),
|
|
56
|
+
"summary_ratio_mean": round(sum(ratios) / len(ratios), 4) if ratios else 0.0,
|
|
57
|
+
"summary_ratio_max": round(max(ratios), 4) if ratios else 0.0,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
def to_dict(self) -> dict[str, Any]:
|
|
61
|
+
return {
|
|
62
|
+
"format": FORMAT,
|
|
63
|
+
"label": self.label,
|
|
64
|
+
"suite": self.suite,
|
|
65
|
+
"model": self.model,
|
|
66
|
+
"fingerprint": self.fingerprint,
|
|
67
|
+
"config": self.config,
|
|
68
|
+
"started_at": self.started_at,
|
|
69
|
+
"duration_seconds": self.duration_seconds,
|
|
70
|
+
"summary": self.summary,
|
|
71
|
+
"tasks": [task.to_dict() for task in self.tasks],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def to_json(self) -> str:
|
|
75
|
+
return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
|
|
76
|
+
|
|
77
|
+
def to_text(self) -> str:
|
|
78
|
+
"""The report, as a table a human reads."""
|
|
79
|
+
lines = [
|
|
80
|
+
f"suite: {self.suite} model: {self.model} label: {self.label or '-'}",
|
|
81
|
+
f"fingerprint: {self.fingerprint}",
|
|
82
|
+
]
|
|
83
|
+
for task in self.tasks:
|
|
84
|
+
mark = "✓" if task.passed else "✗"
|
|
85
|
+
if not task.as_expected:
|
|
86
|
+
mark = "!"
|
|
87
|
+
note = f" {task.error}" if task.error else ""
|
|
88
|
+
lines.append(
|
|
89
|
+
f"{mark} {task.id:<24} {task.mode:<8} {money(task.cost, task.priced)} "
|
|
90
|
+
f"{task.model_calls:>3} calls {task.tool_calls:>3} tools {task.duration_seconds:>6.1f}s{note}"
|
|
91
|
+
)
|
|
92
|
+
summary = self.summary
|
|
93
|
+
priced = all(task.priced for task in self.tasks)
|
|
94
|
+
lines.append(
|
|
95
|
+
f"{summary['tasks']} tasks: {summary['passed']} passed, {summary['failed']} failed, "
|
|
96
|
+
f"{summary['errors']} errors (pass rate {summary['pass_rate'] * 100:.1f}%)"
|
|
97
|
+
)
|
|
98
|
+
if summary["unexpected"]:
|
|
99
|
+
lines.append(f"{summary['unexpected']} tasks did not do what they were supposed to do")
|
|
100
|
+
lines.append(
|
|
101
|
+
f"cost {money(summary['total_cost'], priced)} tokens {summary['total_tokens_in']} in / "
|
|
102
|
+
f"{summary['total_tokens_out']} out {summary['total_model_calls']} model calls"
|
|
103
|
+
)
|
|
104
|
+
if summary["compactions"]:
|
|
105
|
+
lines.append(
|
|
106
|
+
f"{summary['compactions']} compactions: the summaries kept "
|
|
107
|
+
f"{summary['summary_ratio_mean'] * 100:.1f}% of the compacted history on average "
|
|
108
|
+
f"(worst {summary['summary_ratio_max'] * 100:.1f}%)"
|
|
109
|
+
)
|
|
110
|
+
return "\n".join(lines)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def fingerprint_inputs(config: Config, model: str, permission_mode: str = "", tasks=None) -> dict[str, Any]:
|
|
114
|
+
"""The configuration the numbers depend on. The hash of it is the fingerprint."""
|
|
115
|
+
return {
|
|
116
|
+
"format": FORMAT,
|
|
117
|
+
"model": model,
|
|
118
|
+
"model.routing": config.model.routing,
|
|
119
|
+
"model.routing_rules": [rule.model_dump() for rule in config.model.routing_rules],
|
|
120
|
+
"agent.system_prompt": config.agent.system_prompt,
|
|
121
|
+
"agent.max_turns": config.agent.max_turns,
|
|
122
|
+
"agent.cost_limit": config.agent.cost_limit,
|
|
123
|
+
"agent.token_limit": config.agent.token_limit,
|
|
124
|
+
"tools.enabled": config.tools.enabled,
|
|
125
|
+
"tools.disabled": config.tools.disabled,
|
|
126
|
+
"permissions.mode": permission_mode or config.permissions.mode,
|
|
127
|
+
"permissions.rules": config.permissions.rules,
|
|
128
|
+
"permissions.deny_paths": config.permissions.deny_paths,
|
|
129
|
+
"context": config.context.model_dump(),
|
|
130
|
+
"sandbox.type": config.sandbox.type,
|
|
131
|
+
"tasks": {task.id: task_overrides(task) for task in tasks or []},
|
|
132
|
+
"tasks.require_tools": {
|
|
133
|
+
task.id: [requirement.to_dict() for requirement in task.require_tools] for task in tasks or []
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def fingerprint(config: Config, model: str, permission_mode: str = "", tasks=None) -> str:
|
|
139
|
+
"""The hash of the configuration the agent runs with."""
|
|
140
|
+
payload = json.dumps(fingerprint_inputs(config, model, permission_mode, tasks), sort_keys=True, ensure_ascii=False)
|
|
141
|
+
return "sha256:" + hashlib.sha256(payload.encode("utf-8")).hexdigest()
|