@harperfast/template-react-ts-studio 1.11.2 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/harper-best-practices/AGENTS.md +135 -0
- package/.agents/skills/harper-best-practices/SKILL.md +1 -0
- package/.agents/skills/harper-best-practices/rules/delegating-to-the-built-in-agent.md +141 -0
- package/.agents/skills/harper-best-practices/rules.manifest.yaml +9 -0
- package/agent/skills/harper-best-practices/AGENTS.md +135 -0
- package/agent/skills/harper-best-practices/SKILL.md +1 -0
- package/agent/skills/harper-best-practices/rules/delegating-to-the-built-in-agent.md +141 -0
- package/agent/skills/harper-best-practices/rules.manifest.yaml +9 -0
- package/package.json +1 -1
- package/skills-lock.json +1 -1
|
@@ -2621,3 +2621,138 @@ Beyond the required fixes above, Harper v5 encourages these patterns for new and
|
|
|
2621
2621
|
- Implement endpoints with `static` methods on Resources/Tables, reading request information from the request `target` argument (or from `getContext()`).
|
|
2622
2622
|
- Rely on automatic context propagation rather than threading context through every call manually; access it via `getContext()` exported from `harper`.
|
|
2623
2623
|
- Access Harper functions and APIs through the `harper` package rather than through global variables.
|
|
2624
|
+
|
|
2625
|
+
### 4.8 Delegating to the Built-in Agent
|
|
2626
|
+
|
|
2627
|
+
Harper 5.2+ ships with a **built-in agent** that runs _inside_ the server, on the main thread
|
|
2628
|
+
adjacent to the operations API. Because it runs in-process, it can do things a remote client
|
|
2629
|
+
cannot: call the operations API as RBAC-filtered tools, read and write component files under the
|
|
2630
|
+
instance's components root, attach the V8 inspector to worker threads to debug and profile them,
|
|
2631
|
+
schedule follow-up work, and consult the Harper best-practices skill. You send it a natural-language
|
|
2632
|
+
task; it runs a tool-using loop under a super_user identity and reports back.
|
|
2633
|
+
|
|
2634
|
+
#### When to Use
|
|
2635
|
+
|
|
2636
|
+
Delegate to the built-in agent when the work is best done **on the instance itself** rather than
|
|
2637
|
+
from your local client:
|
|
2638
|
+
|
|
2639
|
+
- Operating on a deployed instance in place — inspect the schema, build or adjust a component,
|
|
2640
|
+
restart, run an operation.
|
|
2641
|
+
- Debugging or profiling a running instance — attach to a worker thread, capture a CPU profile,
|
|
2642
|
+
set a logpoint.
|
|
2643
|
+
- Handing off a larger, multi-step task to an agent that already has the instance's tools,
|
|
2644
|
+
filesystem, and credentials in context.
|
|
2645
|
+
|
|
2646
|
+
Do the work in your own client instead when it's purely local (editing source before deploy) or
|
|
2647
|
+
when you don't want a server-side agent making changes.
|
|
2648
|
+
|
|
2649
|
+
**Prerequisites:** the target instance must have the agent enabled (an `agent:` config block with
|
|
2650
|
+
`enabled: true`) and a configured generative model backend. All agent operations require
|
|
2651
|
+
**super_user**.
|
|
2652
|
+
|
|
2653
|
+
#### How It Works
|
|
2654
|
+
|
|
2655
|
+
The lifecycle assumes you have already deployed to and authenticated with the target instance (see
|
|
2656
|
+
[deploying-to-harper-fabric.md](deploying-to-harper-fabric.md) — `harper login` stores a token so
|
|
2657
|
+
you don't repeat credentials). Delegation reuses that same target and credentials.
|
|
2658
|
+
|
|
2659
|
+
There are two equivalent ways to drive the agent.
|
|
2660
|
+
|
|
2661
|
+
##### Option A — the `harper agent` CLI (simplest)
|
|
2662
|
+
|
|
2663
|
+
A thin client over the agent operations API that reuses your stored `harper login` credentials, so
|
|
2664
|
+
no connector setup is needed:
|
|
2665
|
+
|
|
2666
|
+
```bash
|
|
2667
|
+
# One-shot: send a task, print the reply, exit
|
|
2668
|
+
harper agent "Describe the schema, then add a price index to the Product table."
|
|
2669
|
+
|
|
2670
|
+
# Interactive session (REPL)
|
|
2671
|
+
harper agent
|
|
2672
|
+
|
|
2673
|
+
# Against a specific remote instead of the logged-in default
|
|
2674
|
+
harper agent --target <Application URL> "List the databases and tables."
|
|
2675
|
+
```
|
|
2676
|
+
|
|
2677
|
+
The CLI polls the run to completion and renders the transcript (tool calls, results, and the
|
|
2678
|
+
agent's reply). When a run needs approval for a destructive action, it prompts you inline.
|
|
2679
|
+
|
|
2680
|
+
##### Option B — the agent operations API (programmatic)
|
|
2681
|
+
|
|
2682
|
+
Call the operations API directly (HTTP POST to the ops endpoint, super_user auth). This is the path
|
|
2683
|
+
to use from scripts and services.
|
|
2684
|
+
|
|
2685
|
+
1. **Start a task** with `agent_prompt`. Returns a `session_id` and a `status`.
|
|
2686
|
+
|
|
2687
|
+
```bash
|
|
2688
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2689
|
+
-H 'Content-Type: application/json' \
|
|
2690
|
+
-d '{"operation":"agent_prompt","message":"Build a Customer table (id, email, name) exported over REST."}'
|
|
2691
|
+
```
|
|
2692
|
+
|
|
2693
|
+
2. **Poll for progress** with `get_agent_session`, passing the `session_id`. The returned session
|
|
2694
|
+
carries the `status`, the `messages` transcript, and any `pendingApprovals`.
|
|
2695
|
+
|
|
2696
|
+
```bash
|
|
2697
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2698
|
+
-H 'Content-Type: application/json' \
|
|
2699
|
+
-d '{"operation":"get_agent_session","session_id":"<id>"}'
|
|
2700
|
+
```
|
|
2701
|
+
|
|
2702
|
+
Poll until `status` leaves `running` — terminal states are `completed`, `aborted`, and `error`;
|
|
2703
|
+
`awaiting_approval` means it is paused for an approval decision (see step 3).
|
|
2704
|
+
|
|
2705
|
+
3. **Approve or deny a paused action.** When the agent enabled configuration has `autoApprove:false`,
|
|
2706
|
+
a destructive tool call pauses the run with a `pendingApprovals[]` entry. Resolve it with
|
|
2707
|
+
`approve_agent_action`, then poll again — approval executes the saved call, denial hands the
|
|
2708
|
+
rejection back to the agent so it can adjust.
|
|
2709
|
+
|
|
2710
|
+
```bash
|
|
2711
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2712
|
+
-H 'Content-Type: application/json' \
|
|
2713
|
+
-d '{"operation":"approve_agent_action","session_id":"<id>","approval_id":"<approval-id>","approved":true}'
|
|
2714
|
+
```
|
|
2715
|
+
|
|
2716
|
+
4. **Continue the conversation** by passing the same `session_id` back into `agent_prompt` with a
|
|
2717
|
+
new `message`. Omit `session_id` to start a fresh session.
|
|
2718
|
+
|
|
2719
|
+
Supporting operations: `list_agent_sessions` (recent sessions), `cancel_agent_run` (terminate a
|
|
2720
|
+
running or paused session), and `set_agent_config` (adjust `autoApprove`, `allowDestructive`,
|
|
2721
|
+
`model`, and related settings on a running instance).
|
|
2722
|
+
|
|
2723
|
+
#### Examples
|
|
2724
|
+
|
|
2725
|
+
**Delegate a build to a deployed Fabric instance and wait for the result:**
|
|
2726
|
+
|
|
2727
|
+
```bash
|
|
2728
|
+
harper login <Application URL>
|
|
2729
|
+
harper agent --target <Application URL> \
|
|
2730
|
+
"Create a Product table (id, name, price) exported over REST, then confirm the endpoint responds."
|
|
2731
|
+
```
|
|
2732
|
+
|
|
2733
|
+
**Programmatic start-and-poll loop:**
|
|
2734
|
+
|
|
2735
|
+
```bash
|
|
2736
|
+
SID=$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
2737
|
+
-d '{"operation":"agent_prompt","message":"Add a vector index to the Document.embedding field."}' \
|
|
2738
|
+
| jq -r .session_id)
|
|
2739
|
+
|
|
2740
|
+
while [ "$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
2741
|
+
-d "{\"operation\":\"get_agent_session\",\"session_id\":\"$SID\"}" | jq -r .status)" = "running" ]; do
|
|
2742
|
+
sleep 3
|
|
2743
|
+
done
|
|
2744
|
+
```
|
|
2745
|
+
|
|
2746
|
+
#### Notes
|
|
2747
|
+
|
|
2748
|
+
- **All agent operations require super_user.** Authenticate with `harper login`, which stores a
|
|
2749
|
+
short-lived JWT (operation token) plus a refresh token rather than your password — prefer that
|
|
2750
|
+
over passing credentials inline, and never embed a raw password in scripts or client config.
|
|
2751
|
+
- **Approvals are your safety gate.** With `autoApprove:false`, the agent pauses before destructive
|
|
2752
|
+
tools (writing files, deploying, restarting) so an operator decides. Set `autoApprove:true` only
|
|
2753
|
+
when you want unattended runs.
|
|
2754
|
+
- **Sessions are single-active.** A session that is `running` or `awaiting_approval` rejects a new
|
|
2755
|
+
`agent_prompt`; resolve the approval or cancel the run first.
|
|
2756
|
+
- **MCP alternative.** For MCP-native clients, an instance with MCP enabled exposes the agent as
|
|
2757
|
+
curated MCP tools (`agent_prompt`, `get_agent_session`, `list_agent_sessions`) at the ops API's
|
|
2758
|
+
`/mcp` endpoint — the same delegation loop over the MCP transport instead of raw operations.
|
|
@@ -84,6 +84,7 @@ See the concrete examples embedded in each rule subsection below (GraphQL schema
|
|
|
84
84
|
- `logging` — Best practices for logging in Harper, including console capture, the granular logger interface, and programmatic log retrieval.
|
|
85
85
|
- `load-env` — How to load environment variables from .env files into a Harper application using the loadEnv plugin.
|
|
86
86
|
- `v5-upgrade` — Breaking changes and recommended updates when migrating a Harper application to v5.
|
|
87
|
+
- `delegating-to-the-built-in-agent` — How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
87
88
|
|
|
88
89
|
<!-- END GENERATED INDEX -->
|
|
89
90
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: delegating-to-the-built-in-agent
|
|
3
|
+
description: How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: synthesized
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Delegating to the Built-in Agent
|
|
9
|
+
|
|
10
|
+
Harper 5.2+ ships with a **built-in agent** that runs _inside_ the server, on the main thread
|
|
11
|
+
adjacent to the operations API. Because it runs in-process, it can do things a remote client
|
|
12
|
+
cannot: call the operations API as RBAC-filtered tools, read and write component files under the
|
|
13
|
+
instance's components root, attach the V8 inspector to worker threads to debug and profile them,
|
|
14
|
+
schedule follow-up work, and consult the Harper best-practices skill. You send it a natural-language
|
|
15
|
+
task; it runs a tool-using loop under a super_user identity and reports back.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
Delegate to the built-in agent when the work is best done **on the instance itself** rather than
|
|
20
|
+
from your local client:
|
|
21
|
+
|
|
22
|
+
- Operating on a deployed instance in place — inspect the schema, build or adjust a component,
|
|
23
|
+
restart, run an operation.
|
|
24
|
+
- Debugging or profiling a running instance — attach to a worker thread, capture a CPU profile,
|
|
25
|
+
set a logpoint.
|
|
26
|
+
- Handing off a larger, multi-step task to an agent that already has the instance's tools,
|
|
27
|
+
filesystem, and credentials in context.
|
|
28
|
+
|
|
29
|
+
Do the work in your own client instead when it's purely local (editing source before deploy) or
|
|
30
|
+
when you don't want a server-side agent making changes.
|
|
31
|
+
|
|
32
|
+
**Prerequisites:** the target instance must have the agent enabled (an `agent:` config block with
|
|
33
|
+
`enabled: true`) and a configured generative model backend. All agent operations require
|
|
34
|
+
**super_user**.
|
|
35
|
+
|
|
36
|
+
## How It Works
|
|
37
|
+
|
|
38
|
+
The lifecycle assumes you have already deployed to and authenticated with the target instance (see
|
|
39
|
+
[deploying-to-harper-fabric.md](deploying-to-harper-fabric.md) — `harper login` stores a token so
|
|
40
|
+
you don't repeat credentials). Delegation reuses that same target and credentials.
|
|
41
|
+
|
|
42
|
+
There are two equivalent ways to drive the agent.
|
|
43
|
+
|
|
44
|
+
### Option A — the `harper agent` CLI (simplest)
|
|
45
|
+
|
|
46
|
+
A thin client over the agent operations API that reuses your stored `harper login` credentials, so
|
|
47
|
+
no connector setup is needed:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# One-shot: send a task, print the reply, exit
|
|
51
|
+
harper agent "Describe the schema, then add a price index to the Product table."
|
|
52
|
+
|
|
53
|
+
# Interactive session (REPL)
|
|
54
|
+
harper agent
|
|
55
|
+
|
|
56
|
+
# Against a specific remote instead of the logged-in default
|
|
57
|
+
harper agent --target <Application URL> "List the databases and tables."
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The CLI polls the run to completion and renders the transcript (tool calls, results, and the
|
|
61
|
+
agent's reply). When a run needs approval for a destructive action, it prompts you inline.
|
|
62
|
+
|
|
63
|
+
### Option B — the agent operations API (programmatic)
|
|
64
|
+
|
|
65
|
+
Call the operations API directly (HTTP POST to the ops endpoint, super_user auth). This is the path
|
|
66
|
+
to use from scripts and services.
|
|
67
|
+
|
|
68
|
+
1. **Start a task** with `agent_prompt`. Returns a `session_id` and a `status`.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
72
|
+
-H 'Content-Type: application/json' \
|
|
73
|
+
-d '{"operation":"agent_prompt","message":"Build a Customer table (id, email, name) exported over REST."}'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
2. **Poll for progress** with `get_agent_session`, passing the `session_id`. The returned session
|
|
77
|
+
carries the `status`, the `messages` transcript, and any `pendingApprovals`.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
81
|
+
-H 'Content-Type: application/json' \
|
|
82
|
+
-d '{"operation":"get_agent_session","session_id":"<id>"}'
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Poll until `status` leaves `running` — terminal states are `completed`, `aborted`, and `error`;
|
|
86
|
+
`awaiting_approval` means it is paused for an approval decision (see step 3).
|
|
87
|
+
|
|
88
|
+
3. **Approve or deny a paused action.** When the agent enabled configuration has `autoApprove:false`,
|
|
89
|
+
a destructive tool call pauses the run with a `pendingApprovals[]` entry. Resolve it with
|
|
90
|
+
`approve_agent_action`, then poll again — approval executes the saved call, denial hands the
|
|
91
|
+
rejection back to the agent so it can adjust.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
95
|
+
-H 'Content-Type: application/json' \
|
|
96
|
+
-d '{"operation":"approve_agent_action","session_id":"<id>","approval_id":"<approval-id>","approved":true}'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
4. **Continue the conversation** by passing the same `session_id` back into `agent_prompt` with a
|
|
100
|
+
new `message`. Omit `session_id` to start a fresh session.
|
|
101
|
+
|
|
102
|
+
Supporting operations: `list_agent_sessions` (recent sessions), `cancel_agent_run` (terminate a
|
|
103
|
+
running or paused session), and `set_agent_config` (adjust `autoApprove`, `allowDestructive`,
|
|
104
|
+
`model`, and related settings on a running instance).
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
**Delegate a build to a deployed Fabric instance and wait for the result:**
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
harper login <Application URL>
|
|
112
|
+
harper agent --target <Application URL> \
|
|
113
|
+
"Create a Product table (id, name, price) exported over REST, then confirm the endpoint responds."
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Programmatic start-and-poll loop:**
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
SID=$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
120
|
+
-d '{"operation":"agent_prompt","message":"Add a vector index to the Document.embedding field."}' \
|
|
121
|
+
| jq -r .session_id)
|
|
122
|
+
|
|
123
|
+
while [ "$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
124
|
+
-d "{\"operation\":\"get_agent_session\",\"session_id\":\"$SID\"}" | jq -r .status)" = "running" ]; do
|
|
125
|
+
sleep 3
|
|
126
|
+
done
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Notes
|
|
130
|
+
|
|
131
|
+
- **All agent operations require super_user.** Authenticate with `harper login`, which stores a
|
|
132
|
+
short-lived JWT (operation token) plus a refresh token rather than your password — prefer that
|
|
133
|
+
over passing credentials inline, and never embed a raw password in scripts or client config.
|
|
134
|
+
- **Approvals are your safety gate.** With `autoApprove:false`, the agent pauses before destructive
|
|
135
|
+
tools (writing files, deploying, restarting) so an operator decides. Set `autoApprove:true` only
|
|
136
|
+
when you want unattended runs.
|
|
137
|
+
- **Sessions are single-active.** A session that is `running` or `awaiting_approval` rejects a new
|
|
138
|
+
`agent_prompt`; resolve the approval or cancel the run first.
|
|
139
|
+
- **MCP alternative.** For MCP-native clients, an instance with MCP enabled exposes the agent as
|
|
140
|
+
curated MCP tools (`agent_prompt`, `get_agent_session`, `list_agent_sessions`) at the ops API's
|
|
141
|
+
`/mcp` endpoint — the same delegation loop over the MCP transport instead of raw operations.
|
|
@@ -422,3 +422,12 @@ rules:
|
|
|
422
422
|
- 'moduleLoader'
|
|
423
423
|
- 'lockdown'
|
|
424
424
|
- 'Table.get'
|
|
425
|
+
|
|
426
|
+
- rule: delegating-to-the-built-in-agent
|
|
427
|
+
description: How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
428
|
+
category: ops
|
|
429
|
+
priority: 4
|
|
430
|
+
order: 8
|
|
431
|
+
mode: synthesized
|
|
432
|
+
cross_links:
|
|
433
|
+
- deploying-to-harper-fabric
|
|
@@ -2621,3 +2621,138 @@ Beyond the required fixes above, Harper v5 encourages these patterns for new and
|
|
|
2621
2621
|
- Implement endpoints with `static` methods on Resources/Tables, reading request information from the request `target` argument (or from `getContext()`).
|
|
2622
2622
|
- Rely on automatic context propagation rather than threading context through every call manually; access it via `getContext()` exported from `harper`.
|
|
2623
2623
|
- Access Harper functions and APIs through the `harper` package rather than through global variables.
|
|
2624
|
+
|
|
2625
|
+
### 4.8 Delegating to the Built-in Agent
|
|
2626
|
+
|
|
2627
|
+
Harper 5.2+ ships with a **built-in agent** that runs _inside_ the server, on the main thread
|
|
2628
|
+
adjacent to the operations API. Because it runs in-process, it can do things a remote client
|
|
2629
|
+
cannot: call the operations API as RBAC-filtered tools, read and write component files under the
|
|
2630
|
+
instance's components root, attach the V8 inspector to worker threads to debug and profile them,
|
|
2631
|
+
schedule follow-up work, and consult the Harper best-practices skill. You send it a natural-language
|
|
2632
|
+
task; it runs a tool-using loop under a super_user identity and reports back.
|
|
2633
|
+
|
|
2634
|
+
#### When to Use
|
|
2635
|
+
|
|
2636
|
+
Delegate to the built-in agent when the work is best done **on the instance itself** rather than
|
|
2637
|
+
from your local client:
|
|
2638
|
+
|
|
2639
|
+
- Operating on a deployed instance in place — inspect the schema, build or adjust a component,
|
|
2640
|
+
restart, run an operation.
|
|
2641
|
+
- Debugging or profiling a running instance — attach to a worker thread, capture a CPU profile,
|
|
2642
|
+
set a logpoint.
|
|
2643
|
+
- Handing off a larger, multi-step task to an agent that already has the instance's tools,
|
|
2644
|
+
filesystem, and credentials in context.
|
|
2645
|
+
|
|
2646
|
+
Do the work in your own client instead when it's purely local (editing source before deploy) or
|
|
2647
|
+
when you don't want a server-side agent making changes.
|
|
2648
|
+
|
|
2649
|
+
**Prerequisites:** the target instance must have the agent enabled (an `agent:` config block with
|
|
2650
|
+
`enabled: true`) and a configured generative model backend. All agent operations require
|
|
2651
|
+
**super_user**.
|
|
2652
|
+
|
|
2653
|
+
#### How It Works
|
|
2654
|
+
|
|
2655
|
+
The lifecycle assumes you have already deployed to and authenticated with the target instance (see
|
|
2656
|
+
[deploying-to-harper-fabric.md](deploying-to-harper-fabric.md) — `harper login` stores a token so
|
|
2657
|
+
you don't repeat credentials). Delegation reuses that same target and credentials.
|
|
2658
|
+
|
|
2659
|
+
There are two equivalent ways to drive the agent.
|
|
2660
|
+
|
|
2661
|
+
##### Option A — the `harper agent` CLI (simplest)
|
|
2662
|
+
|
|
2663
|
+
A thin client over the agent operations API that reuses your stored `harper login` credentials, so
|
|
2664
|
+
no connector setup is needed:
|
|
2665
|
+
|
|
2666
|
+
```bash
|
|
2667
|
+
# One-shot: send a task, print the reply, exit
|
|
2668
|
+
harper agent "Describe the schema, then add a price index to the Product table."
|
|
2669
|
+
|
|
2670
|
+
# Interactive session (REPL)
|
|
2671
|
+
harper agent
|
|
2672
|
+
|
|
2673
|
+
# Against a specific remote instead of the logged-in default
|
|
2674
|
+
harper agent --target <Application URL> "List the databases and tables."
|
|
2675
|
+
```
|
|
2676
|
+
|
|
2677
|
+
The CLI polls the run to completion and renders the transcript (tool calls, results, and the
|
|
2678
|
+
agent's reply). When a run needs approval for a destructive action, it prompts you inline.
|
|
2679
|
+
|
|
2680
|
+
##### Option B — the agent operations API (programmatic)
|
|
2681
|
+
|
|
2682
|
+
Call the operations API directly (HTTP POST to the ops endpoint, super_user auth). This is the path
|
|
2683
|
+
to use from scripts and services.
|
|
2684
|
+
|
|
2685
|
+
1. **Start a task** with `agent_prompt`. Returns a `session_id` and a `status`.
|
|
2686
|
+
|
|
2687
|
+
```bash
|
|
2688
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2689
|
+
-H 'Content-Type: application/json' \
|
|
2690
|
+
-d '{"operation":"agent_prompt","message":"Build a Customer table (id, email, name) exported over REST."}'
|
|
2691
|
+
```
|
|
2692
|
+
|
|
2693
|
+
2. **Poll for progress** with `get_agent_session`, passing the `session_id`. The returned session
|
|
2694
|
+
carries the `status`, the `messages` transcript, and any `pendingApprovals`.
|
|
2695
|
+
|
|
2696
|
+
```bash
|
|
2697
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2698
|
+
-H 'Content-Type: application/json' \
|
|
2699
|
+
-d '{"operation":"get_agent_session","session_id":"<id>"}'
|
|
2700
|
+
```
|
|
2701
|
+
|
|
2702
|
+
Poll until `status` leaves `running` — terminal states are `completed`, `aborted`, and `error`;
|
|
2703
|
+
`awaiting_approval` means it is paused for an approval decision (see step 3).
|
|
2704
|
+
|
|
2705
|
+
3. **Approve or deny a paused action.** When the agent enabled configuration has `autoApprove:false`,
|
|
2706
|
+
a destructive tool call pauses the run with a `pendingApprovals[]` entry. Resolve it with
|
|
2707
|
+
`approve_agent_action`, then poll again — approval executes the saved call, denial hands the
|
|
2708
|
+
rejection back to the agent so it can adjust.
|
|
2709
|
+
|
|
2710
|
+
```bash
|
|
2711
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
2712
|
+
-H 'Content-Type: application/json' \
|
|
2713
|
+
-d '{"operation":"approve_agent_action","session_id":"<id>","approval_id":"<approval-id>","approved":true}'
|
|
2714
|
+
```
|
|
2715
|
+
|
|
2716
|
+
4. **Continue the conversation** by passing the same `session_id` back into `agent_prompt` with a
|
|
2717
|
+
new `message`. Omit `session_id` to start a fresh session.
|
|
2718
|
+
|
|
2719
|
+
Supporting operations: `list_agent_sessions` (recent sessions), `cancel_agent_run` (terminate a
|
|
2720
|
+
running or paused session), and `set_agent_config` (adjust `autoApprove`, `allowDestructive`,
|
|
2721
|
+
`model`, and related settings on a running instance).
|
|
2722
|
+
|
|
2723
|
+
#### Examples
|
|
2724
|
+
|
|
2725
|
+
**Delegate a build to a deployed Fabric instance and wait for the result:**
|
|
2726
|
+
|
|
2727
|
+
```bash
|
|
2728
|
+
harper login <Application URL>
|
|
2729
|
+
harper agent --target <Application URL> \
|
|
2730
|
+
"Create a Product table (id, name, price) exported over REST, then confirm the endpoint responds."
|
|
2731
|
+
```
|
|
2732
|
+
|
|
2733
|
+
**Programmatic start-and-poll loop:**
|
|
2734
|
+
|
|
2735
|
+
```bash
|
|
2736
|
+
SID=$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
2737
|
+
-d '{"operation":"agent_prompt","message":"Add a vector index to the Document.embedding field."}' \
|
|
2738
|
+
| jq -r .session_id)
|
|
2739
|
+
|
|
2740
|
+
while [ "$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
2741
|
+
-d "{\"operation\":\"get_agent_session\",\"session_id\":\"$SID\"}" | jq -r .status)" = "running" ]; do
|
|
2742
|
+
sleep 3
|
|
2743
|
+
done
|
|
2744
|
+
```
|
|
2745
|
+
|
|
2746
|
+
#### Notes
|
|
2747
|
+
|
|
2748
|
+
- **All agent operations require super_user.** Authenticate with `harper login`, which stores a
|
|
2749
|
+
short-lived JWT (operation token) plus a refresh token rather than your password — prefer that
|
|
2750
|
+
over passing credentials inline, and never embed a raw password in scripts or client config.
|
|
2751
|
+
- **Approvals are your safety gate.** With `autoApprove:false`, the agent pauses before destructive
|
|
2752
|
+
tools (writing files, deploying, restarting) so an operator decides. Set `autoApprove:true` only
|
|
2753
|
+
when you want unattended runs.
|
|
2754
|
+
- **Sessions are single-active.** A session that is `running` or `awaiting_approval` rejects a new
|
|
2755
|
+
`agent_prompt`; resolve the approval or cancel the run first.
|
|
2756
|
+
- **MCP alternative.** For MCP-native clients, an instance with MCP enabled exposes the agent as
|
|
2757
|
+
curated MCP tools (`agent_prompt`, `get_agent_session`, `list_agent_sessions`) at the ops API's
|
|
2758
|
+
`/mcp` endpoint — the same delegation loop over the MCP transport instead of raw operations.
|
|
@@ -77,6 +77,7 @@ See the concrete examples embedded in each rule subsection below (GraphQL schema
|
|
|
77
77
|
- `logging` — Best practices for logging in Harper, including console capture, the granular logger interface, and programmatic log retrieval.
|
|
78
78
|
- `load-env` — How to load environment variables from .env files into a Harper application using the loadEnv plugin.
|
|
79
79
|
- `v5-upgrade` — Breaking changes and recommended updates when migrating a Harper application to v5.
|
|
80
|
+
- `delegating-to-the-built-in-agent` — How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
80
81
|
|
|
81
82
|
<!-- END GENERATED INDEX -->
|
|
82
83
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: delegating-to-the-built-in-agent
|
|
3
|
+
description: How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
4
|
+
metadata:
|
|
5
|
+
mode: synthesized
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Delegating to the Built-in Agent
|
|
9
|
+
|
|
10
|
+
Harper 5.2+ ships with a **built-in agent** that runs _inside_ the server, on the main thread
|
|
11
|
+
adjacent to the operations API. Because it runs in-process, it can do things a remote client
|
|
12
|
+
cannot: call the operations API as RBAC-filtered tools, read and write component files under the
|
|
13
|
+
instance's components root, attach the V8 inspector to worker threads to debug and profile them,
|
|
14
|
+
schedule follow-up work, and consult the Harper best-practices skill. You send it a natural-language
|
|
15
|
+
task; it runs a tool-using loop under a super_user identity and reports back.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
Delegate to the built-in agent when the work is best done **on the instance itself** rather than
|
|
20
|
+
from your local client:
|
|
21
|
+
|
|
22
|
+
- Operating on a deployed instance in place — inspect the schema, build or adjust a component,
|
|
23
|
+
restart, run an operation.
|
|
24
|
+
- Debugging or profiling a running instance — attach to a worker thread, capture a CPU profile,
|
|
25
|
+
set a logpoint.
|
|
26
|
+
- Handing off a larger, multi-step task to an agent that already has the instance's tools,
|
|
27
|
+
filesystem, and credentials in context.
|
|
28
|
+
|
|
29
|
+
Do the work in your own client instead when it's purely local (editing source before deploy) or
|
|
30
|
+
when you don't want a server-side agent making changes.
|
|
31
|
+
|
|
32
|
+
**Prerequisites:** the target instance must have the agent enabled (an `agent:` config block with
|
|
33
|
+
`enabled: true`) and a configured generative model backend. All agent operations require
|
|
34
|
+
**super_user**.
|
|
35
|
+
|
|
36
|
+
## How It Works
|
|
37
|
+
|
|
38
|
+
The lifecycle assumes you have already deployed to and authenticated with the target instance (see
|
|
39
|
+
[deploying-to-harper-fabric.md](deploying-to-harper-fabric.md) — `harper login` stores a token so
|
|
40
|
+
you don't repeat credentials). Delegation reuses that same target and credentials.
|
|
41
|
+
|
|
42
|
+
There are two equivalent ways to drive the agent.
|
|
43
|
+
|
|
44
|
+
### Option A — the `harper agent` CLI (simplest)
|
|
45
|
+
|
|
46
|
+
A thin client over the agent operations API that reuses your stored `harper login` credentials, so
|
|
47
|
+
no connector setup is needed:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# One-shot: send a task, print the reply, exit
|
|
51
|
+
harper agent "Describe the schema, then add a price index to the Product table."
|
|
52
|
+
|
|
53
|
+
# Interactive session (REPL)
|
|
54
|
+
harper agent
|
|
55
|
+
|
|
56
|
+
# Against a specific remote instead of the logged-in default
|
|
57
|
+
harper agent --target <Application URL> "List the databases and tables."
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The CLI polls the run to completion and renders the transcript (tool calls, results, and the
|
|
61
|
+
agent's reply). When a run needs approval for a destructive action, it prompts you inline.
|
|
62
|
+
|
|
63
|
+
### Option B — the agent operations API (programmatic)
|
|
64
|
+
|
|
65
|
+
Call the operations API directly (HTTP POST to the ops endpoint, super_user auth). This is the path
|
|
66
|
+
to use from scripts and services.
|
|
67
|
+
|
|
68
|
+
1. **Start a task** with `agent_prompt`. Returns a `session_id` and a `status`.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
72
|
+
-H 'Content-Type: application/json' \
|
|
73
|
+
-d '{"operation":"agent_prompt","message":"Build a Customer table (id, email, name) exported over REST."}'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
2. **Poll for progress** with `get_agent_session`, passing the `session_id`. The returned session
|
|
77
|
+
carries the `status`, the `messages` transcript, and any `pendingApprovals`.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
81
|
+
-H 'Content-Type: application/json' \
|
|
82
|
+
-d '{"operation":"get_agent_session","session_id":"<id>"}'
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Poll until `status` leaves `running` — terminal states are `completed`, `aborted`, and `error`;
|
|
86
|
+
`awaiting_approval` means it is paused for an approval decision (see step 3).
|
|
87
|
+
|
|
88
|
+
3. **Approve or deny a paused action.** When the agent enabled configuration has `autoApprove:false`,
|
|
89
|
+
a destructive tool call pauses the run with a `pendingApprovals[]` entry. Resolve it with
|
|
90
|
+
`approve_agent_action`, then poll again — approval executes the saved call, denial hands the
|
|
91
|
+
rejection back to the agent so it can adjust.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
curl -s -u <user>:<pass> <ops-endpoint> \
|
|
95
|
+
-H 'Content-Type: application/json' \
|
|
96
|
+
-d '{"operation":"approve_agent_action","session_id":"<id>","approval_id":"<approval-id>","approved":true}'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
4. **Continue the conversation** by passing the same `session_id` back into `agent_prompt` with a
|
|
100
|
+
new `message`. Omit `session_id` to start a fresh session.
|
|
101
|
+
|
|
102
|
+
Supporting operations: `list_agent_sessions` (recent sessions), `cancel_agent_run` (terminate a
|
|
103
|
+
running or paused session), and `set_agent_config` (adjust `autoApprove`, `allowDestructive`,
|
|
104
|
+
`model`, and related settings on a running instance).
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
**Delegate a build to a deployed Fabric instance and wait for the result:**
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
harper login <Application URL>
|
|
112
|
+
harper agent --target <Application URL> \
|
|
113
|
+
"Create a Product table (id, name, price) exported over REST, then confirm the endpoint responds."
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Programmatic start-and-poll loop:**
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
SID=$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
120
|
+
-d '{"operation":"agent_prompt","message":"Add a vector index to the Document.embedding field."}' \
|
|
121
|
+
| jq -r .session_id)
|
|
122
|
+
|
|
123
|
+
while [ "$(curl -s -u <user>:<pass> <ops-endpoint> -H 'Content-Type: application/json' \
|
|
124
|
+
-d "{\"operation\":\"get_agent_session\",\"session_id\":\"$SID\"}" | jq -r .status)" = "running" ]; do
|
|
125
|
+
sleep 3
|
|
126
|
+
done
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Notes
|
|
130
|
+
|
|
131
|
+
- **All agent operations require super_user.** Authenticate with `harper login`, which stores a
|
|
132
|
+
short-lived JWT (operation token) plus a refresh token rather than your password — prefer that
|
|
133
|
+
over passing credentials inline, and never embed a raw password in scripts or client config.
|
|
134
|
+
- **Approvals are your safety gate.** With `autoApprove:false`, the agent pauses before destructive
|
|
135
|
+
tools (writing files, deploying, restarting) so an operator decides. Set `autoApprove:true` only
|
|
136
|
+
when you want unattended runs.
|
|
137
|
+
- **Sessions are single-active.** A session that is `running` or `awaiting_approval` rejects a new
|
|
138
|
+
`agent_prompt`; resolve the approval or cancel the run first.
|
|
139
|
+
- **MCP alternative.** For MCP-native clients, an instance with MCP enabled exposes the agent as
|
|
140
|
+
curated MCP tools (`agent_prompt`, `get_agent_session`, `list_agent_sessions`) at the ops API's
|
|
141
|
+
`/mcp` endpoint — the same delegation loop over the MCP transport instead of raw operations.
|
|
@@ -422,3 +422,12 @@ rules:
|
|
|
422
422
|
- 'moduleLoader'
|
|
423
423
|
- 'lockdown'
|
|
424
424
|
- 'Table.get'
|
|
425
|
+
|
|
426
|
+
- rule: delegating-to-the-built-in-agent
|
|
427
|
+
description: How to delegate tasks to Harper's built-in agent via the CLI and the agent operations API.
|
|
428
|
+
category: ops
|
|
429
|
+
priority: 4
|
|
430
|
+
order: 8
|
|
431
|
+
mode: synthesized
|
|
432
|
+
cross_links:
|
|
433
|
+
- deploying-to-harper-fabric
|
package/package.json
CHANGED
package/skills-lock.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"source": "harperfast/skills",
|
|
6
6
|
"sourceType": "github",
|
|
7
7
|
"skillPath": "harper-best-practices/SKILL.md",
|
|
8
|
-
"computedHash": "
|
|
8
|
+
"computedHash": "17647d3ece3f15665ca3c0bdb2e0040f9e3706a3dbd8848c92eba84a93b67c8d"
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|