File size: 10,012 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# A2A agent

**Audience:** developers connecting their own agent to Patchwise (for example an agent that crawls a pod's modules and
versions and Oracle's patch updates), and the administrators who look after it.

Patchwise is an [A2A](https://a2a-protocol.org) agent (protocol 0.3, JSON-RPC 2.0 over HTTP, with server-sent events
for streaming). Your agent can send what it found about a pod and a patch, have Patchwise design and run tests, send its
own test cases, follow progress, and fetch the report.

- **Agent card:** `https://<your-patchwise-host>/.well-known/agent-card.json` (public, no secrets)
- **Endpoint:** `POST https://<your-patchwise-host>/a2a`
- **Auth:** `Authorization: Bearer pwt_…`, a personal access token from **Account → Access tokens for AI assistants**
  (the same tokens as the [MCP connector](MCP.md)). Use `read` to look, `read,act` to design or run tests. The token's
  owner's current role applies, so use an account whose role can start runs (consultant or above).

## The rule: a person always decides

- Starting anything is two steps. The first message returns a task in state `input-required` with a proposal. Your
  agent starts it with a follow-up message `{"confirm": true}` (or the text `confirm`) **on the same task**, with the
  same token. Role, run state and the emergency stop are checked again then. A proposal is single use and expires after
  10 minutes.
- Your own test cases are scripted and dry-run, then a **person approves them in Patchwise**. Your agent cannot approve
  them, by any message. When a person has approved some, `{"confirm": true}` runs the approved ones.
- Scenario reviews, failure decisions, sign-off, waivers, the emergency stop and administration never happen through
  A2A. When a run waits for one of them, the task says so with a link.

## Skills

| Skill | Scope | Input | Result |
|---|---|---|---|
| `assess-readiness` | read | DataPart `{area?, patch?}` or text ("Is Procure-to-Pay ready for 26C?") | `completed`, artifact `readiness` (text + data) |
| `design-tests` | read,act | DataPart `{pod: {...}, patch: {id, changes: [{area, description, source_url?}]}, areas?, mode?, environment?}` | `input-required` with a proposal; confirm → follows the run |
| `test-these-cases` | read,act | DataPart `{cases: [...], environment?}` ([case format](CUSTOM_CASES.md), at most 50) | `working` (scripts + dry run), then `input-required` until a person approves; confirm → follows the run |
| `run-tests` | read,act | DataPart `{area or areas, mode?: quick\|browser, environment?, patch?}` or text | `input-required` with a proposal; confirm → follows the run |
| `get-report` | read | DataPart `{run_id}` | `completed`, artifact `report`: text, data (verdict, QA rule result, counts, exit criteria, links) and the PDF as a FilePart |

Choose the skill with `message.metadata.skill` or a `"skill"` field in the first DataPart. Without one, Patchwise guesses
from the data (`cases` → test-these-cases, `pod`/`patch` → design-tests, `run_id` → get-report) or from the text
(the same rules as Ask); anything else gets a reply listing the skills.

**About your facts.** In `design-tests`, the pod and patch details are stored on the task as data and shown back. They
are never given to an AI model as instructions, and URLs are displayed only, never fetched. Patchwise's own test
designer chooses the scenarios for the business areas named in `changes`; a patch `id` in Oracle's release form
(`26C`) is passed on to its research, other ids are only recorded.

**Areas** are Patchwise's business areas: `P2P` (Procure-to-Pay), `O2C`, `R2R`, `A2R`, `EXP`, or a name that clearly
means one of them ("Payables" → Procure-to-Pay).

## Task states

| State | Meaning |
|---|---|
| `working` | scripts are being built and dry-run, or the test run is going (status text says which step) |
| `input-required` | waiting for your confirm, or for a person in Patchwise (status text has the link) |
| `completed` | done; for a run, the `report` artifact is attached |
| `failed` | the run stopped with an error or the emergency stop, or a confirm was refused |
| `canceled` | `tasks/cancel`, or the run was cancelled in Patchwise |
| `rejected` | the request can't be done with this token, role or input |

Tasks are visible only to their owner (administrators can read them). Only the token that made a task can continue or
cancel it. `tasks/cancel` drops a proposal, or cancels the task's run if your account started it and may cancel runs.

## Methods

`message/send`, `message/stream`, `tasks/get` (with `historyLength`), `tasks/cancel`, `tasks/resubscribe`. Push
notifications are not supported (`-32003`): poll `tasks/get` or stream. Errors: `-32001` task not found, `-32002` not
cancelable, `-32004` the task is finished (start a new one), `-32602` invalid input.

Limits: 256 KB per request, 20 parts per message, 8,000 characters of text, 50 cases, 60 requests a minute per token
(shared with `/mcp`). A stream ends at `input-required` or a final state (`final: true`), or after 10 minutes.

## Examples

Propose a run from your crawler's findings:

```json

{"jsonrpc": "2.0", "id": 1, "method": "message/send", "params": {"message": {

  "role": "user", "messageId": "c1b2", "metadata": {"skill": "design-tests"},

  "parts": [{"kind": "data", "data": {

    "pod": {"name": "DEV2", "modules": ["Payables", "Purchasing"], "versions": {"fusion": "26B"}},

    "patch": {"id": "26C", "changes": [

      {"area": "Payables", "description": "Invoice validation holds changed", "source_url": "https://docs.oracle.com/..."},

      {"area": "Procure-to-Pay", "description": "Requisition approval routing changed"}]},

    "mode": "quick"}}]}}}

```

Answer (abridged):

```json

{"jsonrpc": "2.0", "id": 1, "result": {"kind": "task", "id": "Fy-tKSkqvf-ZgPee", "contextId": "68aa…",

  "status": {"state": "input-required", "message": {"role": "agent", "parts": [{"kind": "text",

    "text": "I will start a quick simulation of Procure-to-Pay on DEV2. … Reply {\"confirm\": true} on this task …"}]}},

  "artifacts": [{"artifactId": "proposal", "parts": [{"kind": "data", "data": {"summary": "…", "items": […], "expires_at": "…"}}]}],

  "metadata": {"skill": "design-tests", "run_id": null, "batch_id": null}}}

```

Send your own cases:

```json

{"role": "user", "messageId": "c1b3", "parts": [{"kind": "data", "data": {"skill": "test-these-cases",

  "cases": [{"title": "Invoice with a line", "area": "AP", "priority": "P2",

             "steps": [{"action": "Open Payables > Invoices > Create Invoice"}, {"action": "Add line 50"},

                       {"action": "Click Save and Close"}]}]}}]}

```

The task's `cases` artifact shows each case's state (`dry_run_passed`, `not_scriptable`, `dry_run_failed`, `approved`,
`rejected`) and the status text links the person to the approval page.

### Python client (httpx)

```python

import json, os, time

import httpx



BASE = "https://patchwise.example.com"

H = {"Authorization": f"Bearer {os.environ['PATCHWISE_TOKEN']}"}   # pwt_…, read,act





def rpc(method, params):

    r = httpx.post(f"{BASE}/a2a", json={"jsonrpc": "2.0", "id": 1, "method": method, "params": params}, headers=H, timeout=60)

    r.raise_for_status()

    body = r.json()

    if "error" in body:

        raise RuntimeError(body["error"])

    return body["result"]





def say(task):

    msg = task["status"].get("message") or {}

    return " ".join(p.get("text", "") for p in msg.get("parts", []))





# 1. propose from the crawler's findings

task = rpc("message/send", {"message": {"role": "user", "messageId": "m1", "parts": [{"kind": "data", "data": {

    "skill": "design-tests", "patch": {"id": "26C", "changes": [{"area": "Payables", "description": "Holds changed"}]}}}]}})

print(task["status"]["state"], say(task))          # input-required + the proposal



# 2. a person on your side agrees, then confirm on the same task

task = rpc("message/send", {"message": {"role": "user", "messageId": "m2", "taskId": task["id"],

                                        "parts": [{"kind": "data", "data": {"confirm": True}}]}})



# 3. poll until it needs a person or finishes

while task["status"]["state"] == "working":

    time.sleep(15)

    task = rpc("tasks/get", {"id": task["id"], "historyLength": 0})

print(task["status"]["state"], say(task))           # e.g. input-required: "Waiting for a person to approve the scenarios …"



# 4. or stream the updates (server-sent events)

with httpx.stream("POST", f"{BASE}/a2a", headers=H, timeout=None, json={

        "jsonrpc": "2.0", "id": 2, "method": "tasks/resubscribe", "params": {"id": task["id"]}}) as r:

    for line in r.iter_lines():

        if line.startswith("data:"):

            event = json.loads(line[5:])["result"]

            print(event["kind"], event.get("status", {}).get("state"))

            if event.get("final"):

                break



# 5. the report, once completed

if task["status"]["state"] == "completed":

    report = next(a for a in task["artifacts"] if a["artifactId"] == "report")

    print(report["parts"][0]["text"])

```

## How a crawler agent should use it

1. After each crawl, call `assess-readiness` (read token) to see where things stand.
2. When the crawler finds a patch or pod change, call `design-tests` with the facts. Show the proposal to whoever owns
   the crawler, or follow your own policy, then confirm. Keep the `taskId`.
3. When you have specific cases (from tickets, past incidents or your own analysis), call `test-these-cases`. Poll or
   stream the task: it waits at `input-required` until someone approves the cases in Patchwise; then confirm.
4. Follow each task until `completed`, then read its `report` artifact (or call `get-report` with the `run_id`). The PDF
   link opens for a signed-in Patchwise user; sign-off happens in Patchwise.