Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/agent_env/cli/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def _format_prompt_response(pr) -> str:
]
if pr.agent_trajectory_object_url:
lines.append(f" agent_trajectory_object_url: {pr.agent_trajectory_object_url}")
if len(urls := pr.trajectory_object_urls()) > 1:
lines.append(f" trajectory_object_urls ({len(urls)}, in turn order):")
lines.extend(f" - {url}" for url in urls)
if pr.agent_trajectory_object_prefix:
lines.append(f" agent_trajectory_object_prefix: {pr.agent_trajectory_object_prefix}")
if pr.agent_trajectory_file_path:
Expand Down
110 changes: 87 additions & 23 deletions src/agent_env/explorer/ui/src/components/task-instance-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
import {
buildBarDownloads,
shouldCollapseBarDownloads,
type BarDownload,
type BarDownloadFile,
} from '../lib/bar-downloads';
import { collectedZipFiles, isAbsoluteArtifactPath } from '../lib/collected-zip-files';

Expand Down Expand Up @@ -613,7 +613,7 @@ export function TaskInstanceViewer({
);
const collapseBarDownloads = shouldCollapseBarDownloads(barDownloads.length);
const runBarDownload = useCallback(
(download: BarDownload) => {
(download: BarDownloadFile) => {
void handleDownloadTrajectory(download.objectUrl);
},
[handleDownloadTrajectory],
Expand Down Expand Up @@ -853,31 +853,95 @@ export function TaskInstanceViewer({
the menu's a11y tree; Radix tracks items by context, not
DOM parentage, so keyboard navigation is unaffected. */}
<div role="none" className="max-h-80 overflow-y-auto">
{barDownloads.map(item => (
<DropdownMenu.Item
key={item.key}
onSelect={() => runBarDownload(item)}
title={item.title}
>
<Download size={12} />
{item.label}
</DropdownMenu.Item>
))}
{barDownloads.map(item =>
item.turnPicker ? (
// A response of several turns is one row, its turns in a submenu.
<DropdownMenu.Sub key={item.key}>
<DropdownMenu.SubTrigger title={item.turnPicker.title}>
<Download size={12} />
{item.turnPicker.label}
</DropdownMenu.SubTrigger>
<DropdownMenu.SubContent>
<div role="none" className="max-h-80 overflow-y-auto">
{item.turnPicker.turns.map(turn => (
<DropdownMenu.Item
key={turn.key}
onSelect={() => runBarDownload(turn)}
title={turn.title}
>
<Download size={12} />
{turn.label}
</DropdownMenu.Item>
))}
</div>
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
) : (
<DropdownMenu.Item
key={item.key}
onSelect={() => runBarDownload(item)}
title={item.title}
>
<Download size={12} />
{item.label}
</DropdownMenu.Item>
),
)}
</div>
</DropdownMenu.Content>
</DropdownMenu.Root>
) : (
barDownloads.map(item => (
<button
key={item.key}
onClick={() => runBarDownload(item)}
title={item.title}
className="flex items-center gap-1 px-2 py-1 rounded text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--accent)] transition-colors"
>
<Download size={12} />
{item.label}
</button>
))
barDownloads.map(item =>
item.turnPicker ? (
// A response of several turns: its button downloads the last available trajectory, the chevron picks
// any turn.
<div key={item.key} className="flex items-center">
<button
onClick={() => runBarDownload(item)}
title={item.title}
className="flex items-center gap-1 pl-2 pr-1 py-1 rounded-l text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--accent)] transition-colors"
>
<Download size={12} />
{item.label}
</button>
<DropdownMenu.Root>
<DropdownMenu.Trigger>
<button
title={item.turnPicker.title}
aria-label={item.turnPicker.title}
className="flex items-center px-1 py-1 rounded-r text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--accent)] transition-colors"
>
<ChevronDown size={12} />
</button>
</DropdownMenu.Trigger>
<DropdownMenu.Content sideOffset={4} align="end">
<div role="none" className="max-h-80 overflow-y-auto">
{item.turnPicker.turns.map(turn => (
<DropdownMenu.Item
key={turn.key}
onSelect={() => runBarDownload(turn)}
title={turn.title}
>
<Download size={12} />
{turn.label}
</DropdownMenu.Item>
))}
</div>
</DropdownMenu.Content>
</DropdownMenu.Root>
</div>
) : (
<button
key={item.key}
onClick={() => runBarDownload(item)}
title={item.title}
className="flex items-center gap-1 px-2 py-1 rounded text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--accent)] transition-colors"
>
<Download size={12} />
{item.label}
</button>
),
)
)}
</div>
</div>
Expand Down
144 changes: 144 additions & 0 deletions src/agent_env/explorer/ui/src/lib/bar-downloads.smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,150 @@ function main(): void {
);
}

// A single trajectory keeps its plain entry: no turn in the label, no turn picker.
{
const [only] = buildBarDownloads(
[{ agent_trajectory_s3_uri: 'obj://t/one', target_agent_per_turn_trajectory_s3_uris: ['obj://t/one'], model: 'm' }],
);
assert(
JSON.stringify(only) ===
JSON.stringify({ key: 'obj://t/one', label: 'Trajectory', title: 'Download Trajectory (m)', objectUrl: 'obj://t/one' }),
'a one-turn response is the same entry as a response with no per-turn list',
);
}

// An always_on step: one entry for the run. Its button downloads the last wake, the picker every wake.
{
const downloads = buildBarDownloads(
[
{
agent_trajectory_s3_uri: 'obj://w/3',
target_agent_per_turn_trajectory_s3_uris: ['obj://w/1', null, 'obj://w/3'],
step_id: 'week',
model: 'm',
},
],
);
assert(downloads.length === 1, 'an always_on run of several wakes is one entry');
const [run] = downloads;
assert(
run?.label === 'Trajectory (turn 3 of 3)' && run.objectUrl === 'obj://w/3',
'its button downloads the last wake, its label naming that turn',
);
assert(run?.title === 'Download Trajectory, turn 3 of 3 (m)', 'the tooltip names the turn and the model');
assert(
run?.turnPicker?.turns.map(t => `${t.label}=${t.objectUrl}`).join('|') ===
'turn 1 of 3=obj://w/1|turn 3 of 3=obj://w/3',
'the turn picker lists every wake that stored a trajectory, in wake order',
);
assert(run?.turnPicker?.label === 'Trajectory (3 turns)', 'the picker counts the run\'s turns');
}

// A multi-turn prompt_agent step (a user-sim conversation of 20 turns) beside a single-turn step: two entries, not 21.
{
const turns = Array.from({ length: 20 }, (_, i) => `obj://chat/${i + 1}`);
const downloads = buildBarDownloads(
[
{ agent_trajectory_object_url: 'obj://t/setup', step_id: 'setup' },
{
agent_trajectory_object_url: turns[19],
target_agent_per_turn_trajectory_object_urls: turns,
step_id: 'converse',
},
],
);
assert(
downloads.map(d => d.label).join('|') === 'setup|converse (turn 20 of 20)',
'one entry per prompt response, the conversation labelled by its last turn',
);
assert(downloads[0]?.turnPicker === undefined, 'the single-turn step has no turn picker');
assert(
JSON.stringify(downloads[1]?.turnPicker?.turns.map(t => t.objectUrl)) === JSON.stringify(turns) &&
downloads[1]?.turnPicker?.turns[0]?.label === 'turn 1 of 20' &&
downloads[1]?.turnPicker?.turns[0]?.title === 'Download converse, turn 1 of 20',
'the conversation\'s picker offers every turn, labelled "turn k of n"',
);
assert(!shouldCollapseBarDownloads(downloads.length), 'two entries stay inline');
}

// A Claude Code atif/1 run's turns share one document: one plain entry, while a step of distinct turns gets a picker.
{
const downloads = buildBarDownloads(
[
{
agent_trajectory_s3_uri: 'obj://atif/doc',
target_agent_per_turn_trajectory_s3_uris: ['obj://atif/doc', 'obj://atif/doc', 'obj://atif/doc'],
step_id: 'copied',
},
{
agent_trajectory_object_url: 'obj://w/2',
target_agent_per_turn_trajectory_object_urls: ['obj://w/1', 'obj://w/2'],
step_id: 'week',
},
],
);
assert(
downloads.map(d => `${d.label}:${d.turnPicker ? d.turnPicker.turns.length : 0}`).join('|') ===
'copied:0|week (turn 2 of 2):2',
'turns sharing a document give one entry and no picker; distinct turns give a picker',
);
assert(new Set(downloads.map(d => d.key)).size === downloads.length, 'keys stay unique');
}

// An atif/1 run whose second turn's copy failed, so that turn kept its native trajectory: per-turn [A, B, A]. The
// button downloads the response's own trajectory, A, which the last turn stored, not the middle turn's B.
{
const [run] = buildBarDownloads(
[
{
agent_trajectory_s3_uri: 'obj://atif/doc',
target_agent_per_turn_trajectory_s3_uris: ['obj://atif/doc', 'obj://native/2', 'obj://atif/doc'],
step_id: 'copied',
model: 'm',
},
],
);
assert(
run?.objectUrl === 'obj://atif/doc' && run.key === 'obj://atif/doc',
'a run of [A, B, A] downloads A, the response\'s own trajectory',
);
assert(
run?.label === 'Trajectory (turn 3 of 3)' && run.title === 'Download Trajectory, turn 3 of 3 (m)',
'its label names the last turn that stored A',
);
assert(
run?.turnPicker?.turns.map(t => t.objectUrl).join('|') === 'obj://atif/doc|obj://native/2',
'its picker still lists every distinct trajectory',
);
}

// A response that records only its per-turn list downloads the last turn that stored one.
{
const [run] = buildBarDownloads(
[{ target_agent_per_turn_trajectory_object_urls: ['obj://w/1', 'obj://w/2', null] }],
);
assert(
run?.objectUrl === 'obj://w/2' && run.label === 'Trajectory (turn 2 of 3)',
'with no agent_trajectory url, the button falls back to the run\'s last trajectory',
);
}

// A response url the per-turn list lacks can't be placed in a turn, so it isn't called the last turn's.
{
const [run] = buildBarDownloads(
[
{
agent_trajectory_s3_uri: 'obj://x/final',
target_agent_per_turn_trajectory_s3_uris: ['obj://x/1', 'obj://x/2'],
},
],
);
assert(
run?.objectUrl === 'obj://x/final' && run.label === 'Trajectory (last available)',
'a url outside the per-turn list is labelled "last available"',
);
}

if (failures > 0) {
console.error(`\n${failures} assertion(s) failed`);
process.exit(1);
Expand Down
Loading
Loading