DeepAgentAsJudge reward
DeepAgentAsJudge
Bases: ProgramAsJudge
Evaluate the output of a program using a DeepAgent.
The judge is a coding agent working in a sandboxed, copy-on-write copy
of workdir, with read_file, list_files, search_files,
write_file, edit_file and run_bash. The gold reference and the
prediction are written to a JSON file in that sandbox and the prompt only
carries a summary of them, so the judge can apply a predicted patch, run
the project's test suite, execute a generated script, or diff long
outputs before writing its critique and grading. Nothing it does touches
the real workdir. By default the sandbox is wiped back to the workdir
seed before each evaluation, so samples are graded independently.
Example:
import asyncio
import numpy as np
import synalinks
class Task(synalinks.DataModel):
task: str = synalinks.Field(description="The coding task to solve")
class Solution(synalinks.DataModel):
code: str = synalinks.Field(description="The Python code solving the task")
async def main():
language_model = synalinks.LanguageModel(model="ollama/mistral")
# The program to train: a plain generator writing Python snippets.
x0 = synalinks.Input(data_model=Task)
x1 = await synalinks.Generator(
data_model=Solution,
language_model=language_model,
)(x0)
program = synalinks.Program(inputs=x0, outputs=x1, name="coder")
# The judge writes the predicted code to a file, runs it in its
# sandbox and compares the output against the gold reference.
program.compile(
reward=synalinks.rewards.DeepAgentAsJudge(
language_model=language_model,
max_iterations=5,
# Optional: grade on a 1..5 integer scale instead of the
# default 1..20 `Rating20`. The reward is normalized back
# to 0.0..1.0 automatically.
score_type=synalinks.Rating,
),
optimizer=synalinks.optimizers.RandomFewShot(),
)
x_train = np.array(
[
Task(task="Print the sum of 152648 and 485."),
Task(task="Print the square of 12."),
Task(task="Print (3 + 4) * 5."),
Task(task="Print 1000 divided by 8."),
],
dtype="object",
)
y_train = np.array(
[
Solution(code="print(152648 + 485)"),
Solution(code="print(12 ** 2)"),
Solution(code="print((3 + 4) * 5)"),
Solution(code="print(1000 / 8)"),
],
dtype="object",
)
history = await program.fit(
x=x_train,
y=y_train,
epochs=4,
validation_split=0.25,
callbacks=[
synalinks.callbacks.EarlyStopping(
monitor="val_reward",
mode="max",
patience=2,
),
],
)
if __name__ == "__main__":
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language_model
|
LanguageModel
|
The language model to use. |
None
|
sub_language_model
|
LanguageModel
|
Optional. The language model
driving spawned subagents (see |
None
|
tools
|
list
|
Optional. Extra |
None
|
prompt_template
|
str
|
The default jinja2 prompt template
to use (see |
None
|
examples
|
list
|
The default examples to use in the prompt
(see |
None
|
instructions
|
str
|
The default instructions for the tool-calling turns.
Defaults to |
None
|
final_instructions
|
str
|
Optional. The instructions for the final
grading turn. Defaults to |
None
|
score_type
|
type | str
|
Optional. The scale the judge picks the reward
from: |
Rating20
|
max_iterations
|
int
|
Optional. The maximum number of tool-calling turns before the judge must grade (Default to 10). |
10
|
use_chain_of_thought
|
bool
|
Optional. Whether the tool-calling turns think step by step before choosing tools (Default to False). |
False
|
timeout
|
float
|
Optional. Per-command budget in seconds for
|
30.0
|
workdir
|
str
|
Optional. Host directory whose files seed the sandbox
(see |
None
|
skills
|
list
|
Optional. Agent Skills roots (see |
None
|
sandbox
|
Sandbox
|
Optional. A ready-made sandbox to grade in instead
of one built from |
None
|
max_subagent_depth
|
int
|
Optional. Lets the judge spawn subagents on
forks of its filesystem (see |
0
|
reset_sandbox
|
bool
|
Optional. Whether to wipe the sandbox back to
the |
None
|
reduction
|
str
|
Optional. The reward reduction (Default to |
'mean'
|
name
|
str
|
Optional. string name of the reward instance. |
'deep_agent_as_judge'
|
in_mask
|
list
|
Optional. list of keys to keep to compute the reward. |
None
|
out_mask
|
list
|
Optional. list of keys to remove to compute the reward. |
None
|
in_mask_pattern
|
str
|
Optional. Regex pattern; fields whose names match
are kept (combined with |
None
|
out_mask_pattern
|
str
|
Optional. Regex pattern; fields whose names match
are dropped (combined with |
None
|
Source code in synalinks/src/rewards/deep_agent_as_judge.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
DeepAgentAsJudgeProgram
Bases: Program
Evaluate the output of a program using a DeepAgent.
The judge works in a sandboxed copy of workdir with file and shell
tools; its final answer is a critique and a reward on the score_type
scale, normalized to 0.0..1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language_model
|
LanguageModel
|
The language model to use. |
None
|
sub_language_model
|
LanguageModel
|
Optional. The language model
driving spawned subagents (see |
None
|
tools
|
list
|
Optional. Extra |
None
|
prompt_template
|
str
|
The default jinja2 prompt template
to use (see |
None
|
examples
|
list
|
The default examples to use in the prompt
(see |
None
|
instructions
|
str
|
The default instructions for the tool-calling turns.
Defaults to |
None
|
final_instructions
|
str
|
Optional. The instructions for the final
grading turn. Defaults to |
None
|
score_type
|
type | str
|
Optional. The scale the judge picks the reward
from (see |
Rating20
|
max_iterations
|
int
|
Optional. The maximum number of tool-calling turns before the judge must grade (Default to 10). |
10
|
use_chain_of_thought
|
bool
|
Optional. Whether the tool-calling turns think step by step before choosing tools (Default to False). |
False
|
timeout
|
float
|
Optional. Per-command budget in seconds for
|
30.0
|
workdir
|
str
|
Optional. Host directory whose files seed the sandbox
(see |
None
|
skills
|
list
|
Optional. Agent Skills roots (see |
None
|
sandbox
|
Sandbox
|
Optional. A ready-made sandbox to grade in instead
of one built from |
None
|
max_subagent_depth
|
int
|
Optional. Lets the judge spawn subagents on
forks of its filesystem (see |
0
|
reset_sandbox
|
bool
|
Optional. Whether to wipe the sandbox back to
the |
None
|
name
|
str
|
Optional. The name of the program. |
None
|
description
|
str
|
Optional. The description of the program. |
None
|
trainable
|
bool
|
Whether the program's variables should be trainable. |
True
|
Source code in synalinks/src/rewards/deep_agent_as_judge.py
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 | |
default_deep_agent_judge_instructions(score_type=Rating20, workdir=None)
Return the default instructions of DeepAgentAsJudge for a score scale.
The instructions are the DeepAgent defaults (the file and shell tools
and how to use them) followed by the judging task: where the prediction
and the gold reference live, how to verify with the tools, and what to
answer. The grading scale is spelled out in plain words so the language
model knows what the reward means.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score_type
|
type | str
|
The score scale (see |
Rating20
|
workdir
|
str
|
Optional. The judge's working directory, rendered in the tool plan. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The instructions string. |