harness.pyruns inside the image. It reads the task instructions, calls the model, grades its work and reports the result.upload.pyruns on your computer. It defines the tasks and uploads the spec and its image files.
agt_...)
wherever YOUR_AGENT_ID appears. If onboarding gives you a project ID, pass it directly as
agent_id to push(), start_push(), or start_task_diagnostic(); no name lookup is needed.
These helpers also accept agent_name when selecting a project by name. Generally, projects
should have a clear grouping of similar specs and tasks.
For fixed-choice tasks, set BenchmarkSpec(benchmark_type="decision", ...) and follow
Train decision models for the decision harness and required
categorical outcome labels. The default spec type is generative.
Define your tasks
UseBenchmarkSpec to describe the spec and TaskSpec for each task. Each task
needs a unique name, a runtime (its own or the spec’s shared runtime), and a
run_command that starts your harness inside that runtime. split is optional; tasks
without one are assigned by a seeded shuffle, about 15% to test and the rest to train.
If needed, you can pass task-specific inputs through env_vars:
upload.py
os.environ. For larger inputs,
package the files in the image and have your harness read them. If tasks share an image,
use task-specific settings—such as environment variables or command-line arguments in
run_command—to select the right files and execute the task.
Task variable names cannot start with TRAJECTORY_ or be MODEL_ENDPOINT_ID,
MODEL_ENDPOINT_ACCESS_TOKEN, or MODEL_ENDPOINT_URL. Use SecretRef for credentials;
managed tasks receive their Trajectory session key and base URL automatically.
Set CPU and memory through env_resources. Keep training and test tasks in their
respective splits, and retain the source task IDs when selecting a subset.
If a task runs Docker containers, set env_resources.docker_engine=True. The execution
environment must be able to start a Docker daemon and pass docker info; installing
only the Docker CLI is not enough.
Network access on Modal
The defaultenv_resources.network_mode="no-network" allows only the platform endpoints
a managed task uses. For known external hosts, set env_resources.network_mode="allowlist"
and list their hostnames in env_resources.allowed_hosts.
Modal’s hostname allowlist matches TLS SNI and permits TLS only on TCP 443. DNS can resolve
a hostname even when the connection is blocked. With hostname allowlisting, PostgreSQL
connections on TCP 5432 fail even with TLS. See
Modal’s networking documentation.
Use env_resources.network_mode="public" only when unrestricted outbound internet access
is explicitly approved. Omit allowed_hosts in public mode. Use least-privilege credentials
and apply destination controls outside Trajectory where available. Changes apply to new
rollouts, so start a new rollout after changing network settings.
Call the model using Trajectory Client
In managed runs, Trajectory provides credentials and the API URL, so your harness can useClient() without configuring them.
Create the trajectory before task setup and keep its ID for the whole attempt.
Pass it with each model request:
harness.py
model does not select a different actor. Generation settings come from the
run’s options, set when you start an evaluation
or training run. The run’s
max_output_tokens_per_turn replaces the request’s max_tokens. If the option is
omitted or null, the run’s default cap applies. Managed evaluations do not support
different caps per request. The run’s temperature, top_p, top_k, and
reasoning_effort also override request values. Your harness decides whether one
response is enough or whether the model needs more turns.
When using Trajectory for a source-fixed judge or other auxiliary model, use an
organization-key client and a separate trajectory. trajectories.create() with the
managed session key reuses the actor’s trajectory. Pass the separate trajectory’s ID
with each auxiliary model request: x_trajectory_id in the Trajectory SDK or
X-Trajectory-Id in direct HTTP calls. Keep the organization key out of actor-visible
tools.
You can give the model tools if your harness supports executing tool calls and returning
their results to the model. Each tool describes an action the model can request, such as
running a shell command or reading a file. Include any software those tools need in the
image and provide the harness code that executes them.
Pass tool definitions through extra_body={"tools": tools}; this SDK’s chat method has no
tools= keyword. Preserve the assistant’s tool calls in the conversation, append each result
with its tool_call_id, and send that conversation on the next request. Check finish_reason
before dispatching tools; see termination reasons for cut-off replies.
Keep source-fixed judge calls separate from the managed actor trajectory.
Managed actor input modalities
Managed actors in task diagnostics, evaluations, and training accept text and, for vision models, images. Audio input, includinginput_audio, is unsupported. This is
a managed actor input limitation, not an SDK typing omission; changing the request’s
model cannot bypass the run’s actor selection or enable audio input.
Before uploading a spec, check each model’s input_modalities in
client.evals.list_models() or client.rl.list_models(). These catalogs currently
advertise only "text" and "image"; see image capability discovery.
If your benchmark requires the actor to hear audio, it cannot run as specified with a
managed actor. Substituting a transcript changes the benchmark’s semantics.
JSON and structured outputs
Managed actor calls in task diagnostics, evaluations, and training don’t support JSON mode or schema-constrained output. The API ignoresresponse_format and json_schema
on these calls, including when passed through extra_body. Function tools with
strict=True are also unsupported.
If your task needs JSON, ask for it in the prompt and validate the response in your
harness. Prompting doesn’t guarantee valid JSON.
Report the grade through the SDK
Your verifier decides how to grade the model’s work. It might compare an answer with an expected value, run a test suite or inspect files and running services. For an existing spec, trace the score field or formula its evaluation reader uses. Keep the native scale and grading rule, including partial credit when that is the reported score; a successful grader command alone does not identify the score. Once your verifier produces a valid numericgrade, report it against the same
trajectory ID, then mark the attempt complete:
harness.py
[0, 1]. For a different scale, declare its bounds when logging:
harness.py
[0, 1] by their
declared bounds. Use weight=0 for a secondary score you want to inspect without
changing that reward. Retrieve components with include_reward_components=True;
trajectory.reward alone can be zero without a native grade. The source-grader guide shows a worked mapping and
grader-output event.
These snippets show the SDK calls to place in your harness; they are not a complete
program. complete() defaults to ENV_DONE, which means the attempt finished normally.
When it did not, pass the reason. For an unrecovered model, environment, or grader
failure, report ERROR. Don’t log a reward for it, even if the grader returned a score:
harness.py
Package the harness in an image
Include your harness, task files and dependencies in the image. This Dockerfile installs the latest SDK and copies your application files into/app:
Dockerfile
run_command="python /app/harness.py" assumes harness.py is in that build
context. Check that paths in your task instructions and commands match where the
Dockerfile copies files. For the /workspace/... paths above, you could put the task
files under spec/workspace/ locally and add COPY workspace/ /workspace/ to the
Dockerfile. COPY . /app/ alone would put them under /app/workspace/ instead.
A build context holds at most 4,096 files. For a larger task set, archive the task files,
COPY the archive, and unpack it in a RUN step that creates the destination first:
ADD accepts only a single http:// or https:// URL, not local files or archives.
Add the tools and verifier dependencies your task needs, keeping held-out tests
out of any environment the model can inspect. Keep credentials out of the image.
Test that separation through the actor’s actual file and shell tools; hiding a path
from its prompt does not make the path private.
DockerfileBuild uploads files under the Dockerfile’s directory. Scope that context
to at most 4,096 files and 3 GiB; use .dockerignore or a smaller runtime directory
when the checkout is larger. COPY paths are relative to that context.
For harnesses that run Docker containers, such as Harbor, install and verify the Docker
daemon, CLI and Compose during the image build. On Debian Trixie:
Dockerfile
Validate one task before uploading
For quick debugging, runstart_task_diagnostic() on one representative task. A diagnostic
reports each task’s status and, for a failed task, its failure: a code, plus the rollout and
trajectory IDs, termination reason, and a redacted summary of any harness exception when the
task got that far:
timeout_seconds bounds only the image-build wait,
not task execution. Poll get_status() until the status is completed, failed, or
cancelled before calling get_diagnostics(). Fetching the report while the diagnostic
is pending or running returns HTTP 409.
ImageRef(...) and RuntimeRef(...) also work if you already have an image or runtime.
Check each task’s failure and the run-wide result.failure before moving on.
A diagnostic makes one attempt per task on the API’s default diagnostic model, reported as
result.base_model_slug; pass base_model_slug to choose another. options takes the
settings an evaluation accepts, except the sample
counts, which the diagnostic sets. Pass the model and settings you will evaluate and train
with, so the diagnostic generates replies the same way. Each task reports its
trajectory_id, the termination_reason it ended with, and its reward, which is null when
the trajectory ended before the harness recorded one.
Upload the spec and build its image
Put your Dockerfile, harness and task files in a localspec/ directory.
The example below uploads the task defined above to your chosen project:
upload.py
., _, and -;
push() and start_push() reject other names before uploading anything.
This uploads your tasks and files and waits for the image build. If registration or
building fails, push() raises BenchmarkOperationError, which you can import from
trajectory.lib; inspect its failures for the affected runtime and build error.
For an upload that may outlive your client, use start_push() and save its returned
operation id. A local timeout does not stop ingestion: reconnect with
get_operation(client, operation_id), then inspect refresh() and pages("failure")
before retrying. A failed runtime blocks evaluation of that spec version;
correct it and upload a new version rather than creating a second, partial spec.
To use this reconnectable form instead of the push() call above:
client.specs.retrieve_readiness(bench_id) before
starting a run. If ready is False, missing_secret_names and
unready_task_image_counts tell you what still needs attention.
A ready spec can contain only test tasks. Check the training split
before starting rollout training.
The upload operation’s ready field only covers builds requested with
build_images=True. When reusing a RuntimeRef with build_images=False, the
operation can succeed with ready=False and ready_runtimes=0 even if the spec
is ready to run.
Uploading does not run the tasks. After the diagnostic passes, run a small
evaluation and confirm a recorded grade. A graded zero is valid;
use held-out tasks when comparing checkpoints.
push(), start_push(), and start_task_diagnostic() accept upload_timeout in seconds
for blob store uploads, defaulting to 3600 (one hour). Pass upload_timeout=None to disable
blob store timeouts. These apply to individual HTTP operations against the blob store,
separately from API request timeouts, image-build waits, and signed-URL expiry. They do not
set a total upload deadline.
push() and start_push() also accept upload_max_retries, the retries for each upload request
(default 32, within 4.5 minutes of waiting). See Errors and retries.
You can share a runtime across tasks or set runtime on individual tasks:
Import the runtime helpers above from
trajectory.lib. For secret task inputs, import
SecretRef from trajectory and use it in env_vars instead of packaging secret values:
Create an organization secret
In the organization that owns the spec, open Settings → Secrets → Add secret. Enter a name that exactly matchessecret_ref. Have the key holder enter the
value directly and keep it out of prompts, source files, and logs.
The key holder can also run this from a terminal signed in to that organization:
client.specs.retrieve_readiness(bench_id) on the existing spec and
check missing_secret_names. Test the credential with its service separately.
Adding the secret requires no reupload or rebuild.
Upload and diagnose the full spec
ExpandBenchmarkSpec.tasks to the full task set and upload it with push(). Once
push() finishes, call client.diagnostics.start_benchmark() using
that upload’s bench_id. It runs up to 10 tasks, one attempt each, starting with one
task per runtime, and reports the same task outcomes and failures as the single-task
diagnostic. You need not repeat the single-task diagnostic for an unchanged runtime.
Like start_task_diagnostic(), start_benchmark() accepts base_model_slug to choose
the diagnostic model. Omit it to use the API’s default diagnostic model; the report
includes the resolved base_model_slug. Use the model and generation settings you
plan to evaluate and train with. The diagnostic sets its own sample counts.
agent_name and benchmark_name together to select the
latest version by name. Use bench_id when you need a specific version; spec
diagnostics require the ID returned by the upload helper.
Record a data quality finding
Useclient.specs.diagnostics.findings to record an issue on a specific spec
version, task, or recorded trajectory. Use the IDs returned by the API. A trajectory
target requires both its spec_id and task_id. Your own code detects issues
and publishes findings; these methods store and review the diagnostics you submit.
include_descendants=True to include child targets or state="all" to include
resolved findings. Use findings.retrieve(finding_id) for one finding or
findings.counts(targets=[{"bench_id": bench_id, "include_descendants": True}])
for open and resolved counts across multiple targets in one read.
The SDK generates one idempotency key per create call and reuses it for automatic
retries. To retry a submission in a separate call or process, supply and reuse an
explicit idempotency_key with the same request. Evidence can cite a spec, task,
or trajectory in your organization. For configuration and grading issues, use
task evidence and describe the relevant setting or behavior in its explanation.
Tool call IDs require the corresponding step indices. The platform displays the
explanation and references you submit. Your code supplies the evidence and runs
any checks needed to verify it.
Update your spec
Useclient.specs.update(bench_id, name=..., description=...) for metadata
changes only; it does not update tasks or runtime files.
To add or replace tasks while keeping the same bench_id, use the
HTTP task diff, append, file upload, and commit workflow.
Changed content under an existing task name replaces that task with a new task ID;
omitted tasks remain. Inspect failed_tasks because a commit can partially succeed.
Legacy tasks without content hashes and active evaluation resource cleanup can block
replacement. For changed runtime source, supply runtime.source and its files;
reusing an old runtime_id keeps that runtime’s source.
To publish a new version, call push() or start_push() with the same spec name
and project and include the full set of tasks you want. These helpers create a new
bench_id; they do not accept an existing ID. Earlier versions remain available.
Evaluation and training by name select the latest version, so finish a baseline/checkpoint
comparison before uploading another version under the same name.
Tips for adapting existing specs
Your harness implements the deadlines, grading environments and evidence uploads below.- Bring the verifier as well as the task environment. Check that its scripts, dependencies and expected paths are available when grading starts. A ready image does not prove the verifier can run; test one task before launching the full set.
- Give the agent and verifier separate time limits. When the agent runs out of time, stop its model calls and tools, then grade the work completed so far. Leave the verifier its full allowance and account for both phases in the rollout timeout.
- Follow the spec’s grading rules. Preserve resource limits, startup commands and environment settings. Some specs grade in the same running container; others require applying the model’s changes to a fresh one. If the model has shell or file access, your harness must keep held-out tests outside the environment those tools can inspect. Uploading an image does not automatically provide this separation.
- Keep enough evidence to explain a result. Save the generated output, verifier logs and error details as artifacts before completing the trajectory. Report missing logs separately from missing grades, and state any changes to the original spec.