Repository navigation
feat(agents): add Cline CLI agent harness - #2563
Conversation
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]>
|
/claude review |
|
SHIP — LGTM, no reliability concerns. Reviewed all 15 changed files against the diff and the trusted base. This adds a new
NOTE (author's call, not a regression): the |
| agent_server_class: ClineAgent | ||
| agent_config_class: ClineAgentConfig | ||
| agent_kwargs: | ||
| model: model |
There was a problem hiding this comment.
can we change this to ${policy_model_name}
| 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 |
There was a problem hiding this comment.
can we add agent_runtime_source: auto
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| source "$SCRIPT_DIR/_portable_python.sh" |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
| input_tokens=input_tokens, | ||
| input_tokens_details=NeMoGymResponseInputTokensDetails(cached_tokens=0), | ||
| output_tokens=output_tokens, | ||
| output_tokens_details=NeMoGymResponseOutputTokensDetails(reasoning_tokens=0), |
There was a problem hiding this comment.
could you also propagate reasoning token count from cline if possible?
|
🌿 Preview your docs: https://nvidia-preview-feat-cline-agent-harness.docs.buildwithfern.com/nemo/gym Here are the markdown pages you've updated: |
Signed-off-by: Arafatkatze <[email protected]>
|
@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? |
|
Looks good! Thanks for the contribution |
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 intomath_with_judgeandanyswe_agent.ClineAgent implementation
ClineAgent/ClineAgentConfigbuilt onSimpleResponsesAPIAgent, following the existing CLI-agent harness pattern.cline --json --auto-approve truesubprocess;responses()returns the parsed trajectory andrun()hands it to the resources server for verification.command(split on spaces sonpx clineworks),model,provider,thinking,compaction,retries,timeout,setup_timeout,extra_args,env,command_permissions,system_prompt/system_prompt_override,workspace_root,repo_dir.concurrencybounds simultaneousrun()calls; timeouts kill the whole process group, and--timeoutis also passed to Cline so it winds the session down itself first.setup_cline.pyauto-installs the pinnedclinenpm 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:--jsonrecordagent_eventcontent_start/content_end(text)agent_eventcontent_start(tool)function_callagent_eventcontent_end(tool)function_call_output(itserrorwhen the tool failed)agent_eventcontent_*(reasoning)<think>block on that turn's messageagent_eventusage,run_resulthook_eventTwo behaviors worth calling out, both covered by tests:
<think>block is assembled from the reasoning streamed so far rather than from the trailingcontent_end, which would otherwise attach it to the following turn.run_result.aggregateUsageis authoritative when present; a run killed on timeout never prints it, so per-turnusagetotals are summed instead andtimed_outis 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 (
-koverrides only the key, and no flag sets a base URL). So on the model-server path the agent runs onecline auth openai-compatible --baseurl <model server> --modelid <model> --data-dir <run dir>before the task.To keep that from becoming shared global state:
CLINE_DATA_DIR; the settings, session, db, and team paths all point inside it.CLINE_SESSION_BACKEND_MODE=localkeeps each run in its own process instead of a shared hub daemon.~/.clineis 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. Settingmodel_server: nullfalls 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, withrepo_dir: /testbedso Cline's edits land where anyswe takes the patch from.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
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
anyswe_cline.yamlpath 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 withverified: false.Xin the trajectory capabilities matrix).Unknown command or unquoted prompt, even after--.