You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Short, runnable patterns for **`apiVersion: agentic.dev/v0`**. For the full YAML spec, CLI behaviour, and field semantics, see [**`design_doc.md`**](design_doc.md).
3
+
Short, runnable patterns for **`apiVersion: agentic.dev/v0`**. For the full YAML spec, CLI behaviour, and field semantics, see [**`DESIGN_DOC.md`**](DESIGN_DOC.md).
4
+
5
+
A checked-in copy of the **OpenAI `support_snippet`** project from **section 4** lives under [**`examples/example1/`**](../examples/example1/). Its **`metadata.name`** is **`example1`**, matching that folder. From the repository root, pass **`--project examples/example1`** to **`agentctl`** (or **`cd` there** and use **`--project .`**).
4
6
5
7
---
6
8
@@ -20,7 +22,7 @@ my-agent-system/
20
22
workflows/hello.yaml
21
23
```
22
24
23
-
The generated files match the snippets in sections 2–4 below (with `metadata.name` set from the argument you pass to `init`).
25
+
Sections **2–3** mirror what `init` creates. **Section 4** is a separate **`gpt-4o-mini`** project layout you can copy beside or instead of the scaffold.
24
26
25
27
---
26
28
@@ -102,23 +104,42 @@ agentctl run workflow/hello --project my-agent-system
102
104
103
105
---
104
106
105
-
## 4. OpenAI chat (real model)
107
+
## 4. Real OpenAI example (`gpt-4o-mini`)
108
+
109
+
This is a small but **end-to-end** project: a **native echo** step supplies fixed “policy” text, then **`gpt-4o-mini`** drafts a one-line customer reply. You need a valid **[OpenAI API key](https://platform.openai.com/api-keys)** and outbound **HTTPS** to `api.openai.com`.
110
+
111
+
**Repo copy:** [**`examples/example1/`**](../examples/example1/) — **`agentctl validate --project examples/example1`** from the repo root, or **`agentctl validate --project .`** after **`cd examples/example1`**.
112
+
113
+
The runtime calls OpenAI’s **`/v1/chat/completions`** endpoint. The agent **must** answer with a **single JSON object** (no markdown fences); the engine parses that object and exposes its fields to **`spec.output`**.
114
+
115
+
**`totalCostUsd` on runs** is accumulated from each step’s reported cost. Native tools report **0**. For **OpenAI**, the client estimates USD from the API **`usage`** token counts × approximate per-million rates for known models (**`gpt-4o-mini`**, **`gpt-4o`**, and dated variants such as **`gpt-4o-mini-…`**). Other model ids stay at **0** until their rates are added in code; see **`internal/models/openai_cost.go`** and verify against [OpenAI pricing](https://openai.com/api/pricing/).
116
+
117
+
### Layout
106
118
107
-
The control plane currently wires **`type: openai`** to the OpenAI **`/v1/chat/completions`** API. Set a key via **`apiKeyFrom`** (MVP: **`env:VAR`** only).
119
+
```text
120
+
example1/
121
+
project.yaml
122
+
policies/default.yaml
123
+
tools/helper.yaml
124
+
agents/support_writer.yaml
125
+
workflows/support_snippet.yaml
126
+
```
108
127
109
-
**`project.yaml`** (add an `openai` provider and point defaults at an OpenAI model id):
128
+
Reuse **`policies/default.yaml`** and **`tools/helper.yaml`** from **section 3** unchanged.
129
+
130
+
### `project.yaml`
110
131
111
132
```yaml
112
133
apiVersion: agentic.dev/v0
113
134
kind: Project
114
135
metadata:
115
-
name: my-agent-system
136
+
name: example1
116
137
spec:
117
138
imports:
118
139
- ./policies/default.yaml
119
140
- ./tools/helper.yaml
120
-
- ./agents/assistant.yaml
121
-
- ./workflows/chat.yaml
141
+
- ./agents/support_writer.yaml
142
+
- ./workflows/support_snippet.yaml
122
143
defaults:
123
144
policy: default
124
145
model: openai/gpt-4o-mini
@@ -131,46 +152,112 @@ spec:
131
152
apiKeyFrom: env:OPENAI_API_KEY
132
153
```
133
154
134
-
```bash
135
-
export OPENAI_API_KEY="sk-..." # required before validate/plan/apply/run
136
-
```
155
+
### `agents/support_writer.yaml`
137
156
138
-
**`agents/assistant.yaml`** — `metadata.name` is what workflow steps reference in **`agent:`**. The executor expects the model’s reply to be a **JSON object** (plain text, not fenced code blocks).
157
+
`metadata.name`is the value you use in **`agent:`** on the workflow step.
139
158
140
159
```yaml
141
160
apiVersion: agentic.dev/v0
142
161
kind: Agent
143
162
metadata:
144
-
name: assistant
163
+
name: support_writer
145
164
spec:
146
165
model: openai/gpt-4o-mini
147
166
policy: default
167
+
constraints:
168
+
timeoutSeconds: 60
148
169
instructions: |
149
-
You are a concise assistant. Respond with a single JSON object only, no markdown.
150
-
Shape: {"message": "<your reply>"}
170
+
You draft short customer-facing email lines for a storefront.
171
+
You receive JSON in the user message: product name and a return-policy line from internal systems.
172
+
Respond with one JSON object only (no markdown, no code fences).
173
+
Use exactly this shape: {"subject": "<=8 words>", "line": "<=25 words, friendly>"}
151
174
```
152
175
153
-
**`workflows/chat.yaml`**
176
+
### `workflows/support_snippet.yaml`
177
+
178
+
The compose step passes the echo step’s payload into the model via **`${steps.context.output.echo...}`** (see §13.1 in **`DESIGN_DOC.md`**).
179
+
180
+
**CLI-driven product (requires `--input`).** If you use **`${input.product}`** anywhere in the workflow, you **must** pass **`--input product=...`** on **`run`**. Otherwise interpolation fails with **`undefined path "input.product"`** because the run input object is empty.
154
181
155
182
```yaml
156
183
apiVersion: agentic.dev/v0
157
184
kind: Workflow
158
185
metadata:
159
-
name: chat
186
+
name: support_snippet
160
187
spec:
161
188
policy: default
162
189
steps:
163
-
- id: reply
164
-
agent: assistant
190
+
- id: context
191
+
uses: tool.helper.echo
192
+
with:
193
+
product: "${input.product}"
194
+
policy_line: "30-day returns on all SKUs; free outbound shipping on defects."
**Zero-argument demo.** To run **`agentctl run workflow/support_snippet`** with no **`--input`**, put a literal product on the first step and thread it through **`steps.context.output.echo`** (the checked-in [**`examples/example1/`**](../examples/example1/) tree uses **`${input.product}`** instead, so it **requires** **`--input product=...`** unless you edit the YAML):
If you copied the files to another folder, point **`--project`** at that path instead. For the [**in-repo example**](../examples/example1/), from the **repository root** use **`examples/example1`** (the directory path), not only the project name **`example1`**.
230
+
231
+
```bash
232
+
export OPENAI_API_KEY="sk-..." # required for any step that calls the model
After the trace table, the CLI prints **Workflow output (from spec.output)** as indented JSON when the run succeeded and **`output_json`** is non-empty.
251
+
252
+
Or list recent runs as JSON (includes **`output`** on each run):
253
+
169
254
```bash
170
-
agentctl run workflow/chat --project my-agent-system
255
+
agentctl logs -o json --project examples/example1
171
256
```
172
257
173
-
Optional: add **`spec.output.schema`** on the agent (path relative to project root) to validate the JSON against JSON Schema; see test fixtures under `internal/engine/testdata/` and **`design_doc.md`**.
258
+
**`agentctl logs --run <id> -o json`** also includes top-level **`input`**, **`output`**, and **`workflowName`** alongside **`events`**.
259
+
260
+
Optional: add **`spec.output.schema`** on the agent (path relative to the project root) so replies are validated with JSON Schema; see `internal/engine/testdata/wfproj/schemas/` and **`DESIGN_DOC.md`**.
0 commit comments