Skip to content

add opencode agent scaffold #9

Open
hrdkbhatnagar wants to merge 12 commits intomainfrom
add_opencode
Open

add opencode agent scaffold #9
hrdkbhatnagar wants to merge 12 commits intomainfrom
add_opencode

Conversation

@hrdkbhatnagar
Copy link
Collaborator

@hrdkbhatnagar hrdkbhatnagar commented Jan 16, 2026

Relevant main changes

Agent Implementation

  • agents/opencode/solve.sh - wrapper that:
    • Creates opencode.json config with auto-approval permissions
    • Runs OpenCode in non-interactive mode with --format json for trace output

Trace Parsing

  • scripts/parse_jsonl/opencode_parse_jsonl.py - parser that handles OpenCode's JSON event stream, right now im parsing:
    • tool_use events (tool calls with input/output)
    • text events (assistant responses)
    • step_start / step_finish events (with token counts and cost)
    • error events

Usage at the moment:

  export ANTHROPIC_API_KEY="..."
  export OPENCODE_API_KEY="..."  # Need for Zen 

  # Submit with direct provider
  condor_submit_bid n \
    -a "agent=opencode" \
    -a "agent_config=anthropic/claude-sonnet-4-5" \
    -a "eval=gsm8k" \
    -a "model_to_train=Qwen/Qwen3-1.7B-Base" \
    src/commit_utils/single_task.sub

  # Submit with Zen 
  condor_submit_bid n \
    -a "agent=opencode" \
    -a "agent_config=opencode/gpt-5.2-codex" \
    -a "eval=gsm8k" \
    -a "model_to_train=Qwen/Qwen3-1.7B-Base" \
    src/commit_utils/single_task.sub

List of supported models for Zen are at https://opencode.ai/docs/zen/

Notes

  • The JSON trace format is consistent across all models/providers, so the parser SHOULD work universally but I need to still check with parsing full runs across various providers

@hrdkbhatnagar hrdkbhatnagar marked this pull request as ready for review January 16, 2026 12:18
@hrdkbhatnagar hrdkbhatnagar added this to the V1 Release milestone Feb 11, 2026
@hrdkbhatnagar hrdkbhatnagar added the feature New feature or request label Feb 11, 2026
@hrdkbhatnagar hrdkbhatnagar self-assigned this Feb 11, 2026
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in agents/opencode/human_readable_trace.py

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed.
This functionality is covered by scripts/parse_all_to_human_readable.sh

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can revert this to non-zeroshot?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, it seems that we can revert this to non-zeroshot

Comment on lines 119 to 121
# Load baseline data
baseline_path = os.path.join(results_dir, "aggregated_baseline.csv")
baseline_path = os.path.join(results_dir, "aggregated_baseline_zeroshot.csv")
baseline_data, baseline_benchmarks = load_csv_as_dict(baseline_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm _zeroshot

Comment on lines 39 to 41
# Scan all directories
for subdir in results_path.glob('baseline/*'):
for subdir in results_path.glob('baseline_zeroshot/*'):
if subdir.is_dir():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm _zeroshot

Comment on lines 83 to 85
if args.include_baseline:
baseline_path = os.path.join(results_dir, "aggregated_baseline.csv")
baseline_path = os.path.join(results_dir, "aggregated_baseline_zeroshot.csv")
header, rows = load_csv_rows(baseline_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm _zeroshot

fi

export HF_HOME_NEW="/home/ben/hf_cache"
source /etc/profile.d/modules.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary I think
Should be covered by the first lines:

if [ "${POST_TRAIN_BENCH_JOB_SCHEDULER}" = "htcondor_mpi-is" ]; then
    source /etc/profile.d/modules.sh
fi

And will run into errors for non-mpi cluster

executable = /bin/bash
arguments = src/run_task.sh $(eval) $(agent) $(model_to_train) $(Cluster) $(num_hours) $(agent_config)
environment = "OPENAI_API_KEY=$ENV(OPENAI_API_KEY) ANTHROPIC_API_KEY=$ENV(ANTHROPIC_API_KEY) GEMINI_API_KEY=$ENV(GEMINI_API_KEY) HOME=$ENV(HOME) POST_TRAIN_BENCH_RESULTS_DIR=$ENV(POST_TRAIN_BENCH_RESULTS_DIR) POST_TRAIN_BENCH_CONTAINERS_DIR=$ENV(POST_TRAIN_BENCH_CONTAINERS_DIR) POST_TRAIN_BENCH_CONTAINER_NAME=$ENV(POST_TRAIN_BENCH_CONTAINER_NAME) POST_TRAIN_BENCH_JOB_SCHEDULER=$ENV(POST_TRAIN_BENCH_JOB_SCHEDULER) POST_TRAIN_BENCH_EXPERIMENT_NAME=$ENV(POST_TRAIN_BENCH_EXPERIMENT_NAME) HF_HOME=$ENV(HF_HOME) POST_TRAIN_BENCH_PROMPT=$ENV(POST_TRAIN_BENCH_PROMPT)"
environment = "OPENAI_API_KEY=$ENV(OPENAI_API_KEY) ANTHROPIC_API_KEY=$ENV(ANTHROPIC_API_KEY) GEMINI_API_KEY=$ENV(GEMINI_API_KEY) OPENCODE_API_KEY=$ENV(OPENCODE_API_KEY) KIMI_API_KEY=$ENV(KIMI_API_KEY) DASHSCOPE_API_KEY=$ENV(DASHSCOPE_API_KEY) ZAI_API_KEY=$ENV(ZAI_API_KEY) HOME=$ENV(HOME) POST_TRAIN_BENCH_RESULTS_DIR=$ENV(POST_TRAIN_BENCH_RESULTS_DIR) POST_TRAIN_BENCH_CONTAINERS_DIR=$ENV(POST_TRAIN_BENCH_CONTAINERS_DIR) POST_TRAIN_BENCH_CONTAINER_NAME=$ENV(POST_TRAIN_BENCH_CONTAINER_NAME) POST_TRAIN_BENCH_JOB_SCHEDULER=$ENV(POST_TRAIN_BENCH_JOB_SCHEDULER) POST_TRAIN_BENCH_EXPERIMENT_NAME=$ENV(POST_TRAIN_BENCH_EXPERIMENT_NAME) HF_HOME=$ENV(HF_HOME) POST_TRAIN_BENCH_PROMPT=$ENV(POST_TRAIN_BENCH_PROMPT)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use KIMI_API_KEY?
-> otherwise we can remove this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants