@memberjunction/ai-agents 6.2.0-edge.1 → 6.2.0-edge.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 +18 -0
- package/dist/AgentDecisionService.d.ts +90 -0
- package/dist/AgentDecisionService.d.ts.map +1 -0
- package/dist/AgentDecisionService.js +159 -0
- package/dist/AgentDecisionService.js.map +1 -0
- package/dist/AgentRunner.d.ts +9 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +23 -7
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ConversationCompactionManager.d.ts +7 -1
- package/dist/ConversationCompactionManager.d.ts.map +1 -1
- package/dist/ConversationCompactionManager.js +4 -1
- package/dist/ConversationCompactionManager.js.map +1 -1
- package/dist/KnowledgeAgent.d.ts.map +1 -1
- package/dist/KnowledgeAgent.js +6 -6
- package/dist/KnowledgeAgent.js.map +1 -1
- package/dist/PayloadFeedbackManager.d.ts +116 -14
- package/dist/PayloadFeedbackManager.d.ts.map +1 -1
- package/dist/PayloadFeedbackManager.js +229 -88
- package/dist/PayloadFeedbackManager.js.map +1 -1
- package/dist/agent-context-injector.d.ts +47 -3
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +77 -10
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.d.ts +13 -0
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +24 -5
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +97 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +281 -24
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/flow-graph-executor.d.ts +12 -1
- package/dist/agent-types/flow-graph-executor.d.ts.map +1 -1
- package/dist/agent-types/flow-graph-executor.js +25 -1
- package/dist/agent-types/flow-graph-executor.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +239 -66
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +47 -2
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +12 -1
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +26 -0
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +115 -5
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +527 -10
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +1779 -110
- package/dist/base-agent.js.map +1 -1
- package/dist/catalog-narrowing.d.ts +136 -0
- package/dist/catalog-narrowing.d.ts.map +1 -0
- package/dist/catalog-narrowing.js +212 -0
- package/dist/catalog-narrowing.js.map +1 -0
- package/dist/decision-discovery.d.ts +401 -0
- package/dist/decision-discovery.d.ts.map +1 -0
- package/dist/decision-discovery.js +511 -0
- package/dist/decision-discovery.js.map +1 -0
- package/dist/finish-if-mode-warnings.d.ts +39 -0
- package/dist/finish-if-mode-warnings.d.ts.map +1 -0
- package/dist/finish-if-mode-warnings.js +78 -0
- package/dist/finish-if-mode-warnings.js.map +1 -0
- package/dist/finish-if-state.d.ts +72 -0
- package/dist/finish-if-state.d.ts.map +1 -0
- package/dist/finish-if-state.js +109 -0
- package/dist/finish-if-state.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-manager-agent.d.ts +108 -2
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +172 -9
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/memory-note-gate.d.ts +208 -0
- package/dist/memory-note-gate.d.ts.map +1 -0
- package/dist/memory-note-gate.js +294 -0
- package/dist/memory-note-gate.js.map +1 -0
- package/dist/native-tools/action-tool-builder.d.ts +14 -0
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +62 -7
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/control-tools.d.ts +17 -1
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +40 -3
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/realtime/bridge-host-params.d.ts +22 -0
- package/dist/realtime/bridge-host-params.d.ts.map +1 -0
- package/dist/realtime/bridge-host-params.js +53 -0
- package/dist/realtime/bridge-host-params.js.map +1 -0
- package/dist/realtime/bridge-realtime-session-factory.d.ts +23 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +22 -6
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.d.ts.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +15 -9
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/bridge-session-transcript-sink.d.ts +37 -0
- package/dist/realtime/bridge-session-transcript-sink.d.ts.map +1 -0
- package/dist/realtime/bridge-session-transcript-sink.js +58 -0
- package/dist/realtime/bridge-session-transcript-sink.js.map +1 -0
- package/dist/realtime/realtime-client-session-service.d.ts +117 -12
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +162 -39
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-resolution.d.ts +90 -0
- package/dist/realtime/realtime-coagent-resolution.d.ts.map +1 -0
- package/dist/realtime/realtime-coagent-resolution.js +186 -0
- package/dist/realtime/realtime-coagent-resolution.js.map +1 -0
- package/dist/realtime/realtime-delegation-narrator.d.ts +97 -0
- package/dist/realtime/realtime-delegation-narrator.d.ts.map +1 -0
- package/dist/realtime/realtime-delegation-narrator.js +162 -0
- package/dist/realtime/realtime-delegation-narrator.js.map +1 -0
- package/dist/realtime/realtime-session-runner.d.ts +2 -82
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +12 -187
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.d.ts +8 -3
- package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.js +3 -3
- package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
- package/dist/rubric-evaluation-agent-runner.d.ts +2 -0
- package/dist/rubric-evaluation-agent-runner.d.ts.map +1 -0
- package/dist/rubric-evaluation-agent-runner.js +47 -0
- package/dist/rubric-evaluation-agent-runner.js.map +1 -0
- package/dist/self-check.d.ts +101 -0
- package/dist/self-check.d.ts.map +1 -0
- package/dist/self-check.js +74 -0
- package/dist/self-check.js.map +1 -0
- package/package.json +19 -18
package/README.md
CHANGED
|
@@ -138,6 +138,21 @@ Abstract base that all agent types extend. Defines the `DetermineNextStep()` int
|
|
|
138
138
|
|
|
139
139
|
Conversational agent that runs in a loop: prompt -> decide -> act -> repeat. Best for interactive, chat-based agents. The LLM decides the next step at each iteration by producing a structured JSON response.
|
|
140
140
|
|
|
141
|
+
##### Decision models
|
|
142
|
+
|
|
143
|
+
An agent can ask a fast decision model typed questions in six places on its own. One master switch governs all of them: the Loop prompt param **`decisionsEnabled`**, `false` by default. Unless it is `true`, the agent never asks a decision model on its own, whatever the other settings say: their docs stay out of the prompt and the runtime refuses the call. With it `true`, each use still needs its own setting, and each of those is off by default too:
|
|
144
|
+
|
|
145
|
+
| Use | Its own setting |
|
|
146
|
+
|---|---|
|
|
147
|
+
| Inline `decisions` on a turn | `includeDecisionsDocs: true` |
|
|
148
|
+
| `finishIf` gates on an Actions or Sub-Agent step | `finishIfMode: 'shadow'` or `'on'` |
|
|
149
|
+
| Decision discovery (suggest an agent before the first prompt) | `decisionDiscovery: true` |
|
|
150
|
+
| Payload change check | `payloadFeedbackCheck: true` |
|
|
151
|
+
| Catalog narrowing | `maxActionsInPrompt` / `maxSubAgentsInPrompt` > 0 |
|
|
152
|
+
| Memory Manager note gate | run `data.enableDecisionGate: true` |
|
|
153
|
+
|
|
154
|
+
Set it in an agent's `AgentTypePromptParams` (`{"decisionsEnabled": true, "finishIfMode": "shadow"}`) or for one run in `data.__agentTypePromptParams`. Uses someone placed explicitly do not read it: a Flow or task-graph Decision step, the Run Decision action, and other direct callers of `AgentDecisionService`. See the [Decision Models guide](./docs/loop-agent-decisions.md).
|
|
155
|
+
|
|
141
156
|
#### FlowAgentType
|
|
142
157
|
|
|
143
158
|
Step-based agent that follows a predefined flow graph — steps with explicit conditional paths between them. Best for deterministic workflows where the execution path is known in advance.
|
|
@@ -150,6 +165,8 @@ Consequences worth knowing before you debug one:
|
|
|
150
165
|
- **A run that needs the result walks the flow in-process.** A sub-agent run (one with `parentRun`) does this automatically, and a top-level caller opts in with `agentTypeParams.executionMode: 'inRun'` (`FlowAgentExecuteParams`). The run returns the flow's final payload, as in 5.x, and `startAtStep` works. A dispatched run that reaches the walker by mistake is refused at its choke point.
|
|
151
166
|
- **The mode is on the run.** A completed `Decision` step named "Workflow runs in this run" or "Workflow runs on the task-graph dispatcher" records which engine ran it and why.
|
|
152
167
|
- **A dispatched `Sub-Agent` node starts its own `AIAgentRun`**, linked from `Task.AgentRunID` and parented to the submitting run. If that sub-agent is itself a Flow agent, it runs in-process and returns its result to the task.
|
|
168
|
+
- **A `Decision` step routes the same way in both modes.** Paths read its answers only through `decisions.<key>.<question>`; its `stepResult.result` is the payload, which carries no answers. A flow with a Decision step is compiled and validated before its first step in-run too, so an incomplete Choice fork, a decision read before it can answer, or one read through the payload is refused in both modes. An answer below its `minConfidence` stops an in-run flow (the dispatcher holds the fork, and `Retry` on the step asks again). A failed decision call is a failed step: the paths that read its answers are passed over, and a recovery path such as `stepResult.Success === false` is taken whatever its rank.
|
|
169
|
+
- **Answers live in the run, not the payload.** A run started with `startAtStep` past a Decision step has no answers from it, so every path that reads that decision stops the run with the reason. Start at or before the Decision step to route on it.
|
|
153
170
|
|
|
154
171
|
See the **[Workflows and Task Graphs Guide](../../../guides/WORKFLOW_AND_TASK_GRAPH_GUIDE.md)** for the full model: node kinds, exclusive groups, payload mappings, loops, failure semantics, observability, and a worked configuration example.
|
|
155
172
|
|
|
@@ -502,6 +519,7 @@ Detailed guides are available in the [`docs/`](./docs/) directory:
|
|
|
502
519
|
| Guide | Description |
|
|
503
520
|
|---|---|
|
|
504
521
|
| [Actions Guide](./docs/actions-guide.md) | Action discovery, execution, result lifecycle, expiration/compaction, context recovery |
|
|
522
|
+
| [Decision Models](./docs/loop-agent-decisions.md) | The `decisionsEnabled` master switch, then each automatic use: inline decisions, finishIf gates, discovery, the payload change check, catalog narrowing, the Memory Manager note gate |
|
|
505
523
|
| [Prompt-Cache Performance and Cost Briefing](./docs/PROMPT_CACHE_PERFORMANCE_BRIEFING.md) | Before/after cached share and cost per model and topology for the trailing runtime-state layout; the action circuit breaker's before/after; what to re-measure |
|
|
506
524
|
| [Agent Prompt Caching Guide](../../../guides/AGENT_PROMPT_CACHING_GUIDE.md) | Repo-level guide: the trailing-state layout, the `PrefixPromptCache` flag from the model catalog, the Anthropic breakpoint seam, specialization placement, the circuit breaker |
|
|
507
525
|
| [Client Tools Guide](./docs/CLIENT_TOOLS_GUIDE.md) | Browser-side tool invocation, runtime decoration, timeout config, prompt design, security |
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Service for executing decision questions on behalf of agents.
|
|
3
|
+
*
|
|
4
|
+
* Wraps AIDecisionRunner and resolves decision prompts from the AIEngine catalog.
|
|
5
|
+
*
|
|
6
|
+
* @module @memberjunction/ai-agents
|
|
7
|
+
* @author MemberJunction.com
|
|
8
|
+
* @since 2.132.0
|
|
9
|
+
*/
|
|
10
|
+
import { UserInfo } from '@memberjunction/core';
|
|
11
|
+
import { DecisionQuestion, DecisionAnswer } from '@memberjunction/ai';
|
|
12
|
+
import { AIDecisionRunResult } from '@memberjunction/ai-prompts';
|
|
13
|
+
import { AgentDecisionAnswerSummary, type AIPromptExecutionScope } from '@memberjunction/ai-core-plus';
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for the AgentDecisionService.Ask method.
|
|
16
|
+
*/
|
|
17
|
+
export interface AgentDecisionAskParams {
|
|
18
|
+
/**
|
|
19
|
+
* The state the questions are asked about.
|
|
20
|
+
*/
|
|
21
|
+
State: string | Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Named questions to evaluate.
|
|
24
|
+
*/
|
|
25
|
+
Questions: Record<string, DecisionQuestion>;
|
|
26
|
+
/**
|
|
27
|
+
* Context user executing the decision.
|
|
28
|
+
*/
|
|
29
|
+
ContextUser: UserInfo;
|
|
30
|
+
/**
|
|
31
|
+
* Optional agent ID initiating the decision.
|
|
32
|
+
*/
|
|
33
|
+
AgentID?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Optional prompt name to resolve from AIEngine. Defaults to 'Default Decision'.
|
|
36
|
+
*/
|
|
37
|
+
PromptName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The asking run's execution scope — its configuration, runtime API keys and credential scope.
|
|
40
|
+
* Without it a decision resolves no run key and, under the default scope, answers on the
|
|
41
|
+
* platform's keys inside a customer's run; under `'RuntimeOnly'` that is exactly what must not
|
|
42
|
+
* happen. `ContextUser` still names the user.
|
|
43
|
+
*/
|
|
44
|
+
ExecutionScope?: AIPromptExecutionScope;
|
|
45
|
+
/**
|
|
46
|
+
* Optional cancellation token to abort execution.
|
|
47
|
+
*/
|
|
48
|
+
CancellationToken?: AbortSignal;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The questions of one decision request after their shapes are checked: the valid ones mapped onto
|
|
52
|
+
* BaseDecision's shape, and why each invalid one was dropped.
|
|
53
|
+
*/
|
|
54
|
+
export interface DecisionQuestionMapping {
|
|
55
|
+
/** The valid questions, keyed as the agent keyed them, in BaseDecision's (PascalCase) shape. */
|
|
56
|
+
Questions: Record<string, DecisionQuestion>;
|
|
57
|
+
/** One reason per dropped question, naming its key. Empty when every question was valid. */
|
|
58
|
+
Invalid: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Asks decision questions for an agent run through AIDecisionRunner and the configured decision prompt.
|
|
62
|
+
*/
|
|
63
|
+
export declare class AgentDecisionService {
|
|
64
|
+
/**
|
|
65
|
+
* The decision prompt used when none is configured.
|
|
66
|
+
*/
|
|
67
|
+
static readonly DEFAULT_PROMPT_NAME = "Default Decision";
|
|
68
|
+
/**
|
|
69
|
+
* Evaluates decision questions against the provided state using the configured decision prompt.
|
|
70
|
+
* Never throws: on failure or missing prompt, returns a failed AIDecisionRunResult.
|
|
71
|
+
*/
|
|
72
|
+
Ask(args: AgentDecisionAskParams): Promise<AIDecisionRunResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks each question's shape and maps the valid ones from the LLM-facing shape (camelCase) onto
|
|
75
|
+
* BaseDecision's (PascalCase). The questions are unchecked model output, so an invalid one is
|
|
76
|
+
* dropped, with its reason, rather than failing the others.
|
|
77
|
+
*/
|
|
78
|
+
static ToDecisionQuestions(questions: Record<string, unknown>): DecisionQuestionMapping;
|
|
79
|
+
/** Maps one question, or returns why it is invalid. */
|
|
80
|
+
private static toDecisionQuestion;
|
|
81
|
+
/** A Choice needs a non-empty `options` array of `{ value, description }` strings. */
|
|
82
|
+
private static toChoiceQuestion;
|
|
83
|
+
/** A Score needs a non-empty `levels` array of strings, lowest first. */
|
|
84
|
+
private static toScoreQuestion;
|
|
85
|
+
/**
|
|
86
|
+
* Summarises answers for the model: probability, or value and confidence.
|
|
87
|
+
*/
|
|
88
|
+
static SummarizeAnswers(answers: Record<string, DecisionAnswer>): Record<string, AgentDecisionAnswerSummary>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=AgentDecisionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentDecisionService.d.ts","sourceRoot":"","sources":["../src/AgentDecisionService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAsC,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,0BAA0B,EAA4B,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEjI;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAExC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE5C;;OAEG;IACH,WAAW,EAAE,QAAQ,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;IAExC;;OAEG;IACH,iBAAiB,CAAC,EAAE,WAAW,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACpC,gGAAgG;IAChG,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE5C,4FAA4F;IAC5F,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAqBD;;GAEG;AACH,qBAAa,oBAAoB;IAC7B;;OAEG;IACH,gBAAuB,mBAAmB,sBAAsB;IAEhE;;;OAGG;IACU,GAAG,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkC5E;;;;OAIG;WACW,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,uBAAuB;IAa9F,uDAAuD;IACvD,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAmBjC,sFAAsF;IACtF,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAc/B,yEAAyE;IACzE,OAAO,CAAC,MAAM,CAAC,eAAe;IAO9B;;OAEG;WACW,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC;CAyBtH"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Service for executing decision questions on behalf of agents.
|
|
3
|
+
*
|
|
4
|
+
* Wraps AIDecisionRunner and resolves decision prompts from the AIEngine catalog.
|
|
5
|
+
*
|
|
6
|
+
* @module @memberjunction/ai-agents
|
|
7
|
+
* @author MemberJunction.com
|
|
8
|
+
* @since 2.132.0
|
|
9
|
+
*/
|
|
10
|
+
import { AIEngine } from '@memberjunction/aiengine';
|
|
11
|
+
import { AIDecisionRunner, AIDecisionParams } from '@memberjunction/ai-prompts';
|
|
12
|
+
import { PickPromptExecutionScope } from '@memberjunction/ai-core-plus';
|
|
13
|
+
/** A plain object, as opposed to null, an array or a primitive. */
|
|
14
|
+
function isPlainObject(value) {
|
|
15
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
/** An array whose every item passes `guard`. */
|
|
18
|
+
function isArrayOf(value, guard) {
|
|
19
|
+
return Array.isArray(value) && value.every(item => guard(item));
|
|
20
|
+
}
|
|
21
|
+
function isString(value) {
|
|
22
|
+
return typeof value === 'string';
|
|
23
|
+
}
|
|
24
|
+
/** One option of a Choice question, as the model writes it. */
|
|
25
|
+
function isChoiceOption(value) {
|
|
26
|
+
return isPlainObject(value) && typeof value.value === 'string' && typeof value.description === 'string';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Asks decision questions for an agent run through AIDecisionRunner and the configured decision prompt.
|
|
30
|
+
*/
|
|
31
|
+
export class AgentDecisionService {
|
|
32
|
+
/**
|
|
33
|
+
* The decision prompt used when none is configured.
|
|
34
|
+
*/
|
|
35
|
+
static { this.DEFAULT_PROMPT_NAME = 'Default Decision'; }
|
|
36
|
+
/**
|
|
37
|
+
* Evaluates decision questions against the provided state using the configured decision prompt.
|
|
38
|
+
* Never throws: on failure or missing prompt, returns a failed AIDecisionRunResult.
|
|
39
|
+
*/
|
|
40
|
+
async Ask(args) {
|
|
41
|
+
try {
|
|
42
|
+
await AIEngine.Instance.Config(false, args.ContextUser);
|
|
43
|
+
const targetName = (args.PromptName ?? AgentDecisionService.DEFAULT_PROMPT_NAME).trim().toLowerCase();
|
|
44
|
+
const prompt = AIEngine.Instance.Prompts?.find(p => (p.Name ?? '').trim().toLowerCase() === targetName);
|
|
45
|
+
if (!prompt) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
errorMessage: `Decision prompt "${args.PromptName ?? AgentDecisionService.DEFAULT_PROMPT_NAME}" not found`,
|
|
49
|
+
Answers: {},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const params = new AIDecisionParams();
|
|
53
|
+
if (args.ExecutionScope) {
|
|
54
|
+
Object.assign(params, PickPromptExecutionScope(args.ExecutionScope));
|
|
55
|
+
}
|
|
56
|
+
params.prompt = prompt;
|
|
57
|
+
params.contextUser = args.ContextUser;
|
|
58
|
+
params.State = args.State;
|
|
59
|
+
params.Questions = args.Questions;
|
|
60
|
+
params.cancellationToken = args.CancellationToken;
|
|
61
|
+
params.agentId = args.AgentID;
|
|
62
|
+
return await new AIDecisionRunner().ExecuteDecision(params);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
success: false,
|
|
67
|
+
errorMessage: `The decision call failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
68
|
+
Answers: {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks each question's shape and maps the valid ones from the LLM-facing shape (camelCase) onto
|
|
74
|
+
* BaseDecision's (PascalCase). The questions are unchecked model output, so an invalid one is
|
|
75
|
+
* dropped, with its reason, rather than failing the others.
|
|
76
|
+
*/
|
|
77
|
+
static ToDecisionQuestions(questions) {
|
|
78
|
+
const mapping = { Questions: {}, Invalid: [] };
|
|
79
|
+
for (const [key, candidate] of Object.entries(questions)) {
|
|
80
|
+
const mapped = AgentDecisionService.toDecisionQuestion(candidate);
|
|
81
|
+
if (typeof mapped === 'string') {
|
|
82
|
+
mapping.Invalid.push(`Question "${key}" ${mapped}`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
mapping.Questions[key] = mapped;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return mapping;
|
|
89
|
+
}
|
|
90
|
+
/** Maps one question, or returns why it is invalid. */
|
|
91
|
+
static toDecisionQuestion(candidate) {
|
|
92
|
+
if (!isPlainObject(candidate)) {
|
|
93
|
+
return 'is not an object';
|
|
94
|
+
}
|
|
95
|
+
if (typeof candidate.instructions !== 'string') {
|
|
96
|
+
return 'has no "instructions" string';
|
|
97
|
+
}
|
|
98
|
+
switch (candidate.kind) {
|
|
99
|
+
case 'Likelihood':
|
|
100
|
+
return { Kind: 'Likelihood', Instructions: candidate.instructions };
|
|
101
|
+
case 'Choice':
|
|
102
|
+
return AgentDecisionService.toChoiceQuestion(candidate.instructions, candidate.options);
|
|
103
|
+
case 'Score':
|
|
104
|
+
return AgentDecisionService.toScoreQuestion(candidate.instructions, candidate.levels);
|
|
105
|
+
default:
|
|
106
|
+
return `has an unknown kind "${String(candidate.kind)}" (use Likelihood, Choice or Score)`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** A Choice needs a non-empty `options` array of `{ value, description }` strings. */
|
|
110
|
+
static toChoiceQuestion(instructions, options) {
|
|
111
|
+
if (!isArrayOf(options, isChoiceOption) || options.length === 0) {
|
|
112
|
+
return 'is a Choice without a non-empty "options" array of { value, description } strings';
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
Kind: 'Choice',
|
|
116
|
+
Instructions: instructions,
|
|
117
|
+
Options: options.map(opt => ({
|
|
118
|
+
Value: opt.value,
|
|
119
|
+
Description: opt.description,
|
|
120
|
+
})),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** A Score needs a non-empty `levels` array of strings, lowest first. */
|
|
124
|
+
static toScoreQuestion(instructions, levels) {
|
|
125
|
+
if (!isArrayOf(levels, isString) || levels.length === 0) {
|
|
126
|
+
return 'is a Score without a non-empty "levels" array of strings';
|
|
127
|
+
}
|
|
128
|
+
return { Kind: 'Score', Instructions: instructions, Levels: [...levels] };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Summarises answers for the model: probability, or value and confidence.
|
|
132
|
+
*/
|
|
133
|
+
static SummarizeAnswers(answers) {
|
|
134
|
+
const result = {};
|
|
135
|
+
for (const [key, a] of Object.entries(answers)) {
|
|
136
|
+
switch (a.Kind) {
|
|
137
|
+
case 'Likelihood':
|
|
138
|
+
result[key] = {
|
|
139
|
+
probability: a.Probability,
|
|
140
|
+
};
|
|
141
|
+
break;
|
|
142
|
+
case 'Choice':
|
|
143
|
+
result[key] = {
|
|
144
|
+
value: a.Value,
|
|
145
|
+
confidence: a.Confidence,
|
|
146
|
+
};
|
|
147
|
+
break;
|
|
148
|
+
case 'Score':
|
|
149
|
+
result[key] = {
|
|
150
|
+
value: a.Value,
|
|
151
|
+
confidence: a.Confidence,
|
|
152
|
+
};
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=AgentDecisionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentDecisionService.js","sourceRoot":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E,CAAC,CAAC,WAAW;qBAC7B,CAAC;oBACF,MAAM;gBACV,KAAK,QAAQ;oBACT,MAAM,CAAC,GAAG,CAAC,GAAG;wBACV,KAAK,EAAE,CAAC,CAAC,KAAK;wBACd,UAAU,EAAE,CAAC,CAAC,UAAU;qBAC3B,CAAC;oBACF,MAAM;gBACV,KAAK,OAAO;oBACR,MAAM,CAAC,GAAG,CAAC,GAAG;wBACV,KAAK,EAAE,CAAC,CAAC,KAAK;wBACd,UAAU,EAAE,CAAC,CAAC,UAAU;qBAC3B,CAAC;oBACF,MAAM;YACd,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC"}
|
package/dist/AgentRunner.d.ts
CHANGED
|
@@ -51,6 +51,13 @@ export declare function selectPrimaryArtifact(fileArtifacts: readonly CreatedArt
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
export declare class AgentRunner {
|
|
54
|
+
/**
|
|
55
|
+
* Why a conversation-detail `Save()` returned false, for an error or log line. The owner gate in
|
|
56
|
+
* `MJConversationDetailEntityExtended` refuses a non-owner's write (e.g. the elevated System user
|
|
57
|
+
* on a widget guest's conversation) and records the reason ONLY on `LatestResult` — it logs
|
|
58
|
+
* nothing itself — so a caller that reports a fixed string loses it (MJ#4791).
|
|
59
|
+
*/
|
|
60
|
+
private static saveFailureReason;
|
|
54
61
|
/** Fallback artifact type for agent payloads when the agent declares no DefaultArtifactTypeID. */
|
|
55
62
|
private static readonly JSON_ARTIFACT_TYPE_ID;
|
|
56
63
|
/**
|
|
@@ -395,6 +402,8 @@ export declare class AgentRunner {
|
|
|
395
402
|
*
|
|
396
403
|
* @param userMessage - The first user message to base the name on
|
|
397
404
|
* @param contextUser - User context for prompt execution
|
|
405
|
+
* @param credentials - The run's configuration, runtime keys and credential scope, so naming runs
|
|
406
|
+
* on the same credentials as the agent run it names
|
|
398
407
|
* @returns Generated conversation name and description, or null if generation failed
|
|
399
408
|
* @private
|
|
400
409
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentRunner.d.ts","sourceRoot":"","sources":["../src/AgentRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentRunner.d.ts","sourceRoot":"","sources":["../src/AgentRunner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAsG,QAAQ,EAAE,iBAAiB,EAAsC,MAAM,sBAAsB,CAAC;AAG3M,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAA4D,MAAM,8BAA8B,CAAC;AAC5K,OAAO,EAA+C,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAwBzG;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACjC,aAAa,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,EACzD,eAAe,EAAE,mBAAmB,GAAG,SAAS,GACjD,mBAAmB,GAAG,SAAS,CAEjC;AAED,qDAAqD;AACrD,wBAAgB,qBAAqB,CACjC,aAAa,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,EACzD,eAAe,EAAE,mBAAmB,GAAG,SAAS,GACjD,mBAAmB,GAAG,SAAS,CAEjC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAW;IACpB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAIhC,kGAAkG;IAClG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAA0C;IAEvF;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAO;IAEvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;gBAElC,QAAQ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,EAAE,aAAa,EAAE,EAC5B,oBAAoB,EAAE,MAAM,EAC5B,WAAW,EAAE,QAAQ,EACrB,wBAAwB,CAAC,EAAE,MAAM,EACjC,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,uBAAuB,CAAC,EAAE,OAAO,GAClC,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAoBjC;0FACsF;YACxE,iBAAiB;IAyB/B;;;;;;OAMG;YACW,qBAAqB;IAmBnC;;;;OAIG;YACW,yBAAyB;IAkHvC;;;;OAIG;YACW,kBAAkB;IAsBhC,0FAA0F;YAC5E,wBAAwB;IAqBtC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAkB5B;;;;;;;;;;;;;;;;;;OAkBG;YACW,gCAAgC;IA0C9C;;;;;;;;;;;;;;;;;OAiBG;YACW,4BAA4B;IAY1C;;;OAGG;YACW,qBAAqB;IAYnC;;;;;;;OAOG;YACW,2BAA2B;IAkIzC;;;;;;;;;;;;;;;;OAgBG;YACW,uBAAuB;IAgDrC;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAS7B;;;;;;;;OAQG;YACW,2BAA2B;CAyC5C"}
|
package/dist/AgentRunner.js
CHANGED
|
@@ -53,6 +53,15 @@ export function selectPrimaryArtifact(fileArtifacts, payloadArtifact) {
|
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
export class AgentRunner {
|
|
56
|
+
/**
|
|
57
|
+
* Why a conversation-detail `Save()` returned false, for an error or log line. The owner gate in
|
|
58
|
+
* `MJConversationDetailEntityExtended` refuses a non-owner's write (e.g. the elevated System user
|
|
59
|
+
* on a widget guest's conversation) and records the reason ONLY on `LatestResult` — it logs
|
|
60
|
+
* nothing itself — so a caller that reports a fixed string loses it (MJ#4791).
|
|
61
|
+
*/
|
|
62
|
+
static saveFailureReason(entity) {
|
|
63
|
+
return entity.LatestResult?.CompleteMessage?.trim() || 'no failure detail recorded';
|
|
64
|
+
}
|
|
56
65
|
/** Fallback artifact type for agent payloads when the agent declares no DefaultArtifactTypeID. */
|
|
57
66
|
static { this.JSON_ARTIFACT_TYPE_ID = 'ae674c7e-ea0d-49ea-89e4-0649f5eb20d4'; }
|
|
58
67
|
/**
|
|
@@ -216,7 +225,7 @@ export class AgentRunner {
|
|
|
216
225
|
let conversationDescription = null;
|
|
217
226
|
if (!conversationName && options.userMessage) {
|
|
218
227
|
// Try to generate a name using the "Name Conversation" prompt (same as UI)
|
|
219
|
-
const nameResult = await this.generateConversationName(options.userMessage, contextUser, md);
|
|
228
|
+
const nameResult = await this.generateConversationName(options.userMessage, contextUser, md, params);
|
|
220
229
|
if (nameResult) {
|
|
221
230
|
conversationName = nameResult.name;
|
|
222
231
|
conversationDescription = nameResult.description;
|
|
@@ -253,7 +262,7 @@ export class AgentRunner {
|
|
|
253
262
|
userMessageDetail.TestRunID = options.testRunId;
|
|
254
263
|
}
|
|
255
264
|
if (!(await userMessageDetail.Save())) {
|
|
256
|
-
throw new Error(
|
|
265
|
+
throw new Error(`Failed to create user message conversation detail: ${AgentRunner.saveFailureReason(userMessageDetail)}`);
|
|
257
266
|
}
|
|
258
267
|
userMessageDetailId = userMessageDetail.ID;
|
|
259
268
|
LogStatus(`Created user message detail ${userMessageDetailId}`);
|
|
@@ -271,7 +280,7 @@ export class AgentRunner {
|
|
|
271
280
|
agentResponseDetail.TestRunID = options.testRunId;
|
|
272
281
|
}
|
|
273
282
|
if (!(await agentResponseDetail.Save())) {
|
|
274
|
-
throw new Error(
|
|
283
|
+
throw new Error(`Failed to create agent response conversation detail: ${AgentRunner.saveFailureReason(agentResponseDetail)}`);
|
|
275
284
|
}
|
|
276
285
|
agentResponseDetailId = agentResponseDetail.ID;
|
|
277
286
|
LogStatus(`Created agent response detail ${agentResponseDetailId}`);
|
|
@@ -299,7 +308,7 @@ export class AgentRunner {
|
|
|
299
308
|
agentResponseDetail.Message = progress.message;
|
|
300
309
|
const saved = await agentResponseDetail.Save();
|
|
301
310
|
if (!saved) {
|
|
302
|
-
LogError(
|
|
311
|
+
LogError(`Failed to save agent response detail progress update: ${AgentRunner.saveFailureReason(agentResponseDetail)}`);
|
|
303
312
|
}
|
|
304
313
|
}
|
|
305
314
|
// Call original callback if provided
|
|
@@ -387,7 +396,7 @@ export class AgentRunner {
|
|
|
387
396
|
}
|
|
388
397
|
const saved = await agentResponseDetail.Save();
|
|
389
398
|
if (!saved) {
|
|
390
|
-
LogError(`Failed to save agent response detail ${agentResponseDetailId} with final status`);
|
|
399
|
+
LogError(`Failed to save agent response detail ${agentResponseDetailId} with final status: ${AgentRunner.saveFailureReason(agentResponseDetail)}`);
|
|
391
400
|
}
|
|
392
401
|
LogStatus(`Updated agent response detail ${agentResponseDetailId} with final status: ${agentResponseDetail.Status}`);
|
|
393
402
|
}
|
|
@@ -498,7 +507,9 @@ export class AgentRunner {
|
|
|
498
507
|
agentResponseDetail.Status = 'Error';
|
|
499
508
|
agentResponseDetail.Message = errorMessage;
|
|
500
509
|
agentResponseDetail.Error = errorMessage;
|
|
501
|
-
await agentResponseDetail.Save()
|
|
510
|
+
if (!(await agentResponseDetail.Save())) {
|
|
511
|
+
LogError(`Failed to persist Error on conversation detail ${agentResponseDetail.ID}: ${AgentRunner.saveFailureReason(agentResponseDetail)}`);
|
|
512
|
+
}
|
|
502
513
|
}
|
|
503
514
|
catch (persistError) {
|
|
504
515
|
LogError(`Failed to persist Error on conversation detail after agent crash: ${persistError}`, undefined, persistError);
|
|
@@ -1075,10 +1086,12 @@ export class AgentRunner {
|
|
|
1075
1086
|
*
|
|
1076
1087
|
* @param userMessage - The first user message to base the name on
|
|
1077
1088
|
* @param contextUser - User context for prompt execution
|
|
1089
|
+
* @param credentials - The run's configuration, runtime keys and credential scope, so naming runs
|
|
1090
|
+
* on the same credentials as the agent run it names
|
|
1078
1091
|
* @returns Generated conversation name and description, or null if generation failed
|
|
1079
1092
|
* @private
|
|
1080
1093
|
*/
|
|
1081
|
-
async generateConversationName(userMessage, contextUser, provider) {
|
|
1094
|
+
async generateConversationName(userMessage, contextUser, provider, credentials) {
|
|
1082
1095
|
try {
|
|
1083
1096
|
// Import AIPromptRunner, AIPromptParams, and AIEngine
|
|
1084
1097
|
const { AIPromptRunner } = await import('@memberjunction/ai-prompts');
|
|
@@ -1099,6 +1112,9 @@ export class AgentRunner {
|
|
|
1099
1112
|
promptParams.UserID = ResolvePromptRunUserID({ ContextUser: contextUser }) ?? undefined;
|
|
1100
1113
|
promptParams.conversationMessages = [{ role: 'user', content: userMessage }];
|
|
1101
1114
|
promptParams.provider = provider || this._provider;
|
|
1115
|
+
promptParams.configurationId = credentials?.configurationId;
|
|
1116
|
+
promptParams.apiKeys = credentials?.apiKeys;
|
|
1117
|
+
promptParams.CredentialScope = credentials?.CredentialScope;
|
|
1102
1118
|
const runner = new AIPromptRunner();
|
|
1103
1119
|
const result = await runner.ExecutePrompt(promptParams);
|
|
1104
1120
|
if (result && result.success && result.result) {
|