Skip to content

feat(agents): add Cline CLI agent harness - #2563

Merged
cmunley1 merged 3 commits into
NVIDIA-NeMo:mainfrom
cline-test-bot:feat/cline-agent-harness
Aug 18, 2026
Merged

cmunley1 merged 3 commits into
NVIDIA-NeMo:mainfrom
cline-test-bot:feat/cline-agent-harness

Conversation

@cline-test-bot

Copy link
Copy Markdown
Contributor

What

Adds cline_agent, a Gym agent harness that runs the Cline CLI headlessly and converts its streamed JSON event log into Gym Responses API trajectories, plus configs, docs, and tests wiring it into math_with_judge and anyswe_agent.

ClineAgent implementation

  • ClineAgent / ClineAgentConfig built on SimpleResponsesAPIAgent, following the existing CLI-agent harness pattern.
  • Each request runs one cline --json --auto-approve true subprocess; responses() returns the parsed trajectory and run() hands it to the resources server for verification.
  • The CLI surface is exposed through Hydra config: command (split on spaces so npx cline works), model, provider, thinking, compaction, retries, timeout, setup_timeout, extra_args, env, command_permissions, system_prompt / system_prompt_override, workspace_root, repo_dir.
  • concurrency bounds simultaneous run() calls; timeouts kill the whole process group, and --timeout is also passed to Cline so it winds the session down itself first.
  • setup_cline.py auto-installs the pinned cline npm package (3.0.55) at startup, bootstrapping a local portable Node.js when npm is not present, per the external-tool auto-install convention.

Streaming reasoning/text/tool parsing

parse_cline_events() maps Cline's newline-delimited JSON records to Gym items:

Cline --json record Gym item
agent_event content_start / content_end (text) assistant message
agent_event content_start (tool) function_call
agent_event content_end (tool) function_call_output (its error when the tool failed)
agent_event content_* (reasoning) <think> block on that turn's message
agent_event usage, run_result token usage
hook_event ignored (duplicates tool boundaries the agent events already carry)

Two behaviors worth calling out, both covered by tests:

  • Cline closes a turn's reasoning after its text, so the <think> block is assembled from the reasoning streamed so far rather than from the trailing content_end, which would otherwise attach it to the following turn.
  • run_result.aggregateUsage is authoritative when present; a run killed on timeout never prints it, so per-turn usage totals are summed instead and timed_out is recorded in metadata.

Isolated per-rollout settings / model-server setup

Cline reads its provider, key, model, and base URL from a settings file rather than from run flags (-k overrides only the key, and no flag sets a base URL). So on the model-server path the agent runs one cline auth openai-compatible --baseurl <model server> --modelid <model> --data-dir <run dir> before the task.

To keep that from becoming shared global state:

  • Every request gets its own run dir with a dedicated CLINE_DATA_DIR; the settings, session, db, and team paths all point inside it.
  • CLINE_SESSION_BACKEND_MODE=local keeps each run in its own process instead of a shared hub daemon.
  • Concurrent rollouts therefore share no provider settings or session state, and the user's ~/.cline is never read or written. The run dir is removed afterwards.

Routing model calls through the Gym Model Server is what makes them show up in Gym's capture and lets one config run against vLLM, OpenAI, or an inference provider by swapping --model-type. Setting model_server: null falls back to calling a provider directly.

Configs, docs, tests

  • responses_api_agents/cline_agent/configs/cline_agent.yaml — base harness config.
  • resources_servers/math_with_judge/configs/math_with_judge_cline_agent.yaml — math env via _inherit_from, math-verify only (should_use_judge: false).
  • responses_api_agents/anyswe_agent/configs/anyswe_cline.yaml + setup_scripts/cline_agent_deps.sh — SWE-bench inside the task container, with repo_dir: /testbed so Cline's edits land where anyswe takes the patch from.
  • Docs: agent README (quick start, model server, config fields, trajectory mapping, limitations), anyswe README, root README environment table, and the trajectory capabilities matrix.
  • responses_api_agents/cline_agent/tests/test_app.py — 51 tests over event parsing, command construction, env isolation, the auth-then-run model server path, prompt handling, timeout behavior, and config parsing.

Validation

.venv/bin/python -m pytest responses_api_agents/cline_agent/tests/test_app.py -q      -> 51 passed
.venv/bin/python -m pytest responses_api_agents/anyswe_agent/tests/test_app.py -q     -> 15 passed
.venv/bin/python -m ruff check responses_api_agents/cline_agent/                      -> All checks passed
.venv/bin/python -m ruff format --check responses_api_agents/cline_agent/             -> 5 files already formatted
.venv/bin/pre-commit run --files <the 15 changed files>                               -> all hooks passed, no files modified

The event parser was validated against Cline 3.0.55, which is why the version is pinned in both the config and the deps script. Treat a bump as a deliberate change: raise it, re-run the tests and a live eval, then commit.

Limitations

  • Full OpenSandbox / SWE-bench grading was not run. The anyswe_cline.yaml path is exercised by config-parsing and deps-script tests only; an end-to-end SWE-bench run with real task images and patch grading has not been performed and should be done before this config is treated as baselined. The config ships with verified: false.
  • Eval-only: token IDs and logprobs are not wired up, so this harness is not usable for training as-is (reflected as X in the trajectory capabilities matrix).
  • One prompt per request. Multi-turn conversation input is reduced to the last user message plus any system message, matching the other CLI agent harnesses.
  • A prompt with no whitespace is padded with a trailing space: Cline decides a bare argument was quoted by looking for whitespace in it and otherwise rejects a single-word prompt as Unknown command or unquoted prompt, even after --.

Add `cline_agent`, a Gym agent harness that runs the Cline CLI headlessly
(`cline --json --auto-approve true`) and converts its newline-delimited JSON
event stream into Gym Responses API trajectory items.

- `ClineAgent` / `ClineAgentConfig` on `SimpleResponsesAPIAgent`, exposing the
  CLI surface (command, model, provider, thinking, compaction, retries,
  timeouts, command permissions, extra args) through Hydra config.
- Streaming event parser maps Cline `agent_event` records to Gym items:
  text `content_start`/`content_end` to assistant messages, tool
  `content_start` to `function_call` and `content_end` to
  `function_call_output` (carrying tool errors), and `reasoning` events to a
  `<think>` block assembled from reasoning streamed so far, since Cline closes
  reasoning after text. Usage comes from `run_result.aggregateUsage` when
  present, falling back to per-turn `usage` totals on a timed-out run.
- Isolated per-rollout state: each request gets its own run dir with a
  dedicated `CLINE_DATA_DIR` (settings, session, db, and team paths all inside
  it) and `CLINE_SESSION_BACKEND_MODE=local`, so concurrent rollouts share no
  provider settings or session state and the user's `~/.cline` is untouched.
  The run dir is removed afterwards; timeouts kill the whole process group.
- Model server path: because Cline reads provider/model/base URL from a
  settings file rather than flags, the agent runs one
  `cline auth openai-compatible --baseurl <model server> --modelid <model>`
  into the run's data dir, so model traffic flows through the Gym model server
  and the backend is swappable via `--model-type`.
- `setup_cline.py` auto-installs the pinned `cline` npm package (3.0.55) on
  startup, bootstrapping a local portable Node.js when npm is absent.
- Configs: `cline_agent.yaml`, `math_with_judge_cline_agent.yaml`, and
  `anyswe_cline.yaml` plus `cline_agent_deps.sh` for SWE-bench task images.
- Docs: agent README, anyswe README, root README table, and the trajectory
  capabilities matrix.

Eval-only: token IDs and logprobs are not wired up, so this harness is not
usable for training as-is.

Signed-off-by: cline-test-bot <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Aug 15, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

SHIP — LGTM, no reliability concerns.

Reviewed all 15 changed files against the diff and the trusted base. This adds a new cline_agent CLI harness (eval-only) plus its anyswe SWE-bench and math_with_judge configs, a portable-Node/npm setup path, README/docs, and a full unit-test suite. It is a faithful structural clone of the already-vetted kilocode_agent/opencode_agent pattern, and the areas I scrutinized hardest all check out:

  • Scoring path is untouched. verify() and reward aggregation are unchanged; math_with_judge_cline_agent.yaml reuses the existing math_with_judge resources server with should_use_judge: false (math-verify only), matching the vetted kilocode config verbatim. The parser only shapes the trajectory the verifier reads, and content_end text supersedes streamed chunks so the final \boxed{} answer surfaces correctly. parse_cline_events has dedicated tests for the doubling, reasoning-ordering, orphan-tool, missing-content_end, and usage-fallback cases.
  • Async is correct. No httpx; run() goes through server_client with raise_for_status/get_response_json and propagates cookies, identical to the sibling agents. Subprocesses use start_new_session=True and a process-group SIGKILL on timeout, with a second communicate() to drain — same as kilocode_agent. No ray.get() in async, no missing awaits.
  • Config convention respected. cline_agent.yaml is the single source of truth; the env configs _inherit_from it. test_anyswe_config_kwargs_are_valid_config_fields guards that anyswe agent_kwargs stay valid ClineAgentConfig fields (they'd otherwise only fail once a sandbox is up).
  • Deps declared. requirements.txt + setup_cline.py/cline_agent_deps.sh auto-install a pinned Node + cline, and ensure_cline() runs in model_post_init, consistent with the auto-install pattern in CLAUDE.md. cline_version is pinned (3.0.55) and kept in sync between the config, the deps script, and the setup module.

NOTE (author's call, not a regression): the math_with_judge path runs Cline locally with --auto-approve true and empty command_permissions (unrestricted shell), executing model-generated commands on the host. This matches the existing local CLI math harnesses (kilocode/opencode), so it's an established pattern rather than something introduced here — flagging only for awareness. In the anyswe path this runs inside the SWE task sandbox, so it's contained.

agent_server_class: ClineAgent
agent_config_class: ClineAgentConfig
agent_kwargs:
model: model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we change this to ${policy_model_name}

@cmunley1 cmunley1 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tested anyswe, anyterminal and math with the changes requested and looks good to me

container_formatter: ${oc.env:ANYSWE_CONTAINER_FORMATTER}
sandbox_provider: sandbox
sandbox_model_base_url: ${oc.env:NEMO_GYM_SANDBOX_MODEL_BASE_URL,null}
swebench_agent_timeout: 2100

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we add agent_runtime_source: auto

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/_portable_python.sh"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think we need to bump this to 3.13 but that can be outside of this PR

)
try:
stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
except asyncio.TimeoutError:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only kills the npm shim and Cline child for TimeoutError. If the request coroutine is externally cancelled, CancelledError unwinds without killing the process group, leaving Cline running after the rollout and workspace are gone. Please catch cancellation separately, kill and await the process group, then re-raise the cancellation.

Comment thread responses_api_agents/cline_agent/app.py Outdated
input_tokens=input_tokens,
input_tokens_details=NeMoGymResponseInputTokensDetails(cached_tokens=0),
output_tokens=output_tokens,
output_tokens_details=NeMoGymResponseOutputTokensDetails(reasoning_tokens=0),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you also propagate reasoning token count from cline if possible?

@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Aug 17, 2026
@arafatkatze

Copy link
Copy Markdown
Contributor

@cmunley1 Thanks, we addressed all five requested changes and added tests for them. We also reran the Cline/AnySWE tests and Docker end-to-end validation locally. Could you please take another look and rerun or approve CI?

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Aug 18, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

Looks good! Thanks for the contribution

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

Labels

community-request Issue reported or requested by someone from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants