@nxisai/agent-harness 0.6.0 → 0.8.0
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/LICENSE +201 -0
- package/README.md +32 -7
- package/dist/handoff/tools.d.ts.map +1 -1
- package/dist/handoff/tools.js +11 -4
- package/dist/handoff/tools.js.map +1 -1
- package/dist/harness/harness.d.ts +16 -0
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +70 -10
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/recommend.d.ts +46 -0
- package/dist/harness/recommend.d.ts.map +1 -0
- package/dist/harness/recommend.js +144 -0
- package/dist/harness/recommend.js.map +1 -0
- package/dist/harness/records.d.ts +70 -0
- package/dist/harness/records.d.ts.map +1 -0
- package/dist/harness/records.js +209 -0
- package/dist/harness/records.js.map +1 -0
- package/dist/harness/renderer.d.ts +31 -1
- package/dist/harness/renderer.d.ts.map +1 -1
- package/dist/harness/tools/action-tools.d.ts +39 -0
- package/dist/harness/tools/action-tools.d.ts.map +1 -1
- package/dist/harness/tools/action-tools.js +82 -4
- package/dist/harness/tools/action-tools.js.map +1 -1
- package/dist/harness/tools/site-actions.d.ts +27 -0
- package/dist/harness/tools/site-actions.d.ts.map +1 -1
- package/dist/harness/tools/site-actions.js +47 -0
- package/dist/harness/tools/site-actions.js.map +1 -1
- package/dist/harness/tools/site-pages.js +1 -1
- package/dist/harness/tools/source.d.ts.map +1 -1
- package/dist/harness/tools/source.js +5 -2
- package/dist/harness/tools/source.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/ui/action-card.d.ts +141 -0
- package/dist/ui/action-card.d.ts.map +1 -0
- package/dist/ui/action-card.js +384 -0
- package/dist/ui/action-card.js.map +1 -0
- package/dist/ui/agent-fullscreen.d.ts.map +1 -1
- package/dist/ui/agent-fullscreen.js +615 -88
- package/dist/ui/agent-fullscreen.js.map +1 -1
- package/dist/ui/result-pick.d.ts +52 -0
- package/dist/ui/result-pick.d.ts.map +1 -0
- package/dist/ui/result-pick.js +196 -0
- package/dist/ui/result-pick.js.map +1 -0
- package/dist/ui/tailwind.generated.d.ts +1 -1
- package/dist/ui/tailwind.generated.d.ts.map +1 -1
- package/dist/ui/tailwind.generated.js +1 -1
- package/dist/ui/tailwind.generated.js.map +1 -1
- package/package.json +1 -1
- package/src/handoff/tools.ts +11 -7
- package/src/harness/harness.ts +82 -17
- package/src/harness/recommend.ts +194 -0
- package/src/harness/records.ts +237 -0
- package/src/harness/renderer.ts +34 -1
- package/src/harness/tools/action-tools.ts +92 -4
- package/src/harness/tools/site-actions.ts +58 -0
- package/src/harness/tools/site-pages.ts +1 -1
- package/src/harness/tools/source.ts +5 -2
- package/src/index.ts +4 -1
- package/src/ui/action-card.ts +496 -0
- package/src/ui/agent-fullscreen.ts +655 -78
- package/src/ui/result-pick.ts +233 -0
- package/src/ui/tailwind.generated.ts +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -222,6 +222,7 @@ Both flags go false at a specialist handoff, which swaps the system prompt and t
|
|
|
222
222
|
| `mode` | `fullscreen` (default), `window`, `inline` | Cover the page; dock in the corner at `--window-w` × `--window-h` (400 × 620); or fill the box the host puts it in and stay open — for a copilot rail the host lays out. Below 520px a window covers the page anyway. |
|
|
223
223
|
| `discover` | `"false"` | Skip remote MCP discovery. |
|
|
224
224
|
| `site-actions` | `"false"` | Don't fetch the actions on other pages of the site. |
|
|
225
|
+
| `prompt-style` | `"classic"` | Use the separate ask, "Ready to send" and "Submitted" cards, and the per-record result cards, of earlier versions instead of the action card and the recommended pick. |
|
|
225
226
|
| `cache` | `"false"` | Do not store model files in Cache Storage. |
|
|
226
227
|
| `model-host` | URL | Fetch weights from another origin. |
|
|
227
228
|
| `model-path-template` | string | Path template under `model-host`. |
|
|
@@ -282,11 +283,33 @@ Given the tool the model picked and everything already known, the harness asks w
|
|
|
282
283
|
|
|
283
284
|
| Tool | Gaps | Result |
|
|
284
285
|
|---|---|---|
|
|
285
|
-
| read (`readOnlyHint`) | none | runs
|
|
286
|
+
| read (`readOnlyHint`) | none | runs; several records end with a recommended pick |
|
|
286
287
|
| read | some | asks only for those, then runs |
|
|
287
|
-
| write | none |
|
|
288
|
-
| write |
|
|
289
|
-
|
|
288
|
+
| write | none | action card: what will be sent, and Send |
|
|
289
|
+
| write | some | action card: what it has, the fields still needed, then Send |
|
|
290
|
+
|
|
291
|
+
### Search results: a pick, and why
|
|
292
|
+
|
|
293
|
+
When a search returns two or more records, the harness asks the model one more question: which of these fits what the visitor asked, and why. The model answers through a `recommend` call (the result's number, one sentence naming it, two or three reasons). Then every reason is checked against the record it picked:
|
|
294
|
+
|
|
295
|
+
- every number in it must be one the record states ("4.7", "412", "40 minutes");
|
|
296
|
+
- "open now" and "24/7" must match the record's opening hours, read at the time of the search;
|
|
297
|
+
- it must share a meaningful word with the record, and not be about another result.
|
|
298
|
+
|
|
299
|
+
Reasons that fail are dropped. If none survive, there is no pick. The widget shows the pick with its reasons ticked, a Call button, "Their page", and "Get a quote" when the site has a form for that business. Under it, "Also good · tap to compare" lists the others. Comparing one shows its own facts without ticks, because the agent did not recommend it. With no pick, the results are a short list that opens per result.
|
|
300
|
+
|
|
301
|
+
Each record's hours become "Open now · 24/7", "Open now · until 5pm" or "Opens 7am" (`openingHoursSpecification` or `openingHours`). `recommend: false` skips the extra completion; `prompt-style="classic"` keeps the earlier result cards. `extractRecords`, `recordFacts`, `openStatus`, `recommend` and `grounded` are exported for hosts that render results themselves.
|
|
302
|
+
|
|
303
|
+
### The action card
|
|
304
|
+
|
|
305
|
+
A write, and a handoff to an agent or a person, is one message in the conversation rather than a series of cards. The card names who it goes to (the business the form belongs to, or the team or agent and whether they are available now), then moves through:
|
|
306
|
+
|
|
307
|
+
1. **Fill in**: what the agent already has, editable, under "What I have", and anything still needed under "Still needed" (for a handoff to a team that is away, "Where should they reply?"). The button says what is missing until nothing is.
|
|
308
|
+
2. **Review**: one sentence saying what will happen ("I'll send this quote form to Hatzel & Sons Plumbing. They'll reply to dana@example.com."), the details behind "What they'll get", and Send or Not now. A form on another page says it will be sent from there.
|
|
309
|
+
3. **Sending**: the steps as they run, on this page or the one it opens.
|
|
310
|
+
4. **Sent**, **Handed to …**, or **It didn't go through** with the form's reason and "Change and try again".
|
|
311
|
+
|
|
312
|
+
The card is saved with the conversation and replaces the step-by-step journey card for that request. `prompt-style="classic"` brings back the earlier cards; a custom renderer opts in to the same behaviour with `inlinePrompts` and `left` (see [`HarnessRenderer`](#harnessrenderer)).
|
|
290
313
|
|
|
291
314
|
Values merge in this order, last wins: schema default, page context, saved preferences, model arguments.
|
|
292
315
|
|
|
@@ -370,7 +393,7 @@ provider.loading: boolean
|
|
|
370
393
|
### `AgentHarness`
|
|
371
394
|
|
|
372
395
|
```ts
|
|
373
|
-
new AgentHarness({ renderer, provider?, toolSource?, systemPrompt?, tools?, maxSiteTools?, name?, unavailable?, profile?, context?, groupRelated?, onMessages? })
|
|
396
|
+
new AgentHarness({ renderer, provider?, toolSource?, systemPrompt?, tools?, maxSiteTools?, name?, unavailable?, profile?, context?, groupRelated?, recommend?, now?, onMessages? })
|
|
374
397
|
harness.turn(goal, messages): Promise<TurnResult>
|
|
375
398
|
harness.owns(toolName): boolean
|
|
376
399
|
harness.stop(): void // abandon the request in flight
|
|
@@ -391,13 +414,15 @@ interface HarnessRenderer {
|
|
|
391
414
|
status(text, isError?): void;
|
|
392
415
|
ask(req: AskRequest): void;
|
|
393
416
|
confirm(req: ConfirmRequest): void;
|
|
394
|
-
results(tool, res): void;
|
|
417
|
+
results(tool, res, extra?): void; // extra.pick: the recommended record and its reasons
|
|
395
418
|
detail(tool, values, text): void;
|
|
396
419
|
toolError(tool, message): void;
|
|
397
420
|
trace?(entry: TraceEntry): void; // { tool, args, text, isError, count? }
|
|
398
421
|
step?(step: AgentStep, all: AgentStep[]): void;
|
|
399
422
|
dismissPrompt?(): void;
|
|
400
423
|
stoppable?(canStop: boolean): void; // false once a tool call has gone out
|
|
424
|
+
inlinePrompts?: boolean; // prompts speak for themselves: no "One more thing for …" line
|
|
425
|
+
left?(tool, destination): void; // a confirmed call is leaving for its page, instead of "Opening …"
|
|
401
426
|
}
|
|
402
427
|
```
|
|
403
428
|
|
|
@@ -593,7 +618,7 @@ That offers two tools, `transfer_to_agent` and `talk_to_a_person`, listing only
|
|
|
593
618
|
|
|
594
619
|
Headless, `HandoffController` runs the same handoffs and reports them as `handoff` events; `registerHandoffTools` offers the tools; `AgentCoordinator`'s `handoff` option routes a handed-off conversation's turns to its target.
|
|
595
620
|
|
|
596
|
-
[docs/handoff.md](docs/handoff.md) is the contract: the relay's endpoints, the handoff extension (`https://nxis.ai/a2a/handoff/v1`: the envelope, queue, operator and hand-back parts), the lifecycle, what makes a good target, and the adapter contract for putting a help desk behind A2A.
|
|
621
|
+
[docs/handoff.md](docs/handoff.md) is the contract: the relay's endpoints, the handoff extension (`https://nxis.ai/a2a/handoff/v1`: the envelope, queue, operator and hand-back parts), the lifecycle, what makes a good target, and the adapter contract for putting a help desk behind A2A.
|
|
597
622
|
|
|
598
623
|
## Requirements
|
|
599
624
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/handoff/tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAe,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,KAA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I,MAAM,GAAG,SAAS,CAAC;IACrC;;;OAGG;IACH,UAAU,CAAC,IAAI;QAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAClE;AAOD,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAK1D;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,iBAAiB,EAC7B,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAQ7B;AAyFD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,YAAY,EAChB,UAAU,EAAE,iBAAiB,EAC7B,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC,CAmBnB"}
|
package/dist/handoff/tools.js
CHANGED
|
@@ -52,7 +52,10 @@ function buildTool(kind, targets, controller, opts) {
|
|
|
52
52
|
.join('; ');
|
|
53
53
|
const description = kind === 'agent'
|
|
54
54
|
? `Hand this conversation to another agent that can finish what you can't. Use only when the visitor needs something one of these handles: ${menu}. The visitor sees the summary and confirms before anything is sent.`
|
|
55
|
-
: `Hand this conversation to a person on the site's team. Use when the visitor asks for a person, or when you can't help. Targets: ${menu}. The visitor sees the summary and confirms before anything is sent. When the team is away,
|
|
55
|
+
: `Hand this conversation to a person on the site's team. Use when the visitor asks for a person, or when you can't help. Targets: ${menu}. The visitor sees the summary and confirms before anything is sent. When the team is away, include the visitor's email if they gave one; the page asks for it otherwise.`;
|
|
56
|
+
// Everyone away: a reply can only go to an email, so the email is required and the page asks for it
|
|
57
|
+
// in the same form as any other missing detail, before the visitor presses Send rather than after.
|
|
58
|
+
const away = kind === 'person' && targets.every((t) => !t.available);
|
|
56
59
|
const properties = {
|
|
57
60
|
target: {
|
|
58
61
|
type: 'string',
|
|
@@ -70,13 +73,15 @@ function buildTool(kind, targets, controller, opts) {
|
|
|
70
73
|
properties.email = {
|
|
71
74
|
type: 'string',
|
|
72
75
|
format: 'email',
|
|
73
|
-
description:
|
|
76
|
+
description: away
|
|
77
|
+
? 'The team is away: the email address they should reply to.'
|
|
78
|
+
: 'Only when the team is away: an email address the visitor gave for a reply.',
|
|
74
79
|
};
|
|
75
80
|
}
|
|
76
81
|
return {
|
|
77
82
|
name,
|
|
78
83
|
description,
|
|
79
|
-
inputSchema: { type: 'object', properties, required: ['target', 'reason', 'summary'] },
|
|
84
|
+
inputSchema: { type: 'object', properties, required: ['target', 'reason', 'summary', ...(away ? ['email'] : [])] },
|
|
80
85
|
// A write: what the visitor said leaves the site. The harness confirms before it runs.
|
|
81
86
|
annotations: { readOnlyHint: false, consequentialHint: true },
|
|
82
87
|
execute: async (input) => {
|
|
@@ -88,8 +93,10 @@ function buildTool(kind, targets, controller, opts) {
|
|
|
88
93
|
return text(`"${String(input?.target ?? '')}" is not someone this conversation can be handed to.`, true);
|
|
89
94
|
}
|
|
90
95
|
const email = typeof input.email === 'string' ? input.email.trim() : '';
|
|
96
|
+
// Went away since the tools were built, or one of several desks is away: said to the visitor,
|
|
97
|
+
// who reads a failed call's result, and read by the model on the next turn.
|
|
91
98
|
if (!current.available && !email) {
|
|
92
|
-
return text(`${current.label} is ${availability(current)}.
|
|
99
|
+
return text(`${current.label} is ${availability(current)}. Leave an email address and they'll reply there.`, true);
|
|
93
100
|
}
|
|
94
101
|
const envelope = buildEnvelope({
|
|
95
102
|
target: current.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/handoff/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD,0FAA0F;AAC1F,MAAM,CAAC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AAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;IACpD,CAAC;IACD,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QACrC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC5B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -89,6 +89,15 @@ export interface HarnessOptions {
|
|
|
89
89
|
* Defaults to true. Pass false to ask one question at a time.
|
|
90
90
|
*/
|
|
91
91
|
groupRelated?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether a search that finds several records ends with a recommendation:
|
|
94
|
+
* the model picks one and gives reasons, and only reasons the record backs
|
|
95
|
+
* are kept (see `recommend`). Defaults to true. Costs one more completion
|
|
96
|
+
* per search.
|
|
97
|
+
*/
|
|
98
|
+
recommend?: boolean;
|
|
99
|
+
/** The clock "open now" is judged by. For tests. */
|
|
100
|
+
now?: () => Date;
|
|
92
101
|
/** Called whenever the conversation changes, for hosts that persist it. */
|
|
93
102
|
onMessages?(messages: ChatMessage[]): void;
|
|
94
103
|
}
|
|
@@ -196,6 +205,8 @@ export declare class AgentHarness {
|
|
|
196
205
|
/** The previous request's system prompt and tool names, for the cache hint. */
|
|
197
206
|
private lastPrompt;
|
|
198
207
|
private lastTools;
|
|
208
|
+
/** What the visitor asked this turn, for a recommendation to answer. */
|
|
209
|
+
private goal;
|
|
199
210
|
constructor(opts: HarnessOptions);
|
|
200
211
|
/**
|
|
201
212
|
* End a turn that the user stopped.
|
|
@@ -331,6 +342,11 @@ export declare class AgentHarness {
|
|
|
331
342
|
* renderer as well saves a renderer from subscribing to anything.
|
|
332
343
|
*/
|
|
333
344
|
private emitStep;
|
|
345
|
+
/**
|
|
346
|
+
* The record to recommend from a search's results, when there are several
|
|
347
|
+
* to choose between and the model can say why from what they state.
|
|
348
|
+
*/
|
|
349
|
+
private pickFrom;
|
|
334
350
|
/** Discard a live prompt and the values typed into it. */
|
|
335
351
|
private cancel;
|
|
336
352
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/harness/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAEL,aAAa,EAGb,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,KAAK,EAAyB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAUhD,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/harness/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAEL,aAAa,EAGb,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,KAAK,EAAyB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,WAAW,E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EAAwE;IACxE,OAAO,CAAC,IAAI,CAAM;gBAEN,IAAI,EAAE,cAAc;IAOhC;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAWhB,4DAA4D;IAC5D,OAAO,CAAC,QAAQ;IAKhB,iDAAiD;IACjD,OAAO,KAAK,OAAO,GAElB;IAED;;;;;;;;;OASG;IACH,IAAI,IAAI,IAAI;IASZ;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAOlB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAYjB;;;;;;;;;;;;;;;;;OAiBG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAqItE;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;;;;;;;;;;;;;OAgBG;IACG,YAAY,CAAC,IAAI,SAAK,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAU9D;;;;;;;;;;OAUG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAU3B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;;;;OAQG;YACW,gBAAgB;IA+C9B;;;;;;;;;OASG;YACW,GAAG;IAgGjB;;;OAGG;IACH,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAKhB;;;OAGG;YACW,QAAQ;IAyBtB,0DAA0D;IAC1D,OAAO,CAAC,MAAM;IAUd;;;;;OAKG;YACW,GAAG;CAqJlB"}
|
package/dist/harness/harness.js
CHANGED
|
@@ -24,6 +24,8 @@ import { decide, policyFor } from './policy.js';
|
|
|
24
24
|
import { buildPlan } from './plan.js';
|
|
25
25
|
import { resolveSlots, summarySlots } from './slots.js';
|
|
26
26
|
import { beginJourney, journeySteps, recordStep } from './steps.js';
|
|
27
|
+
import { extractRecords } from './records.js';
|
|
28
|
+
import { recommend } from './recommend.js';
|
|
27
29
|
import { HANDOFF_SESSION_RESULT, TALK_TO_A_PERSON_TOOL, isHandoffTool } from '../handoff/tools.js';
|
|
28
30
|
/**
|
|
29
31
|
* Whether a reply reads as the model asking rather than answering.
|
|
@@ -194,6 +196,8 @@ export class AgentHarness {
|
|
|
194
196
|
/** The previous request's system prompt and tool names, for the cache hint. */
|
|
195
197
|
this.lastPrompt = '';
|
|
196
198
|
this.lastTools = '';
|
|
199
|
+
/** What the visitor asked this turn, for a recommendation to answer. */
|
|
200
|
+
this.goal = '';
|
|
197
201
|
this.provider = opts.provider ?? new LocalGemmaProvider();
|
|
198
202
|
this.toolSource = opts.toolSource ?? new WebMcpTools();
|
|
199
203
|
this.renderer = opts.renderer;
|
|
@@ -297,6 +301,7 @@ export class AgentHarness {
|
|
|
297
301
|
// rather than the previous turn's.
|
|
298
302
|
this.abort?.abort();
|
|
299
303
|
this.abort = new AbortController();
|
|
304
|
+
this.goal = goal;
|
|
300
305
|
this.renderer.stoppable?.(true);
|
|
301
306
|
// Opened before the model is touched: loading weights is the longest
|
|
302
307
|
// silence in a turn, and the thread should not be empty during it.
|
|
@@ -600,9 +605,11 @@ export class AgentHarness {
|
|
|
600
605
|
detail: resolution.missing.map((s) => humanize(s.name).toLowerCase()).join(', '),
|
|
601
606
|
});
|
|
602
607
|
const plan = buildPlan(resolution.missing, this.opts.groupRelated !== false);
|
|
603
|
-
this.renderer.
|
|
604
|
-
|
|
605
|
-
|
|
608
|
+
if (!this.renderer.inlinePrompts) {
|
|
609
|
+
this.renderer.message('assistant', plan.stepped
|
|
610
|
+
? `I need ${plan.steps.length} more details for ${humanize(tool.name)}.`
|
|
611
|
+
: `One more thing for ${humanize(tool.name)}.`);
|
|
612
|
+
}
|
|
606
613
|
this.renderer.ask({
|
|
607
614
|
tool,
|
|
608
615
|
plan,
|
|
@@ -657,6 +664,38 @@ export class AgentHarness {
|
|
|
657
664
|
recordStep(step);
|
|
658
665
|
this.renderer.step?.(step, journeySteps());
|
|
659
666
|
}
|
|
667
|
+
/**
|
|
668
|
+
* The record to recommend from a search's results, when there are several
|
|
669
|
+
* to choose between and the model can say why from what they state.
|
|
670
|
+
*/
|
|
671
|
+
async pickFrom(res) {
|
|
672
|
+
if (this.opts.recommend === false || !this.goal)
|
|
673
|
+
return null;
|
|
674
|
+
// Records of things, not rows of a type listing: something with a name and a kind.
|
|
675
|
+
const records = extractRecords(res).filter((r) => typeof r.name === 'string' && r['@type'] != null);
|
|
676
|
+
if (records.length < 2)
|
|
677
|
+
return null;
|
|
678
|
+
const bubble = this.renderer.streaming();
|
|
679
|
+
bubble.thinking('Comparing them…');
|
|
680
|
+
try {
|
|
681
|
+
const pick = await recommend({
|
|
682
|
+
provider: this.provider,
|
|
683
|
+
goal: this.goal,
|
|
684
|
+
records,
|
|
685
|
+
now: this.opts.now?.(),
|
|
686
|
+
signal: this.abort?.signal,
|
|
687
|
+
transcribe: withTranscribedCall,
|
|
688
|
+
});
|
|
689
|
+
return pick ? { pick, name: String(records[pick.index].name) } : null;
|
|
690
|
+
}
|
|
691
|
+
catch {
|
|
692
|
+
// Stopped, or the model failed: the results stand on their own.
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
finally {
|
|
696
|
+
bubble.finalize('');
|
|
697
|
+
}
|
|
698
|
+
}
|
|
660
699
|
/** Discard a live prompt and the values typed into it. */
|
|
661
700
|
cancel() {
|
|
662
701
|
// A journey that stops here should say so, not sit waiting for a press
|
|
@@ -695,7 +734,7 @@ export class AgentHarness {
|
|
|
695
734
|
// courier persists the journey as it leaves, and this step has to be in
|
|
696
735
|
// it or the page it lands on shows no reason for being there.
|
|
697
736
|
const handing = isHandoffTool(tool.name);
|
|
698
|
-
|
|
737
|
+
const inFlight = handing
|
|
699
738
|
? { id: 'fill', label: 'Handing the conversation over', status: 'active' }
|
|
700
739
|
: leaving
|
|
701
740
|
? { id: 'navigate', label: `Opening ${leaving.label}`, status: 'active' }
|
|
@@ -703,7 +742,15 @@ export class AgentHarness {
|
|
|
703
742
|
id: 'fill',
|
|
704
743
|
label: readOnly ? 'Looking that up' : `Filling ${humanize(tool.name)}`,
|
|
705
744
|
status: 'active',
|
|
706
|
-
}
|
|
745
|
+
};
|
|
746
|
+
this.emitStep(inFlight);
|
|
747
|
+
// A failure ends the step that was running, so the card never shows it still under way.
|
|
748
|
+
const failed = (detail) => {
|
|
749
|
+
this.emitStep({ ...inFlight, label: 'It did not go through', status: 'failed', detail });
|
|
750
|
+
// The model reads why on its next turn, and can act on it rather than repeat the call.
|
|
751
|
+
messages.push({ role: 'user', content: `[${tool.name} did not go through: ${detail.slice(0, 400)}]` });
|
|
752
|
+
this.opts.onMessages?.(messages);
|
|
753
|
+
};
|
|
707
754
|
try {
|
|
708
755
|
const res = await this.toolSource.execTool(tool, tool.name, values);
|
|
709
756
|
const text = extractResult(res);
|
|
@@ -717,7 +764,7 @@ export class AgentHarness {
|
|
|
717
764
|
count: countRecords(res, text),
|
|
718
765
|
});
|
|
719
766
|
if (res?.isError) {
|
|
720
|
-
|
|
767
|
+
failed(text || 'Failed');
|
|
721
768
|
this.renderer.toolError(tool, text || 'Failed');
|
|
722
769
|
return;
|
|
723
770
|
}
|
|
@@ -730,6 +777,11 @@ export class AgentHarness {
|
|
|
730
777
|
// Said from what we know, not from what came back: a registry may
|
|
731
778
|
// return the whole response object as JSON, and that is not a
|
|
732
779
|
// sentence to put in front of anyone.
|
|
780
|
+
if (this.renderer.left) {
|
|
781
|
+
const carried = res?.structuredContent?.[HANDOFF_RESULT];
|
|
782
|
+
this.renderer.left(tool, (visiting ?? leaving)?.label ?? carried?.label ?? null);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
733
785
|
this.renderer.message('assistant', visiting
|
|
734
786
|
? `Opening ${visiting.label}…`
|
|
735
787
|
: leaving
|
|
@@ -742,7 +794,10 @@ export class AgentHarness {
|
|
|
742
794
|
const started = res?.structuredContent?.[HANDOFF_SESSION_RESULT];
|
|
743
795
|
if (handing && started) {
|
|
744
796
|
const who = started.label ?? 'another agent';
|
|
745
|
-
this
|
|
797
|
+
// Handing over is where this journey ends; the conversation carries on outside it. Without a
|
|
798
|
+
// `submit` step the card would read as running for as long as the handoff lasts.
|
|
799
|
+
this.emitStep({ id: 'fill', label: 'Handed the conversation over', status: 'done' });
|
|
800
|
+
this.emitStep({ id: 'submit', label: `Handed to ${who}`, status: 'done' });
|
|
746
801
|
messages.push({
|
|
747
802
|
role: 'user',
|
|
748
803
|
content: `[${tool.name}: the conversation was handed to ${who}. Their replies go to the visitor directly.]`,
|
|
@@ -766,8 +821,13 @@ export class AgentHarness {
|
|
|
766
821
|
status: 'done',
|
|
767
822
|
});
|
|
768
823
|
if (readOnly) {
|
|
769
|
-
this.
|
|
770
|
-
|
|
824
|
+
const picked = await this.pickFrom(res);
|
|
825
|
+
this.renderer.results(tool, res, picked ? { pick: picked.pick } : undefined);
|
|
826
|
+
messages.push({
|
|
827
|
+
role: 'user',
|
|
828
|
+
content: `[${tool.name} returned: ${text.slice(0, 400)}]` +
|
|
829
|
+
(picked ? ` [You recommended ${picked.name}: ${picked.pick.reasons.join(' ')}]` : ''),
|
|
830
|
+
});
|
|
771
831
|
}
|
|
772
832
|
else {
|
|
773
833
|
this.renderer.detail(tool, values, text);
|
|
@@ -780,7 +840,7 @@ export class AgentHarness {
|
|
|
780
840
|
}
|
|
781
841
|
catch (err) {
|
|
782
842
|
const message = String(err?.message || err);
|
|
783
|
-
|
|
843
|
+
failed(message);
|
|
784
844
|
working.finalize('');
|
|
785
845
|
this.renderer.status('');
|
|
786
846
|
// A call that threw is the main reason to open a trace.
|