Skip to content

Commit 0f47bdc

Browse files
feat(harness): deployable Harness server + veadk harness CLI (create/add/show/deploy/invoke), with OAuth2/JWT deploy (#603)
* feat(harness): accept a runtime parameter (adk default, codex) The Harness model now carries a `runtime` field (Literal["adk","codex"], default "adk") passed through to the Agent, so a deployed Harness server can run an agent on the codex runtime. Exposed on the CLI via `--runtime` on both `harness add` and `harness invoke` (one-time override). Docs + example updated. * feat(harness): add deployable harness_app package and `veadk harness` CLI - veadk/cloud/harness_app/: env-assembled agent + FastAPI harness server (/harness/invoke with clone-based once-time overrides; incremental, deduped tools/skills; per-invoke skill temp-dir cleanup) - veadk harness create/deploy/invoke; deploy builds the image via AgentKit and creates an AgentKit runtime (Name=HARNESS_NAME, tag "Harness") - invoke override flags are generated from HarnessOverrides - replaces the single-file veadk/cloud/harness_app.py * feat(harness): layered harness.yaml config + env_mapping; redesign create/add/deploy - harness.yaml (layered, per-component) is the agent spec; env_mapping.to_runtime_env reuses veadk flatten_dict for generic fields and maps each component's backend connection params to the veadk DATABASE_* env vars the backend reads - veadk harness create/add/deploy: create scaffolds harness.yaml + .env.example (AK/SK only) + domestic-source Dockerfile; add edits harness.yaml; deploy builds the image on AgentKit cloud and creates a runtime via sdk.launch - runtime env names aligned (MODEL_NAME / KNOWLEDGE_BASE_TYPE / LONG_TERM_MEMORY_TYPE / SHORT_TERM_MEMORY_TYPE) * feat(harness): full-commented harness.yaml template; deploy prints apikey + invoke cmd; add --path takes a dir - create's harness.yaml now documents every component's supported backends and their connection params as comments (uncomment for your chosen type) - deploy surfaces the created runtime's id / endpoint / api key and a ready-to-run invoke command (from the deploy result's config_updates) - harness add --path now takes the harness directory (consistent with deploy); setting a component type preserves its existing connection params * fix(harness): read deploy runtime apikey/endpoint from deploy_result.metadata * feat(harness): 'harness add --set KEY=VALUE' writes nested params into harness.yaml Lets users fill backend connection params from the CLI, e.g. veadk harness add --long-term-memory-type viking \ --set long_term_memory.project=my-proj --set long_term_memory.region=cn-beijing Values are parsed as YAML scalars (ints/bools stay typed); deploy maps them to the veadk DATABASE_* env vars. * feat(harness): explicit per-component connection flags for 'harness add' Replace the generic '--set KEY=VALUE' with explicit flags in the same style as '--short-term-memory-type', e.g. --long-term-memory-project, --short-term-memory-host. Flags are auto-generated from env_mapping.COMPONENT_BACKENDS so they stay in sync with the backends; values are written under the matching component section and mapped to the veadk DATABASE_* env vars on deploy. * feat(harness): unify add/invoke flags, knowledgebase rename, cleaner harness.yaml - add reuses invoke's HarnessOverrides-generated flags (--model-name/--tools/ --skills/--system-prompt/--runtime identical in both); --tools/--skills are comma-separated; --name (alias --harness-name) for the harness name; invoke also accepts --name - rename component knowledge_base -> knowledgebase (env KNOWLEDGEBASE_TYPE) - add writes connection params via explicit --<component>-<param> flags - add output: inline-style lists, and drop unset components (knowledgebase / long_term_memory); short_term_memory always shown - create's harness.yaml annotates each field with its env var + add flag - register demo tools (get_city_weather / get_location_weather) as built-ins * feat(harness): deploy records harness.json; invoke resolves url/key from it + --message - deploy writes/updates ./harness.json: {name: {url, key, runtime_id}} - invoke takes --name (reads url/key from harness.json), --message/-m (or positional); --url/--key optional overrides; --path for harness.json location * feat(harness): add 'veadk harness show' (configured agent params + overridable flags) * docs(harness): rewrite CLI reference for current create/add/show/deploy/invoke flow The reference still described the removed server-side `/harness/add` registration and the old `--harness/--url/--key` invoke design. Rewrite it around the current `veadk harness` flow: layered harness.yaml (knowledgebase/KNOWLEDGEBASE_TYPE), comma-separated --tools/--skills, per-component connection flags, deploy writing harness.json, and invoke resolving url/key by --name. * test(harness): fix contract tests for redesigned harness_app API The contract tests still imported the removed `/harness/add` design (`AddHarnessRequest`/`AddHarnessResponse`/`Harness`/`_split_csv`), so the module failed to import. Rewrite against the current schemas: HarnessOverrides (per-call overridable) vs HarnessConfig (creation-time, with memory/kb), the InvokeHarness request/response models, and split_csv. * refactor(harness): remove dead 'veadk agentkit harness add' command The server (harness_app) no longer exposes /harness/add — agents are assembled from env at deploy time, not registered at runtime — so the client 'add' command posted to a route that 404s. Remove it (and its contract tests); keep the working 'invoke' client and the shared _harness_request helper. * docs(examples): rewrite #14 harness example for the veadk harness flow The example documented the removed /harness/add registration, the old `agentkit config --entry_point ...` deploy flow, and `python -m veadk.cloud.harness_app` (now a package, no __main__). Rewrite both READMEs around create -> add -> deploy -> invoke with harness.json, and drop the orphaned .env.example / requirements.txt (the scaffold is now generated by `veadk harness create`). * feat(harness): add OAuth2/JWT (custom_jwt) deploy option An `auth` block in harness.yaml (or --discovery-url / --allowed-id on deploy) switches the runtime gateway to custom_jwt: it admits only JWTs issued by the user pool at `discovery_url` whose audience is in `allowed_ids`. Absent an `auth` block, deploy keeps the existing key_auth path unchanged. The auth block is excluded from the flattened runtime env (it configures the gateway authorizer, not the container). No secret is involved — the user pool / client / external IdP are set up in the Volcengine Identity console and the CLI only references discovery_url + allowed_ids. custom_jwt deploys record {url, runtime_id, auth_type, discovery_url, allowed_ids} in harness.json. Verified end-to-end against a real user pool: deploy -> runtime Ready with a custom_jwt authorizer carrying the given discovery_url + allowed_clients, no key_auth. Docs (zh/en) updated.
1 parent b7038b8 commit 0f47bdc

20 files changed

Lines changed: 2231 additions & 702 deletions
Lines changed: 175 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,219 @@
11
---
22
title: "Harness Commands"
3-
description: "Register and invoke harnesses (agent specs) on a deployed Harness server from the CLI."
3+
description: "Scaffold, configure, deploy, and invoke a VeADK Harness server."
44
---
55

6-
`veadk agentkit harness` is a thin set of HTTP client commands for a deployed
7-
**Harness server** (`veadk.cloud.harness_app`).
6+
`veadk harness` is a group of commands to **scaffold, configure, deploy, and invoke** a VeADK **Harness server** (`veadk.cloud.harness_app`).
87

9-
A *harness* is a named agent spec — **model + system prompt + tools + skills**.
10-
The Harness server exposes `/harness/add` and `/harness/invoke`, letting you
11-
register and invoke harnesses at runtime without redeploying.
8+
A *harness* is an agent specification — **model + system prompt + tools + skills**, plus a knowledge base and long/short-term memory bound at creation time. The whole spec is described by a layered `harness.yaml`; `deploy` flattens it into the runtime's environment variables, the Harness server assembles an agent from them at startup, and serves it over `POST /harness/invoke`.
129

1310
<Callout type="info">
14-
Before you start, deploy the Harness server to Volcengine AgentKit (see the
15-
[`14_harness_server_on_agentkit`](https://github.com/volcengine/veadk-python/tree/main/examples/14_harness_server_on_agentkit)
16-
example) and grab its **endpoint URL** and gateway **API key**.
11+
Deploying requires Volcengine AgentKit credentials (`VOLCENGINE_ACCESS_KEY` / `VOLCENGINE_SECRET_KEY`). For an end-to-end example see [`14_harness_server_on_agentkit`](https://github.com/volcengine/veadk-python/tree/main/examples/14_harness_server_on_agentkit).
1712
</Callout>
1813

19-
## Command reference
14+
## Commands at a glance
2015

2116
| Command | Description |
2217
| :-- | :-- |
23-
| `veadk agentkit harness add` | Register a new harness on the server. |
24-
| `veadk agentkit harness invoke` | Invoke a harness and print its output. |
18+
| `veadk harness create <dir>` | Scaffold a deployable harness directory. |
19+
| `veadk harness add` | Write agent parameters into `harness.yaml`. |
20+
| `veadk harness show` | Show configured params and the per-invoke overridable params. |
21+
| `veadk harness deploy` | Cloud-build the image and create an AgentKit runtime (no local Docker). |
22+
| `veadk harness invoke` | Invoke a deployed harness and print its output. |
2523

26-
## Connection options
24+
Typical flow: **`create` → `add` → `deploy` → `invoke`**.
2725

28-
Both commands need the server address and auth, supplied via options or
29-
environment variables:
26+
## `veadk harness create`
3027

31-
| Option | Env var | Description |
32-
| :-- | :-- | :-- |
33-
| `--url` | `HARNESS_URL` | Harness server base URL (required). |
34-
| `--key` | `HARNESS_KEY` | Gateway API key for Bearer auth (optional). |
35-
| — | `HARNESS_TIMEOUT` | Client request timeout in seconds, default `600` (agent runs can be slow). |
28+
Scaffold a deployment directory:
29+
30+
```bash
31+
veadk harness create my-harness
32+
```
33+
34+
It writes:
35+
36+
- `harness.yaml` — the agent config template (see below).
37+
- `.env.example` — Volcengine deploy credentials only (`VOLCENGINE_ACCESS_KEY`, `VOLCENGINE_SECRET_KEY`, and optional `VOLCENGINE_REGION`). Model/agent config lives in `harness.yaml`.
38+
- `Dockerfile` — builds the harness server image.
39+
- `README.md` — quick-start notes.
40+
41+
### `harness.yaml`
42+
43+
A layered, self-contained-per-component config. `deploy` converts it into the runtime's environment variables: top-level fields and `model` are flattened (`model.name` → `MODEL_NAME`, `tools` → `TOOLS`, …) with lists comma-joined; each component's `type` selects its backend, and the component's other params map to the VeADK env vars that backend actually reads (e.g. viking `project` → `DATABASE_VIKING_PROJECT`). Empty values are skipped, so VeADK falls back to its own defaults.
44+
45+
```yaml
46+
harness_name: "" # -> HARNESS_NAME (runtime name + knowledgebase/long-term-memory index name)
47+
model:
48+
name: "" # -> MODEL_NAME (Ark auth is resolved by the runtime's IAM role after deploy)
49+
tools: [] # -> TOOLS (comma-joined)
50+
skills: [] # -> SKILLS (comma-joined)
51+
system_prompt: "" # -> SYSTEM_PROMPT (empty = VeADK default)
52+
runtime: adk # -> RUNTIME ("adk" or "codex")
53+
knowledgebase:
54+
type: "" # -> KNOWLEDGEBASE_TYPE (empty = not created)
55+
long_term_memory:
56+
type: "" # -> LONG_TERM_MEMORY_TYPE (empty = not created)
57+
short_term_memory:
58+
type: local # -> SHORT_TERM_MEMORY_TYPE
59+
```
3660
37-
## `harness add`
61+
Under each component, uncomment the params for the backend you set as `type` (the template annotates the env var and CLI flag for every field). On an AgentKit runtime Ark auth is resolved by the IAM role, so the model needs no API key here.
3862

39-
Register a named harness on the server.
63+
## `veadk harness add`
64+
65+
Write agent parameters into `./harness.yaml` (or the directory given by `--path`). Fails fast if `harness.yaml` does not exist.
4066

4167
```bash
42-
veadk agentkit harness add \
68+
cd my-harness
69+
veadk harness add \
4370
--name research-agent \
4471
--model-name doubao-seed-1-6-250615 \
4572
--system-prompt "You are a research assistant." \
4673
--tools web_search,web_fetch \
47-
--url "<ENDPOINT>" --key "<API_KEY>"
74+
--runtime adk
75+
```
76+
77+
| Option | Description |
78+
| :-- | :-- |
79+
| `--name` / `--harness-name` | Logical harness / runtime name (sets `harness_name`). |
80+
| `--model-name` | Reasoning model name (sets `model.name`). |
81+
| `--tools` | Comma-separated built-in tool names, e.g. `web_search,web_fetch` (sets `tools`). |
82+
| `--skills` | Comma-separated skill hub names (sets `skills`). |
83+
| `--system-prompt` | System prompt / instruction. |
84+
| `--runtime` | Agent runtime, `adk` (default) or `codex`. |
85+
| `--knowledgebase-type` | Knowledge base backend (sets `knowledgebase.type`). |
86+
| `--long-term-memory-type` | Long-term memory backend (sets `long_term_memory.type`). |
87+
| `--short-term-memory-type` | Short-term memory backend (sets `short_term_memory.type`). |
88+
| `--path` | Directory containing `harness.yaml`, default `.`. |
89+
90+
#### Component connection params
91+
92+
Each component also auto-generates `--<component>-<param>` connection flags for the backends it supports, e.g.:
93+
94+
```bash
95+
veadk harness add --name kb-agent \
96+
--knowledgebase-type viking \
97+
--knowledgebase-project my-project --knowledgebase-region cn-beijing
98+
```
99+
100+
| Component prefix | Available flags (depend on backend) |
101+
| :-- | :-- |
102+
| `--knowledgebase-*` | `project` / `region` (viking); `host` / `port` / `username` / `password` / `use-ssl` / `cert-path` / `secret-token` (opensearch); `host` / `port` / `username` / `password` / `db` (redis) |
103+
| `--long-term-memory-*` | the same per-backend params, plus `api-key` / `api-key-id` / `project-id` / `base-url` (mem0) |
104+
| `--short-term-memory-*` | `host` / `user` / `password` / `database` / `charset` / `port` (mysql / postgresql) |
105+
106+
Credentials (access key / secret key) are not passed via these flags; they reuse the `VOLCENGINE_*` values from the deploy `.env`.
107+
108+
## `veadk harness show`
109+
110+
Print the params configured in `harness.yaml`, plus the params overridable per invocation. Fails fast if `harness.yaml` does not exist.
111+
112+
```bash
113+
veadk harness show --path my-harness
114+
```
115+
116+
It prints two sections:
117+
118+
1. **Configured agent params** — the contents of `harness.yaml` (`harness_name`, `model`, `tools`, `skills`, `system_prompt`, `runtime`, and any configured `knowledgebase` / `long_term_memory` / `short_term_memory`).
119+
2. **Overridable at invoke time** — each `--<flag>` derived from `HarnessOverrides` (`--model-name`, `--tools`, `--skills`, `--system-prompt`, `--runtime`) and its description. Memory and the knowledge base are **not** overridable.
120+
121+
| Option | Description |
122+
| :-- | :-- |
123+
| `--path` | Directory containing `harness.yaml`, default `.`. |
124+
125+
## `veadk harness deploy`
126+
127+
With deploy credentials in place, run inside the directory:
128+
129+
```bash
130+
cd my-harness
131+
cp .env.example .env # then set VOLCENGINE_ACCESS_KEY / VOLCENGINE_SECRET_KEY
132+
veadk harness deploy
48133
```
49134

50135
| Option | Required | Description |
51136
| :-- | :-- | :-- |
52-
| `--name` | Yes | Harness (agent) name. |
53-
| `--model-name` | No | Model name; defaults to the server's `MODEL_AGENT_NAME`. |
54-
| `--system-prompt` | No | System prompt; defaults to `You are a helpful assistant.`. |
55-
| `--tools` | No | Comma-separated built-in tool names, e.g. `web_search,web_fetch`. |
56-
| `--skills` | No | Comma-separated skill hub names, e.g. `clawhub/lgwventrue/system-file-handler`. |
57-
58-
<Callout type="warn">
59-
If a harness with the same name already exists, the server returns `code: 400`
60-
and does not overwrite it.
61-
</Callout>
137+
| `--volcengine-access-key` | No | Volcengine access key (defaults to `VOLCENGINE_ACCESS_KEY`). |
138+
| `--volcengine-secret-key` | No | Volcengine secret key (defaults to `VOLCENGINE_SECRET_KEY`). |
139+
| `--region` | No | AgentKit region (defaults to `cn-beijing` or `VOLCENGINE_REGION`). |
140+
| `--path` | No | Harness directory, default `.`. |
141+
| `--discovery-url` | No | OIDC discovery URL; enables OAuth2/JWT auth (overrides `auth.discovery_url`). |
142+
| `--allowed-id` | No | Comma-separated allowed client IDs for OAuth2/JWT auth (overrides `auth.allowed_ids`). |
143+
144+
`deploy` loads `harness.yaml`, flattens it into the runtime environment, runs an AgentKit **cloud** build (no local Docker), and creates the runtime. The runtime is named after `harness_name`.
62145

63-
## `harness invoke`
146+
On success the endpoint and gateway API key are recorded into **`harness.json`** in the directory (shape `{name: {url, key, runtime_id}}`), so you can invoke it with `veadk harness invoke --name <name>` without copying the URL / key by hand:
64147

65-
Invoke an **already-registered** harness and print its output. The message is a
66-
positional argument.
148+
```text
149+
Harness runtime deployed: name=research-agent
150+
Runtime id: r-xxxx
151+
Endpoint: https://xxxx.apigateway-cn-beijing.volceapi.com
152+
API key: ****
153+
154+
Recorded in .../harness.json. Invoke it with:
155+
veadk harness invoke --name research-agent --message "<message>"
156+
```
157+
158+
### OAuth2 / JWT auth deploy (optional)
159+
160+
By default the gateway uses an API key (key_auth). To gate the runtime with
161+
OAuth2/JWT backed by a **Volcengine Identity user pool**, add an `auth` block to
162+
`harness.yaml` — **its presence switches to custom_jwt; without it, the default
163+
key_auth is used**:
164+
165+
```yaml
166+
auth:
167+
discovery_url: "https://userpool-<pool-id>.userpool.auth.id.cn-beijing.volces.com/.well-known/openid-configuration"
168+
allowed_ids: ["<client-id>"] # a client created in the console; the gateway only admits tokens whose aud matches
169+
```
170+
171+
You can also override it at deploy time with `--discovery-url` / `--allowed-id`.
172+
The `auth` block is **not** written into the container environment — it only
173+
configures the runtime's gateway authorizer.
174+
175+
- The user pool, client, and external IdP (e.g. Feishu) are set up once in the
176+
**Identity console**; the CLI only references `discovery_url` + `allowed_ids`
177+
and **never touches a secret**.
178+
- A custom_jwt deploy records `{url, runtime_id, auth_type, discovery_url, allowed_ids}`
179+
in `harness.json` (no key). Calling such a runtime requires your own
180+
`Authorization: Bearer <user-pool JWT>` header — the CLI does not mint it.
181+
182+
## `veadk harness invoke`
183+
184+
Invoke a **deployed** harness and print its output. The `url` and `key` are resolved from `harness.json` (written by `deploy`) by `--name`, so you need not pass them explicitly.
67185

68186
```bash
69-
veadk agentkit harness invoke \
70-
--harness research-agent \
71-
--url "<ENDPOINT>" --key "<API_KEY>" \
72-
"Summarize the latest on reinforcement learning."
187+
veadk harness invoke --name research-agent --message "Summarize recent progress in RL."
73188
```
74189

190+
The message may be given via `--message` / `-m` or as a positional argument.
191+
75192
| Option | Required | Description |
76193
| :-- | :-- | :-- |
77-
| `MESSAGE` (positional) | Yes | The message to send to the harness. |
78-
| `--harness` | Yes | Harness name to invoke. |
194+
| `--name` / `--harness` | Yes | Harness name; its `url`/`key` are read from `harness.json`. |
195+
| `MESSAGE` (positional) or `--message` / `-m` | Yes | The message to send to the harness. |
79196
| `--user-id` | No | User id for the session, default `cli-user`. |
80-
| `--session-id` | No | Session id for the call, default `cli-session`. |
81-
| `--model-name` | No | Override the model for this call only (creates a one-time harness). |
82-
| `--system-prompt` | No | Override the system prompt for this call only (creates a one-time harness). |
83-
| `--tools` | No | Override tools for this call only, comma-separated (creates a one-time harness). |
84-
| `--skills` | No | Override skills for this call only, comma-separated (creates a one-time harness). |
197+
| `--session-id` | No | Session id for the call. |
198+
| `--url` | No | Harness URL (default `harness.json[name]`, or `HARNESS_URL`). |
199+
| `--key` | No | API key for Bearer auth (default `harness.json[name]`, or `HARNESS_KEY`). |
200+
| `--path` | No | Directory containing `harness.json`, default `.`. |
201+
| `--model-name` | No | Override the model for this call only. |
202+
| `--tools` | No | Override tools for this call only (comma-separated). |
203+
| `--skills` | No | Override skills for this call only (comma-separated). |
204+
| `--system-prompt` | No | Override the system prompt for this call only. |
205+
| `--runtime` | No | Override the runtime for this call only (`adk` / `codex`). |
85206

86-
### One-time harness override
207+
### Once-time overrides
87208

88-
If any of `--model-name` / `--system-prompt` / `--tools` / `--skills` is passed
89-
to `invoke`, the server builds a **one-time harness** from those fields that
90-
applies to this single call only — the stored harness of the same name is left
91-
untouched:
209+
If any of `--model-name` / `--tools` / `--skills` / `--system-prompt` / `--runtime` is given, the server clones the deployed agent and applies the overrides **for that single call only**: tools and skills are added **incrementally** (deduped against existing ones), while memory and the knowledge base are **never** overridable.
92210

93211
```bash
94-
veadk agentkit harness invoke \
95-
--harness research-agent \
96-
--system-prompt "Answer in one sentence." \
97-
--url "<ENDPOINT>" --key "<API_KEY>" \
98-
"What is reinforcement learning?"
212+
veadk harness invoke --name research-agent \
213+
--tools get_city_weather \
214+
--message "What's the weather in Beijing today?"
99215
```
100216

101217
## Full example
102218

103-
For the end-to-end deploy-and-invoke flow (including the `curl` equivalents),
104-
see the [`14_harness_server_on_agentkit`](https://github.com/volcengine/veadk-python/tree/main/examples/14_harness_server_on_agentkit)
105-
example.
219+
For the end-to-end deploy-and-invoke flow (with `curl` equivalents) see the example [`14_harness_server_on_agentkit`](https://github.com/volcengine/veadk-python/tree/main/examples/14_harness_server_on_agentkit).

0 commit comments

Comments
 (0)