@agentfield/sdk 0.1.44-rc.1 → 0.1.44-rc.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/README.md +38 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,3 +53,41 @@ agent.reasoner('process', async (ctx) => {
|
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
**Use `note()` for AgentField UI tracking, `console.log()` for local debugging.**
|
|
56
|
+
|
|
57
|
+
## Human-in-the-Loop Approvals
|
|
58
|
+
|
|
59
|
+
Use the `ApprovalClient` to pause agent execution for human review:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { Agent, ApprovalClient } from '@agentfield/sdk';
|
|
63
|
+
|
|
64
|
+
const agent = new Agent({ nodeId: 'reviewer', agentFieldUrl: 'http://localhost:8080' });
|
|
65
|
+
const approvalClient = new ApprovalClient({
|
|
66
|
+
baseURL: 'http://localhost:8080',
|
|
67
|
+
nodeId: 'reviewer',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
agent.reasoner<{ task: string }, { status: string }>('deploy', async (ctx) => {
|
|
71
|
+
const plan = await ctx.ai(`Create deployment plan for: ${ctx.input.task}`);
|
|
72
|
+
|
|
73
|
+
// Request approval — transitions execution to "waiting"
|
|
74
|
+
await approvalClient.requestApproval(ctx.executionId, {
|
|
75
|
+
projectId: 'my-project',
|
|
76
|
+
title: `Deploy: ${ctx.input.task}`,
|
|
77
|
+
description: String(plan),
|
|
78
|
+
expiresInHours: 24,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Wait for human decision (polls with exponential backoff)
|
|
82
|
+
const result = await approvalClient.waitForApproval(ctx.executionId, {
|
|
83
|
+
pollIntervalMs: 5_000,
|
|
84
|
+
timeoutMs: 3_600_000,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return { status: result.status };
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Methods:** `requestApproval()`, `getApprovalStatus()`, `waitForApproval()`
|
|
92
|
+
|
|
93
|
+
See `examples/ts-node-examples/waiting-state/` for a complete working example.
|