Spaces:
Running
Running
Zhu Jiajun (jz28583) Claude Opus 4.7 (1M context) commited on
Commit Β·
701d9c5
1
Parent(s): 464248e
Trim agents/cliproxyapi surface
Browse filesDrop unused symbols + the misleading config.example.yaml so the public
shim is just six things: ProxyEndpoint, anthropic_env, openai_env,
openai_yaml_block, is_ready, wait_until_ready.
- Remove gemini_env() β no current consumer.
- Remove spawn_proxy() ctx-manager β proxy always runs out of band on
this deploy (long-lived OAuth state).
- Remove agents/cliproxyapi/config.example.yaml β the real working
config lives in the operator's own ~/.cli-proxy-api/.
- Remove empty agents/common/tasks_md/ scaffolding.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- agents/README.md +1 -1
- agents/cliproxyapi/README.md +3 -14
- agents/cliproxyapi/__init__.py +2 -4
- agents/cliproxyapi/env.py +1 -18
- agents/cliproxyapi/health.py +3 -35
agents/README.md
CHANGED
|
@@ -45,7 +45,7 @@ gtb submit figraph --file <printed-path> --agent <my-agent-id>
|
|
| 45 |
|
| 46 |
1. Create `agents/<new_agent>/{__init__.py,runner.py,install.sh,README.md}`.
|
| 47 |
2. In `runner.py` import from `agents.cliproxyapi` (one of `anthropic_env`,
|
| 48 |
-
`openai_env`,
|
| 49 |
3. Use `agents.common.workspace.make_workspace()` for the run dir,
|
| 50 |
`agents.common.tasks.task_instruction()` for the task prompt,
|
| 51 |
`agents.common.submit.finalize()` for validate+optional-submit.
|
|
|
|
| 45 |
|
| 46 |
1. Create `agents/<new_agent>/{__init__.py,runner.py,install.sh,README.md}`.
|
| 47 |
2. In `runner.py` import from `agents.cliproxyapi` (one of `anthropic_env`,
|
| 48 |
+
`openai_env`, or `openai_yaml_block` per the agent's SDK).
|
| 49 |
3. Use `agents.common.workspace.make_workspace()` for the run dir,
|
| 50 |
`agents.common.tasks.task_instruction()` for the task prompt,
|
| 51 |
`agents.common.submit.finalize()` for validate+optional-submit.
|
agents/cliproxyapi/README.md
CHANGED
|
@@ -16,10 +16,8 @@ from agents.cliproxyapi import (
|
|
| 16 |
ProxyEndpoint, # where + key (read from env)
|
| 17 |
anthropic_env, # β dict, splice into subprocess env
|
| 18 |
openai_env,
|
| 19 |
-
gemini_env,
|
| 20 |
openai_yaml_block, # β dict, drop into a YAML config
|
| 21 |
wait_until_ready, # TCP probe; raise SystemExit on miss
|
| 22 |
-
spawn_proxy, # ctx-manager (opt-in; mostly for CI)
|
| 23 |
)
|
| 24 |
```
|
| 25 |
|
|
@@ -49,11 +47,6 @@ env = {**os.environ, **openai_env(ep, model="gpt-5.3-codex-spark")}
|
|
| 49 |
Sets `OPENAI_BASE_URL=β¦/v1`, `OPENAI_API_KEY`, `OPENAI_API_BASE`,
|
| 50 |
`OPENAI_MODEL`.
|
| 51 |
|
| 52 |
-
### Gemini SDK
|
| 53 |
-
```python
|
| 54 |
-
env = {**os.environ, **gemini_env(ep, model="gemini-2-pro-preview")}
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
### YAML configs (e.g. MLEvolve)
|
| 58 |
```python
|
| 59 |
block = openai_yaml_block(ep, model="gpt-5.3-codex-spark")
|
|
@@ -69,13 +62,9 @@ config["agent"]["feedback"].update(block)
|
|
| 69 |
git clone https://github.com/router-for-me/CLIProxyAPI && cd CLIProxyAPI
|
| 70 |
docker compose up -d # or: go build -o cliproxy ./cmd/...
|
| 71 |
```
|
| 72 |
-
2.
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
mkdir -p ~/.cli-proxy-api
|
| 76 |
-
cp agents/cliproxyapi/config.example.yaml ~/.cli-proxy-api/config.yaml
|
| 77 |
-
$EDITOR ~/.cli-proxy-api/config.yaml # set api-keys[0] + aliases
|
| 78 |
-
```
|
| 79 |
3. Run interactively once to OAuth-log into Claude / Codex / Gemini accounts.
|
| 80 |
4. Export client-side env vars:
|
| 81 |
```bash
|
|
|
|
| 16 |
ProxyEndpoint, # where + key (read from env)
|
| 17 |
anthropic_env, # β dict, splice into subprocess env
|
| 18 |
openai_env,
|
|
|
|
| 19 |
openai_yaml_block, # β dict, drop into a YAML config
|
| 20 |
wait_until_ready, # TCP probe; raise SystemExit on miss
|
|
|
|
| 21 |
)
|
| 22 |
```
|
| 23 |
|
|
|
|
| 47 |
Sets `OPENAI_BASE_URL=β¦/v1`, `OPENAI_API_KEY`, `OPENAI_API_BASE`,
|
| 48 |
`OPENAI_MODEL`.
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
### YAML configs (e.g. MLEvolve)
|
| 51 |
```python
|
| 52 |
block = openai_yaml_block(ep, model="gpt-5.3-codex-spark")
|
|
|
|
| 62 |
git clone https://github.com/router-for-me/CLIProxyAPI && cd CLIProxyAPI
|
| 63 |
docker compose up -d # or: go build -o cliproxy ./cmd/...
|
| 64 |
```
|
| 65 |
+
2. Set up the proxy config (`~/.cli-proxy-api/config.yaml`) with one
|
| 66 |
+
`api-keys:` entry and your upstream Claude / Codex / Gemini OAuth
|
| 67 |
+
accounts. See the upstream README for the full schema.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
3. Run interactively once to OAuth-log into Claude / Codex / Gemini accounts.
|
| 69 |
4. Export client-side env vars:
|
| 70 |
```bash
|
agents/cliproxyapi/__init__.py
CHANGED
|
@@ -18,16 +18,14 @@ isn't up, and an opt-in `spawn_proxy()` ctx-manager for one-off testing.
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
from .endpoint import ProxyEndpoint
|
| 21 |
-
from .env import anthropic_env,
|
| 22 |
-
from .health import is_ready,
|
| 23 |
|
| 24 |
__all__ = [
|
| 25 |
"ProxyEndpoint",
|
| 26 |
"anthropic_env",
|
| 27 |
-
"gemini_env",
|
| 28 |
"openai_env",
|
| 29 |
"openai_yaml_block",
|
| 30 |
"is_ready",
|
| 31 |
-
"spawn_proxy",
|
| 32 |
"wait_until_ready",
|
| 33 |
]
|
|
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
from .endpoint import ProxyEndpoint
|
| 21 |
+
from .env import anthropic_env, openai_env, openai_yaml_block
|
| 22 |
+
from .health import is_ready, wait_until_ready
|
| 23 |
|
| 24 |
__all__ = [
|
| 25 |
"ProxyEndpoint",
|
| 26 |
"anthropic_env",
|
|
|
|
| 27 |
"openai_env",
|
| 28 |
"openai_yaml_block",
|
| 29 |
"is_ready",
|
|
|
|
| 30 |
"wait_until_ready",
|
| 31 |
]
|
agents/cliproxyapi/env.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
"""Build env-var dicts (or YAML-config snippets) that point an SDK at the proxy.
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
anthropic_env(ep, model) β Anthropic SDK / Claude Code CLI
|
| 6 |
openai_env(ep, model) β OpenAI SDK / Codex CLI
|
| 7 |
-
gemini_env(ep, model) β google-generativeai SDK / gemini-cli
|
| 8 |
|
| 9 |
Plus `openai_yaml_block(ep, model)` for agents whose config files take
|
| 10 |
`base_url` / `api_key` / `model` fields directly (e.g. MLEvolve).
|
|
@@ -53,22 +52,6 @@ def openai_env(ep: ProxyEndpoint, model: str | None = None) -> dict[str, str]:
|
|
| 53 |
return env
|
| 54 |
|
| 55 |
|
| 56 |
-
def gemini_env(ep: ProxyEndpoint, model: str | None = None) -> dict[str, str]:
|
| 57 |
-
"""Env vars consumed by google-generativeai and gemini-cli.
|
| 58 |
-
|
| 59 |
-
The proxy exposes Gemini's `/v1beta/models/.../generateContent` shape on
|
| 60 |
-
the proxy root β clients prepend nothing.
|
| 61 |
-
"""
|
| 62 |
-
env = {
|
| 63 |
-
"GEMINI_API_BASE": ep.base_url(),
|
| 64 |
-
"GOOGLE_API_KEY": ep.api_key,
|
| 65 |
-
"GEMINI_API_KEY": ep.api_key,
|
| 66 |
-
}
|
| 67 |
-
if model:
|
| 68 |
-
env["GEMINI_MODEL"] = model
|
| 69 |
-
return env
|
| 70 |
-
|
| 71 |
-
|
| 72 |
def openai_yaml_block(ep: ProxyEndpoint, model: str) -> dict[str, str]:
|
| 73 |
"""Three-key dict for configs that name the proxy directly (e.g. MLEvolve).
|
| 74 |
|
|
|
|
| 1 |
"""Build env-var dicts (or YAML-config snippets) that point an SDK at the proxy.
|
| 2 |
|
| 3 |
+
Two SDK shapes are covered today; add more here as agents arrive:
|
| 4 |
|
| 5 |
anthropic_env(ep, model) β Anthropic SDK / Claude Code CLI
|
| 6 |
openai_env(ep, model) β OpenAI SDK / Codex CLI
|
|
|
|
| 7 |
|
| 8 |
Plus `openai_yaml_block(ep, model)` for agents whose config files take
|
| 9 |
`base_url` / `api_key` / `model` fields directly (e.g. MLEvolve).
|
|
|
|
| 52 |
return env
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def openai_yaml_block(ep: ProxyEndpoint, model: str) -> dict[str, str]:
|
| 56 |
"""Three-key dict for configs that name the proxy directly (e.g. MLEvolve).
|
| 57 |
|
agents/cliproxyapi/health.py
CHANGED
|
@@ -1,20 +1,11 @@
|
|
| 1 |
-
"""
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
matter which protocol surfaces the proxy version exposes.
|
| 5 |
-
|
| 6 |
-
`spawn_proxy` is a context manager for tests / one-off CI runs. Most users
|
| 7 |
-
should run the proxy out-of-band: it owns long-lived OAuth tokens and may
|
| 8 |
-
serve other tools besides the testbed.
|
| 9 |
-
"""
|
| 10 |
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
-
import contextlib
|
| 14 |
import socket
|
| 15 |
-
import subprocess
|
| 16 |
import time
|
| 17 |
-
from pathlib import Path
|
| 18 |
|
| 19 |
from .endpoint import ProxyEndpoint
|
| 20 |
|
|
@@ -38,26 +29,3 @@ def wait_until_ready(ep: ProxyEndpoint, timeout: float = 30.0) -> None:
|
|
| 38 |
f"Start it (e.g. `cliproxy --config ~/.cli-proxy-api/config.yaml`) "
|
| 39 |
f"and confirm CLIPROXYAPI_HOST / CLIPROXYAPI_PORT."
|
| 40 |
)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
@contextlib.contextmanager
|
| 44 |
-
def spawn_proxy(
|
| 45 |
-
config_path: str | Path,
|
| 46 |
-
binary: str = "cliproxy",
|
| 47 |
-
timeout: float = 30.0,
|
| 48 |
-
):
|
| 49 |
-
ep = ProxyEndpoint.from_env()
|
| 50 |
-
proc = subprocess.Popen(
|
| 51 |
-
[binary, "--config", str(config_path)],
|
| 52 |
-
stdout=subprocess.PIPE,
|
| 53 |
-
stderr=subprocess.STDOUT,
|
| 54 |
-
)
|
| 55 |
-
try:
|
| 56 |
-
wait_until_ready(ep, timeout=timeout)
|
| 57 |
-
yield ep
|
| 58 |
-
finally:
|
| 59 |
-
proc.terminate()
|
| 60 |
-
try:
|
| 61 |
-
proc.wait(timeout=5)
|
| 62 |
-
except subprocess.TimeoutExpired:
|
| 63 |
-
proc.kill()
|
|
|
|
| 1 |
+
"""TCP-probe the CLIProxyAPI port. Endpoint-agnostic β works regardless of
|
| 2 |
+
which protocol surfaces (Anthropic / OpenAI / Gemini) the proxy version
|
| 3 |
+
exposes."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
|
|
|
|
| 7 |
import socket
|
|
|
|
| 8 |
import time
|
|
|
|
| 9 |
|
| 10 |
from .endpoint import ProxyEndpoint
|
| 11 |
|
|
|
|
| 29 |
f"Start it (e.g. `cliproxy --config ~/.cli-proxy-api/config.yaml`) "
|
| 30 |
f"and confirm CLIPROXYAPI_HOST / CLIPROXYAPI_PORT."
|
| 31 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|