agentic-api 1.0.6 → 2.0.31
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 +336 -76
- package/dist/src/agents/agents.example.d.ts +3 -0
- package/dist/src/agents/agents.example.js +38 -0
- package/dist/src/agents/authentication.js +2 -0
- package/dist/src/agents/prompts.d.ts +2 -2
- package/dist/src/agents/prompts.js +112 -49
- package/dist/src/agents/reducer.core.d.ts +12 -0
- package/dist/src/agents/reducer.core.js +207 -0
- package/dist/src/agents/reducer.d.ts +3 -0
- package/dist/src/agents/reducer.example.d.ts +28 -0
- package/dist/src/agents/reducer.example.js +118 -0
- package/dist/src/agents/reducer.js +19 -0
- package/dist/src/agents/reducer.loaders.d.ts +34 -0
- package/dist/src/agents/reducer.loaders.js +122 -0
- package/dist/src/agents/reducer.process.d.ts +16 -0
- package/dist/src/agents/reducer.process.js +143 -0
- package/dist/src/agents/reducer.tools.d.ts +29 -0
- package/dist/src/agents/reducer.tools.js +157 -0
- package/dist/src/agents/reducer.types.d.ts +50 -0
- package/dist/src/agents/reducer.types.js +5 -0
- package/dist/src/agents/simulator.d.ts +47 -0
- package/dist/src/agents/simulator.executor.d.ts +26 -0
- package/dist/src/agents/simulator.executor.js +132 -0
- package/dist/src/agents/simulator.js +205 -0
- package/dist/src/agents/simulator.prompts.d.ts +16 -0
- package/dist/src/agents/simulator.prompts.js +108 -0
- package/dist/src/agents/simulator.types.d.ts +42 -0
- package/dist/src/agents/simulator.types.js +2 -0
- package/dist/src/agents/simulator.utils.d.ts +20 -0
- package/dist/src/agents/simulator.utils.js +87 -0
- package/dist/src/execute.d.ts +13 -6
- package/dist/src/execute.js +351 -85
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +14 -0
- package/dist/src/princing.openai.d.ts +9 -2
- package/dist/src/princing.openai.js +15 -11
- package/dist/src/prompts.d.ts +3 -2
- package/dist/src/prompts.js +159 -19
- package/dist/src/rag/embeddings.d.ts +103 -0
- package/dist/src/rag/embeddings.js +466 -0
- package/dist/src/rag/index.d.ts +12 -0
- package/dist/src/rag/index.js +40 -0
- package/dist/src/rag/lucene.d.ts +45 -0
- package/dist/src/rag/lucene.js +227 -0
- package/dist/src/rag/parser.d.ts +68 -0
- package/dist/src/rag/parser.js +192 -0
- package/dist/src/rag/tools.d.ts +76 -0
- package/dist/src/rag/tools.js +196 -0
- package/dist/src/rag/types.d.ts +178 -0
- package/dist/src/rag/types.js +21 -0
- package/dist/src/rag/usecase.d.ts +16 -0
- package/dist/src/rag/usecase.js +79 -0
- package/dist/src/rules/errors.d.ts +60 -0
- package/dist/src/rules/errors.js +97 -0
- package/dist/src/rules/git/git.e2e.helper.d.ts +104 -0
- package/dist/src/rules/git/git.e2e.helper.js +488 -0
- package/dist/src/rules/git/git.health.d.ts +66 -0
- package/dist/src/rules/git/git.health.js +354 -0
- package/dist/src/rules/git/git.helper.d.ts +129 -0
- package/dist/src/rules/git/git.helper.js +53 -0
- package/dist/src/rules/git/index.d.ts +6 -0
- package/dist/src/rules/git/index.js +76 -0
- package/dist/src/rules/git/repo.d.ts +128 -0
- package/dist/src/rules/git/repo.js +900 -0
- package/dist/src/rules/git/repo.pr.d.ts +137 -0
- package/dist/src/rules/git/repo.pr.js +589 -0
- package/dist/src/rules/git/repo.tools.d.ts +134 -0
- package/dist/src/rules/git/repo.tools.js +730 -0
- package/dist/src/rules/index.d.ts +8 -0
- package/dist/src/rules/index.js +25 -0
- package/dist/src/rules/messages.d.ts +17 -0
- package/dist/src/rules/messages.js +21 -0
- package/dist/src/rules/types.ctrl.d.ts +28 -0
- package/dist/src/rules/types.ctrl.js +2 -0
- package/dist/src/rules/types.d.ts +510 -0
- package/dist/src/rules/types.helpers.d.ts +132 -0
- package/dist/src/rules/types.helpers.js +2 -0
- package/dist/src/rules/types.js +33 -0
- package/dist/src/rules/user.mapper.d.ts +61 -0
- package/dist/src/rules/user.mapper.js +160 -0
- package/dist/src/rules/utils/slug.d.ts +22 -0
- package/dist/src/rules/utils/slug.js +35 -0
- package/dist/src/rules/utils.matter.d.ts +66 -0
- package/dist/src/rules/utils.matter.js +208 -0
- package/dist/src/rules/utils.slug.d.ts +22 -0
- package/dist/src/rules/utils.slug.js +35 -0
- package/dist/src/scrapper.d.ts +3 -2
- package/dist/src/scrapper.js +33 -37
- package/dist/src/stategraph/index.d.ts +8 -0
- package/dist/src/stategraph/index.js +21 -0
- package/dist/src/stategraph/stategraph.d.ts +91 -0
- package/dist/src/stategraph/stategraph.js +241 -0
- package/dist/src/stategraph/stategraph.storage.d.ts +41 -0
- package/dist/src/stategraph/stategraph.storage.js +166 -0
- package/dist/src/stategraph/types.d.ts +139 -0
- package/dist/src/stategraph/types.js +19 -0
- package/dist/src/types.d.ts +62 -39
- package/dist/src/types.js +53 -89
- package/dist/src/usecase.d.ts +4 -0
- package/dist/src/usecase.js +44 -0
- package/dist/src/utils.d.ts +12 -5
- package/dist/src/utils.js +30 -13
- package/package.json +9 -3
package/dist/src/types.d.ts
CHANGED
|
@@ -47,69 +47,42 @@ export interface AgentModel {
|
|
|
47
47
|
}
|
|
48
48
|
export interface AgentConfig {
|
|
49
49
|
name: string;
|
|
50
|
-
model
|
|
50
|
+
model: AgentModel;
|
|
51
51
|
human?: boolean;
|
|
52
52
|
publicDescription: string;
|
|
53
53
|
instructions: string;
|
|
54
54
|
maxSteps?: number;
|
|
55
55
|
tools: Tool[];
|
|
56
|
-
toolLogic?: Record<string, (args: any, session?: AgenticContext) => Promise<any> | any>;
|
|
56
|
+
toolLogic?: Record<string, (args: any, session?: AgenticContext | any) => Promise<any> | any>;
|
|
57
57
|
downstreamAgents?: AgentConfig[] | {
|
|
58
58
|
name: string;
|
|
59
59
|
publicDescription: string;
|
|
60
60
|
human?: boolean;
|
|
61
61
|
}[];
|
|
62
62
|
ready?: boolean;
|
|
63
|
+
cancelMemory?: boolean;
|
|
63
64
|
}
|
|
64
65
|
export interface UserNano {
|
|
65
66
|
id: string;
|
|
66
67
|
isAnonymous?: boolean;
|
|
67
68
|
role: string;
|
|
68
|
-
|
|
69
|
-
export declare abstract class AgenticMemory {
|
|
70
|
-
abstract get currentAgent(): AgentConfig;
|
|
71
|
-
abstract set currentAgent(agent: AgentConfig);
|
|
72
|
-
abstract agents: AgentConfig[];
|
|
73
|
-
abstract messages: any[];
|
|
74
|
-
abstract usage: Usage;
|
|
75
|
-
abstract state?: string;
|
|
76
|
-
}
|
|
77
|
-
export interface AgenticMemorySession {
|
|
78
|
-
state: string;
|
|
79
|
-
user: UserNano;
|
|
80
|
-
currentAgent: string;
|
|
81
|
-
messages: any[];
|
|
82
|
-
usage: Usage;
|
|
69
|
+
uid?: string;
|
|
83
70
|
}
|
|
84
71
|
export type AgenticCache = {
|
|
85
72
|
get: <T>(key: string) => Promise<T | null>;
|
|
86
73
|
set: <T>(key: string, value: T, ttl?: number) => Promise<T>;
|
|
87
74
|
};
|
|
75
|
+
export interface ExecuteAgentResult {
|
|
76
|
+
usage: Usage;
|
|
77
|
+
content: string;
|
|
78
|
+
messages: any[];
|
|
79
|
+
state: string;
|
|
80
|
+
}
|
|
88
81
|
export interface AgenticContext {
|
|
89
|
-
memory?: AgenticMemorySession;
|
|
90
82
|
user: UserNano;
|
|
83
|
+
session: any;
|
|
91
84
|
[key: string]: any;
|
|
92
|
-
|
|
93
|
-
export declare class AgenticMemoryManager extends AgenticMemory {
|
|
94
|
-
#private;
|
|
95
|
-
constructor(session: {
|
|
96
|
-
memory?: AgenticMemorySession;
|
|
97
|
-
user?: UserNano;
|
|
98
|
-
}, initialAgent: string, agents: AgentConfig[]);
|
|
99
|
-
static createOrLoad(session: {
|
|
100
|
-
memory?: AgenticMemorySession;
|
|
101
|
-
user: UserNano;
|
|
102
|
-
}, agents: any[], initialAgent: string): AgenticMemoryManager;
|
|
103
|
-
get session(): AgenticMemorySession;
|
|
104
|
-
get agents(): AgentConfig[];
|
|
105
|
-
get state(): string;
|
|
106
|
-
set state(state: string);
|
|
107
|
-
get currentAgent(): AgentConfig;
|
|
108
|
-
set currentAgent(agent: AgentConfig);
|
|
109
|
-
get usage(): Usage;
|
|
110
|
-
get messages(): any[];
|
|
111
|
-
set messages(messages: any[]);
|
|
112
|
-
set usage(usage: Usage);
|
|
85
|
+
currentAgent?: AgentConfig;
|
|
113
86
|
}
|
|
114
87
|
export type AllAgentConfigsType = Record<string, AgentConfig[]>;
|
|
115
88
|
export interface Usage {
|
|
@@ -124,6 +97,7 @@ export interface Feedback {
|
|
|
124
97
|
description?: string;
|
|
125
98
|
usage: Usage;
|
|
126
99
|
state: string;
|
|
100
|
+
verbose?: boolean;
|
|
127
101
|
}
|
|
128
102
|
export interface TranscriptItem {
|
|
129
103
|
id: string;
|
|
@@ -134,3 +108,52 @@ export interface TranscriptItem {
|
|
|
134
108
|
timestamp: string;
|
|
135
109
|
status: "IN_PROGRESS" | "DONE";
|
|
136
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Represents a single action taken during an agent execution.
|
|
113
|
+
*
|
|
114
|
+
* - For a transfer action, use `action: 'transfert'` and set `content` to the destination agent name.
|
|
115
|
+
* - For a tool call, use `action: <function name>` and set `content` to the tool output (stringified if needed).
|
|
116
|
+
* - `feedback` can include justification, notes, or any short status associated with the action.
|
|
117
|
+
*/
|
|
118
|
+
export interface ExecutionAction {
|
|
119
|
+
action: string;
|
|
120
|
+
content: string;
|
|
121
|
+
feedback?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Aggregated result of an agent set execution.
|
|
125
|
+
*
|
|
126
|
+
* - `runId`: Correlation identifier for the execution run.
|
|
127
|
+
* - `actions`: Ordered list of actions (tools/transfers) performed.
|
|
128
|
+
* - `lastMessage`: The final assistant message content after execution.
|
|
129
|
+
* - `usage`: Token usage/cost snapshot for the whole execution.
|
|
130
|
+
* - `error`: Optional error message if something went wrong (non-fatal).
|
|
131
|
+
* - `moreThinkin`: When true, caller should continue the execution loop (retro-compat flag).
|
|
132
|
+
*/
|
|
133
|
+
export interface ExecutionResult {
|
|
134
|
+
runId: string;
|
|
135
|
+
/** Initial user query used to start the execution */
|
|
136
|
+
startQuery: string;
|
|
137
|
+
actions: ExecutionAction[];
|
|
138
|
+
lastMessage: string;
|
|
139
|
+
usage: Usage;
|
|
140
|
+
error?: string;
|
|
141
|
+
moreThinkin: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Human-readable summary formatter. Optional to preserve backward compatibility.
|
|
144
|
+
*/
|
|
145
|
+
toString?: () => string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Merge two partial execution results into a single result.
|
|
149
|
+
*
|
|
150
|
+
* Merge strategy:
|
|
151
|
+
* - `runId`: preserved from the primary accumulator `a`.
|
|
152
|
+
* - `actions`: appended in order (a.actions then b.actions).
|
|
153
|
+
* - `lastMessage`: preserved from `a` unless set elsewhere later in the workflow.
|
|
154
|
+
* - `usage`: summed field-by-field to accumulate totals across steps.
|
|
155
|
+
* - `error`: keep the latest non-undefined error (prefer `b`).
|
|
156
|
+
* - `moreThinkin`: true if either `a` or `b` requests continued thinking.
|
|
157
|
+
*/
|
|
158
|
+
export declare function enrichExecutionResult(result: ExecutionResult): ExecutionResult;
|
|
159
|
+
export declare function executionResultMerge(a: ExecutionResult, b: ExecutionResult): ExecutionResult;
|
package/dist/src/types.js
CHANGED
|
@@ -1,93 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _AgenticMemoryManager_memory, _AgenticMemoryManager_initialAgent, _AgenticMemoryManager_agents;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
3
|
+
exports.enrichExecutionResult = enrichExecutionResult;
|
|
4
|
+
exports.executionResultMerge = executionResultMerge;
|
|
5
|
+
/**
|
|
6
|
+
* Merge two partial execution results into a single result.
|
|
7
|
+
*
|
|
8
|
+
* Merge strategy:
|
|
9
|
+
* - `runId`: preserved from the primary accumulator `a`.
|
|
10
|
+
* - `actions`: appended in order (a.actions then b.actions).
|
|
11
|
+
* - `lastMessage`: preserved from `a` unless set elsewhere later in the workflow.
|
|
12
|
+
* - `usage`: summed field-by-field to accumulate totals across steps.
|
|
13
|
+
* - `error`: keep the latest non-undefined error (prefer `b`).
|
|
14
|
+
* - `moreThinkin`: true if either `a` or `b` requests continued thinking.
|
|
15
|
+
*/
|
|
16
|
+
function enrichExecutionResult(result) {
|
|
17
|
+
const formatAction = (action, index) => {
|
|
18
|
+
const content = (action.content ?? '').toString();
|
|
19
|
+
const trimmed = content.length > 160 ? content.slice(0, 160) + '…' : content;
|
|
20
|
+
const feedback = action.feedback ? ` | feedback: ${action.feedback}` : '';
|
|
21
|
+
return `${index + 1}. ${action.action}: ${trimmed}${feedback}`;
|
|
22
|
+
};
|
|
23
|
+
result.toString = () => {
|
|
24
|
+
const lines = [];
|
|
25
|
+
lines.push(`runId: ${result.runId}`);
|
|
26
|
+
lines.push(`startQuery: ${result.startQuery?.slice(0, 200)}`);
|
|
27
|
+
lines.push(`lastMessage: ${result.lastMessage?.slice(0, 200)}`);
|
|
28
|
+
lines.push(`usage: prompt=${result.usage?.prompt || 0}, completion=${result.usage?.completion || 0}, total=${result.usage?.total || 0}, cost=${result.usage?.cost || 0}`);
|
|
29
|
+
if (result.error) {
|
|
30
|
+
lines.push(`error: ${result.error}`);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
get state() {
|
|
67
|
-
return __classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").state;
|
|
68
|
-
}
|
|
69
|
-
set state(state) {
|
|
70
|
-
__classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").state = state;
|
|
71
|
-
}
|
|
72
|
-
get currentAgent() {
|
|
73
|
-
const name = __classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").currentAgent || __classPrivateFieldGet(this, _AgenticMemoryManager_initialAgent, "f");
|
|
74
|
-
return __classPrivateFieldGet(this, _AgenticMemoryManager_agents, "f").find((a) => a.name == name);
|
|
75
|
-
}
|
|
76
|
-
set currentAgent(agent) {
|
|
77
|
-
__classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").currentAgent = agent.name;
|
|
78
|
-
}
|
|
79
|
-
get usage() {
|
|
80
|
-
return __classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").usage;
|
|
81
|
-
}
|
|
82
|
-
get messages() {
|
|
83
|
-
return __classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").messages;
|
|
84
|
-
}
|
|
85
|
-
set messages(messages) {
|
|
86
|
-
__classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").messages = messages;
|
|
87
|
-
}
|
|
88
|
-
set usage(usage) {
|
|
89
|
-
__classPrivateFieldGet(this, _AgenticMemoryManager_memory, "f").usage = usage;
|
|
90
|
-
}
|
|
32
|
+
lines.push(`moreThinkin: ${Boolean(result.moreThinkin)}`);
|
|
33
|
+
const actions = result.actions || [];
|
|
34
|
+
lines.push(`actions (${actions.length}):`);
|
|
35
|
+
actions.forEach((a, i) => lines.push(` - ${formatAction(a, i)}`));
|
|
36
|
+
return lines.join('\n');
|
|
37
|
+
};
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function executionResultMerge(a, b) {
|
|
41
|
+
// Prefer b.runId if a.runId is empty (initial placeholder result)
|
|
42
|
+
const merged = {
|
|
43
|
+
runId: a.runId && a.runId.length > 0 ? a.runId : b.runId,
|
|
44
|
+
startQuery: a.startQuery || b.startQuery || '',
|
|
45
|
+
actions: [...(a.actions || []), ...(b.actions || [])],
|
|
46
|
+
lastMessage: a.lastMessage || '',
|
|
47
|
+
usage: {
|
|
48
|
+
prompt: (a.usage?.prompt || 0) + (b.usage?.prompt || 0),
|
|
49
|
+
completion: (a.usage?.completion || 0) + (b.usage?.completion || 0),
|
|
50
|
+
total: (a.usage?.total || 0) + (b.usage?.total || 0),
|
|
51
|
+
cost: (a.usage?.cost || 0) + (b.usage?.cost || 0),
|
|
52
|
+
},
|
|
53
|
+
error: b.error ?? a.error,
|
|
54
|
+
moreThinkin: Boolean(a.moreThinkin || b.moreThinkin),
|
|
55
|
+
};
|
|
56
|
+
return enrichExecutionResult(merged);
|
|
91
57
|
}
|
|
92
|
-
exports.AgenticMemoryManager = AgenticMemoryManager;
|
|
93
|
-
_AgenticMemoryManager_memory = new WeakMap(), _AgenticMemoryManager_initialAgent = new WeakMap(), _AgenticMemoryManager_agents = new WeakMap();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callGPTToExtractUserQueries = callGPTToExtractUserQueries;
|
|
4
|
+
const princing_openai_1 = require("./princing.openai");
|
|
5
|
+
const prompts_1 = require("./prompts");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
async function callGPTToExtractUserQueries(inputsection, file) {
|
|
8
|
+
const openai = (0, utils_1.openaiInstance)();
|
|
9
|
+
// Format: YYYY-MM-DD
|
|
10
|
+
const today = new Date().toISOString().substring(0, 10);
|
|
11
|
+
// Créer le prompt pour décrire la tâche au LLM
|
|
12
|
+
const messages = [
|
|
13
|
+
{
|
|
14
|
+
role: "system",
|
|
15
|
+
content: (0, prompts_1.usecaseExtractionPrompt)(file)
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
role: "user",
|
|
19
|
+
content: `Nous sommes le ${today}.\nVoici le document à analyser :\n${inputsection}`
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
// WARNING: o3-mini is buggy with "Marche à suivre nouveau bail.pdf"
|
|
23
|
+
//const model = "o3-mini";// "gpt-4o-mini";
|
|
24
|
+
const model = "gpt-5-mini";
|
|
25
|
+
const response = await openai.chat.completions.create({
|
|
26
|
+
model: model,
|
|
27
|
+
reasoning_effort: "low",
|
|
28
|
+
verbosity: "low",
|
|
29
|
+
messages,
|
|
30
|
+
//reasoning_effort:"low",
|
|
31
|
+
response_format: { type: "json_object" }
|
|
32
|
+
});
|
|
33
|
+
// response_format: { type: "json_object" }
|
|
34
|
+
const cost = (0, princing_openai_1.calculateCost)(model, response.usage);
|
|
35
|
+
// Récupérer la réponse markdown
|
|
36
|
+
const json = response.choices[0].message.content;
|
|
37
|
+
console.log(`Markdown 💰 cost: ${cost}`);
|
|
38
|
+
//
|
|
39
|
+
// add a regex to extract the markdown content between <thinking></thinking> tags
|
|
40
|
+
// const thinking = markdown.match(/<thinking>[\s\S]*?<\/thinking>/)?.[0];
|
|
41
|
+
// const markdownWithoutThinking = markdown.replace(/<thinking>[\s\S]*?<\/thinking>/g, '');
|
|
42
|
+
// return markdownWithoutThinking;
|
|
43
|
+
return { json, cost };
|
|
44
|
+
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { ParsedFunctionToolCall } from "openai/resources/beta/chat/completions";
|
|
2
|
-
import { AgentConfig, AgenticContext
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { AgentConfig, AgenticContext } from "./types";
|
|
3
|
+
export declare const openaiInstance: (openai?: any) => any;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string to a URL-friendly slug
|
|
6
|
+
* @param text The text to convert to a slug
|
|
7
|
+
* @param whitespace The character to use for whitespace replacement (default: '-')
|
|
8
|
+
* @returns A URL-friendly slug
|
|
9
|
+
*/
|
|
10
|
+
export declare const toSlug: (text: string, whitespace?: string) => string;
|
|
6
11
|
/**
|
|
7
12
|
* This defines and adds "transferAgents" tool dynamically based on the specified downstreamAgents on each agent.
|
|
8
13
|
*/
|
|
9
14
|
export declare function injectTransferTools(agentDefs: AgentConfig[]): AgentConfig[];
|
|
10
|
-
export declare function handleTransferCall(
|
|
15
|
+
export declare function handleTransferCall(discussion: any, currentAgentRef: {
|
|
16
|
+
name: string;
|
|
17
|
+
}, agents: AgentConfig[], functionCallParams: ParsedFunctionToolCall, context: AgenticContext): Promise<any>;
|
|
11
18
|
/**
|
|
12
19
|
* Calls the system review agent to analyze a prompt
|
|
13
20
|
*
|
package/dist/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toSlug = exports.openaiInstance = void 0;
|
|
4
4
|
exports.injectTransferTools = injectTransferTools;
|
|
5
5
|
exports.handleTransferCall = handleTransferCall;
|
|
6
6
|
exports.callForSystemReview = callForSystemReview;
|
|
@@ -18,10 +18,28 @@ const openaiInstance = function (openai) {
|
|
|
18
18
|
return _openaiInstance;
|
|
19
19
|
};
|
|
20
20
|
exports.openaiInstance = openaiInstance;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Converts a string to a URL-friendly slug
|
|
23
|
+
* @param text The text to convert to a slug
|
|
24
|
+
* @param whitespace The character to use for whitespace replacement (default: '-')
|
|
25
|
+
* @returns A URL-friendly slug
|
|
26
|
+
*/
|
|
27
|
+
const toSlug = (text, whitespace = '-') => {
|
|
28
|
+
// Trim and lowercase
|
|
29
|
+
let str = text.trim().toLowerCase();
|
|
30
|
+
// Remove accents and special characters
|
|
31
|
+
const from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
32
|
+
const to = "aaaaeeeeiiiioooouuuunc------";
|
|
33
|
+
for (let i = 0, l = from.length; i < l; i++) {
|
|
34
|
+
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
35
|
+
}
|
|
36
|
+
return str
|
|
37
|
+
.replace(/[^a-z0-9 -]/g, '') // Remove invalid chars
|
|
38
|
+
.replace(/\s+/g, whitespace) // Collapse whitespace and replace by whitespace char
|
|
39
|
+
.replace(/-+/g, whitespace === '-' ? '-' : whitespace) // Collapse dashes, but respect whitespace char
|
|
40
|
+
.replace(new RegExp(`^\\${whitespace}+|\\${whitespace}+$`, 'g'), ''); // Trim whitespace char (escape for regex)
|
|
23
41
|
};
|
|
24
|
-
exports.
|
|
42
|
+
exports.toSlug = toSlug;
|
|
25
43
|
/**
|
|
26
44
|
* This defines and adds "transferAgents" tool dynamically based on the specified downstreamAgents on each agent.
|
|
27
45
|
*/
|
|
@@ -148,9 +166,8 @@ ${availableAgentsList}
|
|
|
148
166
|
//
|
|
149
167
|
// Fonction pour gérer un appel de fonction retourné par OpenAI
|
|
150
168
|
// le contexte est un objet qui contient des informations supplémentaires de session
|
|
151
|
-
async function handleTransferCall(
|
|
152
|
-
const
|
|
153
|
-
const currentAgentName = memory.currentAgent?.name;
|
|
169
|
+
async function handleTransferCall(discussion, currentAgentRef, agents, functionCallParams, context) {
|
|
170
|
+
const currentAgentName = currentAgentRef.name;
|
|
154
171
|
const args = JSON.parse(functionCallParams?.function?.arguments || '{}');
|
|
155
172
|
// console.log("↩️ Appel de fonction à gérer :",currentAgent?.name,'->', functionCallParams.function.name,'::',args);
|
|
156
173
|
if (functionCallParams.function.name === "transferAgents") {
|
|
@@ -167,7 +184,7 @@ async function handleTransferCall(memory, functionCallParams, session) {
|
|
|
167
184
|
// For debug, we don't want to transfer to the same agent
|
|
168
185
|
if (currentAgentName === destinationAgentName) {
|
|
169
186
|
console.log("❌ Le transfert sur moi-même n'est pas nécessaire", destinationAgentName, args);
|
|
170
|
-
|
|
187
|
+
discussion.messages.slice(1).forEach((m) => {
|
|
171
188
|
process.stdout.write(`-- DBG ---> 🤖 ${m.role}: ${m.content}\n`);
|
|
172
189
|
});
|
|
173
190
|
}
|
|
@@ -176,7 +193,7 @@ async function handleTransferCall(memory, functionCallParams, session) {
|
|
|
176
193
|
const destinationAgent = agents.find((agent) => agent.name === destinationAgentName);
|
|
177
194
|
if (destinationAgent) {
|
|
178
195
|
//console.log(`🤖 Agent "${destinationAgent.name}" en préparation`);
|
|
179
|
-
|
|
196
|
+
currentAgentRef.name = destinationAgent.name;
|
|
180
197
|
return {
|
|
181
198
|
feedback: args.rationale_for_transfer,
|
|
182
199
|
destination_agent: destinationAgentName,
|
|
@@ -196,7 +213,7 @@ async function handleTransferCall(memory, functionCallParams, session) {
|
|
|
196
213
|
}
|
|
197
214
|
if (functionCallParams.function.name === "thinking") {
|
|
198
215
|
const { justification, thought, step } = args;
|
|
199
|
-
console.log('🤖',
|
|
216
|
+
console.log('🤖', currentAgentRef.name, '->', functionCallParams.function.name, '::', thought, '(step', step, ')');
|
|
200
217
|
return {
|
|
201
218
|
feedback: justification,
|
|
202
219
|
content: `Pour l'étape ${step}, j'ai pensé à "${thought}"`,
|
|
@@ -206,10 +223,10 @@ async function handleTransferCall(memory, functionCallParams, session) {
|
|
|
206
223
|
}
|
|
207
224
|
//
|
|
208
225
|
// looking on agents tool logic
|
|
209
|
-
|
|
226
|
+
// ⚠️ ALWAYS inject context in tool logic, ALWAYS!
|
|
227
|
+
const agent = agents.find(a => a.name === currentAgentRef.name);
|
|
210
228
|
if (agent?.toolLogic && agent.toolLogic[functionCallParams.function.name]) {
|
|
211
|
-
const { content, usage } = await agent.toolLogic[functionCallParams.function.name](args,
|
|
212
|
-
console.log('🤖', agent.name, '->', functionCallParams.function.name, '::usage', usage);
|
|
229
|
+
const { content, usage } = await agent.toolLogic[functionCallParams.function.name](args, context);
|
|
213
230
|
return {
|
|
214
231
|
content,
|
|
215
232
|
name: functionCallParams.function.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.31",
|
|
4
4
|
"description": "API pour l'orchestration d'agents intelligents avec séquences et escalades automatiques",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
"dist/src"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
+
"prebuild": "npm version patch --no-git-tag-version",
|
|
11
12
|
"build": "tsc",
|
|
12
13
|
"test": "jest",
|
|
13
14
|
"lint": "eslint 'src/**/*.ts'",
|
|
14
15
|
"prepublishOnly": "npm run build",
|
|
15
|
-
"extract:pdf": "texttopdf "
|
|
16
|
+
"extract:pdf": "texttopdf ",
|
|
17
|
+
"deploy": "npm run prebuild && npm run build"
|
|
16
18
|
},
|
|
17
19
|
"optionalDependencies": {
|
|
18
20
|
"python3": ">=3.5"
|
|
@@ -22,7 +24,11 @@
|
|
|
22
24
|
"dotenv": "^16.4.7",
|
|
23
25
|
"hnswlib-node": "^3.0.0",
|
|
24
26
|
"jsdom": "^26.0.0",
|
|
25
|
-
"
|
|
27
|
+
"minisearch": "^7.1.0",
|
|
28
|
+
"natural": "^8.1.0",
|
|
29
|
+
"openai": "^4.102.0",
|
|
30
|
+
"simple-git": "^3.27.0",
|
|
31
|
+
"stopwords-fr": "^0.3.0"
|
|
26
32
|
},
|
|
27
33
|
"devDependencies": {
|
|
28
34
|
"@types/jest": "^29.5.14",
|