agentic-api 2.0.646 → 2.0.885
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/dist/src/agents/prompts.d.ts +2 -3
- package/dist/src/agents/prompts.js +21 -118
- package/dist/src/agents/reducer.loaders.d.ts +103 -1
- package/dist/src/agents/reducer.loaders.js +164 -2
- package/dist/src/agents/reducer.types.d.ts +34 -3
- package/dist/src/agents/simulator.d.ts +32 -2
- package/dist/src/agents/simulator.executor.d.ts +15 -5
- package/dist/src/agents/simulator.executor.js +134 -67
- package/dist/src/agents/simulator.js +251 -8
- package/dist/src/agents/simulator.prompts.d.ts +55 -10
- package/dist/src/agents/simulator.prompts.js +305 -61
- package/dist/src/agents/simulator.types.d.ts +62 -1
- package/dist/src/agents/simulator.types.js +5 -0
- package/dist/src/agents/subagent.d.ts +128 -0
- package/dist/src/agents/subagent.js +231 -0
- package/dist/src/agents/worker.executor.d.ts +48 -0
- package/dist/src/agents/worker.executor.js +152 -0
- package/dist/src/execute/helpers.d.ts +3 -0
- package/dist/src/execute/helpers.js +222 -16
- package/dist/src/execute/responses.js +81 -55
- package/dist/src/execute/shared.d.ts +5 -0
- package/dist/src/execute/shared.js +27 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -1
- package/dist/src/llm/openai.js +8 -1
- package/dist/src/llm/pricing.js +2 -0
- package/dist/src/llm/xai.js +11 -6
- package/dist/src/prompts.d.ts +14 -0
- package/dist/src/prompts.js +41 -1
- package/dist/src/rag/rag.manager.d.ts +18 -3
- package/dist/src/rag/rag.manager.js +114 -12
- package/dist/src/rag/types.d.ts +3 -1
- package/dist/src/rules/git/git.e2e.helper.js +51 -4
- package/dist/src/rules/git/git.health.js +89 -56
- package/dist/src/rules/git/index.d.ts +2 -2
- package/dist/src/rules/git/index.js +22 -5
- package/dist/src/rules/git/repo.d.ts +64 -6
- package/dist/src/rules/git/repo.js +572 -141
- package/dist/src/rules/git/repo.pr.d.ts +11 -18
- package/dist/src/rules/git/repo.pr.js +82 -94
- package/dist/src/rules/git/repo.tools.d.ts +5 -0
- package/dist/src/rules/git/repo.tools.js +6 -1
- package/dist/src/rules/types.d.ts +0 -2
- package/dist/src/rules/utils.matter.js +1 -5
- package/dist/src/scrapper.d.ts +138 -25
- package/dist/src/scrapper.js +538 -160
- package/dist/src/stategraph/stategraph.d.ts +6 -2
- package/dist/src/stategraph/stategraph.js +21 -6
- package/dist/src/stategraph/types.d.ts +14 -6
- package/dist/src/types.d.ts +22 -0
- package/dist/src/utils.d.ts +24 -0
- package/dist/src/utils.js +84 -86
- package/package.json +3 -2
- package/dist/src/agents/semantic.d.ts +0 -4
- package/dist/src/agents/semantic.js +0 -19
- package/dist/src/execute/legacy.d.ts +0 -46
- package/dist/src/execute/legacy.js +0 -460
- package/dist/src/pricing.llm.d.ts +0 -5
- package/dist/src/pricing.llm.js +0 -14
|
@@ -38,7 +38,7 @@ export declare class AgentStateGraph implements IAgentStateGraph {
|
|
|
38
38
|
set(agentName: string, content: string): void;
|
|
39
39
|
/**
|
|
40
40
|
* Ajoute une étape au CONTEXT TRAIL et met à jour le message system
|
|
41
|
-
* Injecte automatiquement le trail dans le system message via
|
|
41
|
+
* Injecte automatiquement le trail dans le system message via updateSystemContextTrail()
|
|
42
42
|
*
|
|
43
43
|
* Utilisée par:
|
|
44
44
|
* - readCompletionsStream (responses.ts) : après chaque tool call exécuté
|
|
@@ -64,7 +64,7 @@ export declare class AgentStateGraph implements IAgentStateGraph {
|
|
|
64
64
|
* Met à jour le message system avec le nouveau trail via regexp
|
|
65
65
|
* @param agentName Nom de l'agent
|
|
66
66
|
*/
|
|
67
|
-
private
|
|
67
|
+
private updateSystemContextTrail;
|
|
68
68
|
/**
|
|
69
69
|
* Additionne l'usage des tokens pour un agent
|
|
70
70
|
* @param agentName Nom de l'agent
|
|
@@ -95,6 +95,10 @@ export declare class AgentStateGraph implements IAgentStateGraph {
|
|
|
95
95
|
* @returns Discussion trouvée ou undefined
|
|
96
96
|
*/
|
|
97
97
|
findDiscussionById(discussionId: string): AgentDiscussion | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Supprime les sessions enfants sub-agent dont l'id commence par `{parentId}_subAgent`
|
|
100
|
+
*/
|
|
101
|
+
private deleteChildSubAgentDiscussions;
|
|
98
102
|
/**
|
|
99
103
|
* Supprime une discussion
|
|
100
104
|
* @param discussionId ID de la discussion à supprimer
|
|
@@ -86,12 +86,12 @@ class AgentStateGraph {
|
|
|
86
86
|
discussion.messages[0].agent = systemMessage.agent;
|
|
87
87
|
discussion.messages[0].timestamp = new Date();
|
|
88
88
|
}
|
|
89
|
-
this.
|
|
89
|
+
this.updateSystemContextTrail(discussion);
|
|
90
90
|
discussion.updatedAt = new Date();
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Ajoute une étape au CONTEXT TRAIL et met à jour le message system
|
|
94
|
-
* Injecte automatiquement le trail dans le system message via
|
|
94
|
+
* Injecte automatiquement le trail dans le system message via updateSystemContextTrail()
|
|
95
95
|
*
|
|
96
96
|
* Utilisée par:
|
|
97
97
|
* - readCompletionsStream (responses.ts) : après chaque tool call exécuté
|
|
@@ -105,7 +105,7 @@ class AgentStateGraph {
|
|
|
105
105
|
if (!discussion)
|
|
106
106
|
return;
|
|
107
107
|
discussion.trailSteps.push(step);
|
|
108
|
-
this.
|
|
108
|
+
this.updateSystemContextTrail(discussion);
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Retourne tous les steps du CONTEXT TRAIL pour une discussion
|
|
@@ -127,15 +127,14 @@ class AgentStateGraph {
|
|
|
127
127
|
return '(No actions yet)';
|
|
128
128
|
}
|
|
129
129
|
return discussion.trailSteps.map(s => {
|
|
130
|
-
|
|
131
|
-
return `- ${s.tool}: ${s.context} "${s.reason}"${idPart}`;
|
|
130
|
+
return `- ${s.tool}: ${s.reason}`;
|
|
132
131
|
}).join('\n');
|
|
133
132
|
}
|
|
134
133
|
/**
|
|
135
134
|
* Met à jour le message system avec le nouveau trail via regexp
|
|
136
135
|
* @param agentName Nom de l'agent
|
|
137
136
|
*/
|
|
138
|
-
|
|
137
|
+
updateSystemContextTrail(discussion) {
|
|
139
138
|
const systemMessage = discussion.messages.find((m) => m.role === 'system');
|
|
140
139
|
if (!systemMessage)
|
|
141
140
|
return;
|
|
@@ -238,12 +237,27 @@ class AgentStateGraph {
|
|
|
238
237
|
findDiscussionById(discussionId) {
|
|
239
238
|
return this.discussions.find(d => d.id === discussionId);
|
|
240
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Supprime les sessions enfants sub-agent dont l'id commence par `{parentId}_subAgent`
|
|
242
|
+
*/
|
|
243
|
+
deleteChildSubAgentDiscussions(parentId) {
|
|
244
|
+
if (!parentId)
|
|
245
|
+
return;
|
|
246
|
+
const prefix = `${parentId}_subAgent`;
|
|
247
|
+
const children = this.discussions.filter(d => d.id.startsWith(prefix));
|
|
248
|
+
for (const child of children) {
|
|
249
|
+
this.deleteDiscussion(child.id);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
241
252
|
/**
|
|
242
253
|
* Supprime une discussion
|
|
243
254
|
* @param discussionId ID de la discussion à supprimer
|
|
244
255
|
* @returns true si supprimée, false si non trouvée
|
|
245
256
|
*/
|
|
246
257
|
deleteDiscussion(discussionId) {
|
|
258
|
+
if (!discussionId)
|
|
259
|
+
return false;
|
|
260
|
+
this.deleteChildSubAgentDiscussions(discussionId);
|
|
247
261
|
const index = this.discussions.findIndex(d => d.id === discussionId);
|
|
248
262
|
if (index >= 0) {
|
|
249
263
|
this.discussions.splice(index, 1);
|
|
@@ -257,6 +271,7 @@ class AgentStateGraph {
|
|
|
257
271
|
*/
|
|
258
272
|
clearDiscussion(agentName) {
|
|
259
273
|
const discussion = this.createOrRestore(agentName);
|
|
274
|
+
this.deleteChildSubAgentDiscussions(discussion.id);
|
|
260
275
|
// Garder uniquement le premier message s'il est de type system
|
|
261
276
|
if (discussion.messages.length > 0 && discussion.messages[0].role === 'system') {
|
|
262
277
|
discussion.messages = [discussion.messages[0]];
|
|
@@ -41,14 +41,10 @@ export interface TokenUsage {
|
|
|
41
41
|
* Utilisé pour maintenir une mémoire de travail des actions effectuées par les outils
|
|
42
42
|
*/
|
|
43
43
|
export interface StepTrail {
|
|
44
|
-
/** Nom de l'outil (ex: "
|
|
44
|
+
/** Nom de l'outil (ex: "resolveLocataire", "lookupKnowledge") */
|
|
45
45
|
tool: string;
|
|
46
|
-
/**
|
|
47
|
-
context: string;
|
|
48
|
-
/** Justification/raison de l'action */
|
|
46
|
+
/** Raison de l'appel (context du résultat ou justification de l'appel) */
|
|
49
47
|
reason: string;
|
|
50
|
-
/** ID optionnel pour détection de boucles */
|
|
51
|
-
id?: string;
|
|
52
48
|
}
|
|
53
49
|
/**
|
|
54
50
|
* Discussion d'agent - thread de messages pour un agent spécifique
|
|
@@ -73,6 +69,18 @@ export interface AgentDiscussion {
|
|
|
73
69
|
updatedAt: Date;
|
|
74
70
|
/** Agent qui a initié cette discussion (requis) */
|
|
75
71
|
startAgent: string;
|
|
72
|
+
/**
|
|
73
|
+
* Responses API: ID de la dernière réponse complète du tour précédent.
|
|
74
|
+
* Permet d'utiliser previous_response_id pour éviter de re-envoyer l'historique complet.
|
|
75
|
+
* Mis à jour à la FIN de chaque tour (readCompletionsStream, base cases uniquement).
|
|
76
|
+
*/
|
|
77
|
+
lastResponseId?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Nombre de messages dans discussion.messages à la fin du tour précédent.
|
|
80
|
+
* Permet de calculer le delta : messages.slice(lastResponseMsgCount) = nouveaux messages.
|
|
81
|
+
* Mis à jour en même temps que lastResponseId.
|
|
82
|
+
*/
|
|
83
|
+
lastResponseMsgCount?: number;
|
|
76
84
|
}
|
|
77
85
|
/**
|
|
78
86
|
* Interface principale du StateGraph pour gérer les discussions par agent
|
package/dist/src/types.d.ts
CHANGED
|
@@ -42,8 +42,25 @@ export type ToolContractOutput<T> = {
|
|
|
42
42
|
can_retry: boolean;
|
|
43
43
|
error_code?: string;
|
|
44
44
|
transfer_message?: string;
|
|
45
|
+
pipeline?: string[];
|
|
46
|
+
query_id?: string;
|
|
45
47
|
};
|
|
46
48
|
};
|
|
49
|
+
export interface SubAgentResult {
|
|
50
|
+
/** Dernier message produit par le sub-agent (réponse finale) */
|
|
51
|
+
message: string;
|
|
52
|
+
/** Nom original du sub-agent appelé (ex: "PR-knowledge") */
|
|
53
|
+
agentName: string;
|
|
54
|
+
/** Clé de session scoped utilisée ({parentId}_{toolName}) */
|
|
55
|
+
sessionKey: string;
|
|
56
|
+
/** Usage tokens consommés par le sub-agent */
|
|
57
|
+
usage: {
|
|
58
|
+
prompt: number;
|
|
59
|
+
completion: number;
|
|
60
|
+
total: number;
|
|
61
|
+
cost: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
47
64
|
export interface AgentModelMapping {
|
|
48
65
|
[key: string]: string;
|
|
49
66
|
}
|
|
@@ -94,6 +111,11 @@ export interface AgentConfig {
|
|
|
94
111
|
publicDescription: string;
|
|
95
112
|
human?: boolean;
|
|
96
113
|
}[];
|
|
114
|
+
subAgents?: AgentConfig[] | {
|
|
115
|
+
name: string;
|
|
116
|
+
publicDescription: string;
|
|
117
|
+
}[];
|
|
118
|
+
outputSchema?: any;
|
|
97
119
|
ready?: boolean;
|
|
98
120
|
cancelMemory?: boolean;
|
|
99
121
|
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ import { AgentConfig, AgenticContext } from "./types";
|
|
|
7
7
|
* @returns A URL-friendly slug
|
|
8
8
|
*/
|
|
9
9
|
export declare const toSlug: (text: string, whitespace?: string) => string;
|
|
10
|
+
import { subAgentInjectTools, subAgentExtractCapabilities, subAgentComposeMission } from './agents/subagent';
|
|
11
|
+
/** @deprecated Use subAgentInjectTools from 'agents/subagent' */
|
|
12
|
+
export declare const injectSubAgentTools: typeof subAgentInjectTools;
|
|
13
|
+
/** @deprecated Use subAgentExtractCapabilities from 'agents/subagent' */
|
|
14
|
+
export declare const extractAgentCapabilities: typeof subAgentExtractCapabilities;
|
|
15
|
+
export { subAgentComposeMission };
|
|
10
16
|
/**
|
|
11
17
|
* Contrat standard JSON pour le transfert (handoff) entre agents.
|
|
12
18
|
*
|
|
@@ -35,6 +41,24 @@ export declare const toSlug: (text: string, whitespace?: string) => string;
|
|
|
35
41
|
* https://github.com/openai/openai-realtime-agents/blob/without-agents-sdk/src/app/agentConfigs/utils.ts
|
|
36
42
|
*/
|
|
37
43
|
export declare function injectTransferTools(agentDefs: AgentConfig[]): AgentConfig[];
|
|
44
|
+
/**
|
|
45
|
+
* Gère le transfert d'un agent vers un autre (handoff).
|
|
46
|
+
* Responsabilité unique : `transferAgents` uniquement.
|
|
47
|
+
*
|
|
48
|
+
* TODO [Phase 2 - openai-agents-js]:
|
|
49
|
+
* Sera remplacé par le handoff natif openai-agents-js.
|
|
50
|
+
* Les concepts downstreamAgents/confidence seront mappés vers swarm.run / handoff strategies.
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
38
53
|
export declare function handleTransferCall(discussion: any, currentAgentRef: {
|
|
39
54
|
name: string;
|
|
40
55
|
}, agents: AgentConfig[], functionCallParams: ParsedFunctionToolCall, context: AgenticContext): Promise<any>;
|
|
56
|
+
/**
|
|
57
|
+
* Gère les tool calls métier (toolLogic) et le thinking interne.
|
|
58
|
+
* Extrait de handleTransferCall — responsabilité : tout sauf transferAgents et subAgent*.
|
|
59
|
+
*
|
|
60
|
+
* ⚠️ ALWAYS inject context in tool logic, ALWAYS!
|
|
61
|
+
*/
|
|
62
|
+
export declare function handleToolLogicCall(currentAgentRef: {
|
|
63
|
+
name: string;
|
|
64
|
+
}, agents: AgentConfig[], functionCallParams: ParsedFunctionToolCall, context: AgenticContext): Promise<any>;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toSlug = void 0;
|
|
3
|
+
exports.subAgentComposeMission = exports.extractAgentCapabilities = exports.injectSubAgentTools = exports.toSlug = void 0;
|
|
4
4
|
exports.injectTransferTools = injectTransferTools;
|
|
5
5
|
exports.handleTransferCall = handleTransferCall;
|
|
6
|
+
exports.handleToolLogicCall = handleToolLogicCall;
|
|
6
7
|
const prompts_1 = require("./prompts");
|
|
7
8
|
/**
|
|
8
9
|
* Converts a string to a URL-friendly slug
|
|
@@ -26,6 +27,16 @@ const toSlug = (text, whitespace = '-') => {
|
|
|
26
27
|
.replace(new RegExp(`^\\${whitespace}+|\\${whitespace}+$`, 'g'), ''); // Trim whitespace char (escape for regex)
|
|
27
28
|
};
|
|
28
29
|
exports.toSlug = toSlug;
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// SubAgent functions — re-exported from agents/subagent.ts
|
|
32
|
+
// Aliases preserve backward compatibility with existing imports.
|
|
33
|
+
// ============================================================================
|
|
34
|
+
const subagent_1 = require("./agents/subagent");
|
|
35
|
+
Object.defineProperty(exports, "subAgentComposeMission", { enumerable: true, get: function () { return subagent_1.subAgentComposeMission; } });
|
|
36
|
+
/** @deprecated Use subAgentInjectTools from 'agents/subagent' */
|
|
37
|
+
exports.injectSubAgentTools = subagent_1.subAgentInjectTools;
|
|
38
|
+
/** @deprecated Use subAgentExtractCapabilities from 'agents/subagent' */
|
|
39
|
+
exports.extractAgentCapabilities = subagent_1.subAgentExtractCapabilities;
|
|
29
40
|
/**
|
|
30
41
|
* Contrat standard JSON pour le transfert (handoff) entre agents.
|
|
31
42
|
*
|
|
@@ -124,113 +135,100 @@ ${availableAgentsList}
|
|
|
124
135
|
});
|
|
125
136
|
return agentDefs;
|
|
126
137
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// vers les primitives de l'Agent SDK (swarm.run, handoff strategies).
|
|
137
|
-
// Le stateGraph restera compatible car il utilise AgentMessage générique.
|
|
138
|
+
/**
|
|
139
|
+
* Gère le transfert d'un agent vers un autre (handoff).
|
|
140
|
+
* Responsabilité unique : `transferAgents` uniquement.
|
|
141
|
+
*
|
|
142
|
+
* TODO [Phase 2 - openai-agents-js]:
|
|
143
|
+
* Sera remplacé par le handoff natif openai-agents-js.
|
|
144
|
+
* Les concepts downstreamAgents/confidence seront mappés vers swarm.run / handoff strategies.
|
|
145
|
+
* @deprecated
|
|
146
|
+
*/
|
|
138
147
|
async function handleTransferCall(discussion, currentAgentRef, agents, functionCallParams, context) {
|
|
139
148
|
const currentAgentName = currentAgentRef.name;
|
|
140
149
|
const args = JSON.parse(functionCallParams?.function?.arguments || '{}');
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
console.log(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
discussion.messages.slice(1).forEach((m) => {
|
|
157
|
-
process.stdout.write(`-- DBG ---> 🤖 ${m.role}: ${m.content}\n`);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
//
|
|
161
|
-
// agent transfer to the destination agent
|
|
162
|
-
const destinationAgent = agents.find((agent) => agent.name === destinationAgentName);
|
|
163
|
-
if (destinationAgent) {
|
|
164
|
-
//console.log(`🤖 Agent "${destinationAgent.name}" en préparation`);
|
|
165
|
-
currentAgentRef.name = destinationAgent.name;
|
|
166
|
-
//
|
|
167
|
-
// Generate ID for CONTEXT TRAIL (loop detection)
|
|
168
|
-
const transferId = (0, exports.toSlug)(args.rationale_for_transfer);
|
|
169
|
-
return {
|
|
170
|
-
name: functionCallParams.function.name, // ← tool pour addStep
|
|
171
|
-
feedback: args.rationale_for_transfer, // ← reason pour addStep
|
|
172
|
-
context: `${currentAgentName} → ${destinationAgentName}`, // ← context pour addStep
|
|
173
|
-
id: transferId, // ← ID optionnel pour addStep
|
|
174
|
-
destination_agent: destinationAgentName,
|
|
175
|
-
source_agent: currentAgentName,
|
|
176
|
-
content: '', // ✅ Transfert silencieux
|
|
177
|
-
did_transfer: true
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
console.log(`❌L'agent destination "${destinationAgentName}" n'a pas été trouvé.`);
|
|
182
|
-
return {
|
|
183
|
-
feedback: `❌ L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
184
|
-
content: `❌L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
185
|
-
context: `❌L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
186
|
-
did_transfer: false,
|
|
187
|
-
name: functionCallParams.function.name
|
|
188
|
-
};
|
|
189
|
-
}
|
|
150
|
+
if (args.confidence < 0.7) {
|
|
151
|
+
return {
|
|
152
|
+
content: "Le transfert n'est pas nécessaire, tu DOIS répondre directement",
|
|
153
|
+
feedback: args.rationale_for_transfer,
|
|
154
|
+
did_transfer: false,
|
|
155
|
+
name: functionCallParams.function.name
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const destinationAgentName = args.destination_agent;
|
|
159
|
+
console.log(`🤖 Transfert de l'agent "${currentAgentName}" vers "${destinationAgentName}" (${args?.confidence})`, '::', args?.rationale_for_transfer);
|
|
160
|
+
if (currentAgentName === destinationAgentName) {
|
|
161
|
+
console.log("❌ Le transfert sur moi-même n'est pas nécessaire", destinationAgentName, args);
|
|
162
|
+
discussion.messages.slice(1).forEach((m) => {
|
|
163
|
+
process.stdout.write(`-- DBG ---> 🤖 ${m.role}: ${m.content}\n`);
|
|
164
|
+
});
|
|
190
165
|
}
|
|
191
|
-
|
|
166
|
+
const destinationAgent = agents.find(a => a.name === destinationAgentName);
|
|
167
|
+
if (destinationAgent) {
|
|
168
|
+
currentAgentRef.name = destinationAgent.name;
|
|
169
|
+
const transferId = (0, exports.toSlug)(args.rationale_for_transfer);
|
|
170
|
+
return {
|
|
171
|
+
name: functionCallParams.function.name,
|
|
172
|
+
feedback: args.rationale_for_transfer,
|
|
173
|
+
context: `${currentAgentName} → ${destinationAgentName}`,
|
|
174
|
+
id: transferId,
|
|
175
|
+
destination_agent: destinationAgentName,
|
|
176
|
+
source_agent: currentAgentName,
|
|
177
|
+
content: '',
|
|
178
|
+
did_transfer: true
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
console.log(`❌ L'agent destination "${destinationAgentName}" n'a pas été trouvé.`);
|
|
182
|
+
return {
|
|
183
|
+
feedback: `❌ L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
184
|
+
content: `❌ L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
185
|
+
context: `❌ L'agent destination "${destinationAgentName}" n'a pas été trouvé.`,
|
|
186
|
+
did_transfer: false,
|
|
187
|
+
name: functionCallParams.function.name
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gère les tool calls métier (toolLogic) et le thinking interne.
|
|
192
|
+
* Extrait de handleTransferCall — responsabilité : tout sauf transferAgents et subAgent*.
|
|
193
|
+
*
|
|
194
|
+
* ⚠️ ALWAYS inject context in tool logic, ALWAYS!
|
|
195
|
+
*/
|
|
196
|
+
async function handleToolLogicCall(currentAgentRef, agents, functionCallParams, context) {
|
|
197
|
+
const args = JSON.parse(functionCallParams?.function?.arguments || '{}');
|
|
198
|
+
const toolName = functionCallParams.function.name;
|
|
199
|
+
if (toolName === 'thinking') {
|
|
192
200
|
const { justification, thought, step } = args;
|
|
193
|
-
console.log('🤖', currentAgentRef.name, '->',
|
|
201
|
+
console.log('🤖', currentAgentRef.name, '->', toolName, '::', thought, '(step', step, ')');
|
|
194
202
|
return {
|
|
195
203
|
feedback: justification,
|
|
196
204
|
content: `Pour l'étape ${step}, j'ai pensé à "${thought}"`,
|
|
197
|
-
name:
|
|
205
|
+
name: toolName,
|
|
198
206
|
usage: 0
|
|
199
207
|
};
|
|
200
208
|
}
|
|
201
|
-
//
|
|
202
|
-
// looking on agents tool logic
|
|
203
|
-
// ⚠️ ALWAYS inject context in tool logic, ALWAYS!
|
|
204
209
|
const agent = agents.find(a => a.name === currentAgentRef.name);
|
|
205
|
-
if (agent?.toolLogic && agent.toolLogic[
|
|
206
|
-
const rawResult = await agent.toolLogic[
|
|
210
|
+
if (agent?.toolLogic && agent.toolLogic[toolName]) {
|
|
211
|
+
const rawResult = await agent.toolLogic[toolName](args, context);
|
|
207
212
|
//
|
|
208
213
|
// ✅ Le tool peut retourner { content, context, id, usage? } OU ToolContractOutput
|
|
209
|
-
// - Si content existe → utiliser le texte formaté
|
|
210
|
-
// - Sinon → préserver rawResult pour sérialisation (ToolContractOutput)
|
|
211
214
|
// - context: identifiant sémantique unique pour le trail (ex: "intention_123", "daily-events")
|
|
212
|
-
// - id: slug unique pour détection de boucles
|
|
213
|
-
// Si le tool ne fournit pas context/id, on utilise le nom du tool comme fallback
|
|
215
|
+
// - id: slug unique pour détection de boucles
|
|
214
216
|
const toolContext = rawResult.context || 'Null';
|
|
215
217
|
const toolId = rawResult.id || args.justification || JSON.stringify(args);
|
|
216
218
|
return {
|
|
217
|
-
content: rawResult.content,
|
|
218
|
-
name:
|
|
219
|
+
content: rawResult.content,
|
|
220
|
+
name: toolName,
|
|
219
221
|
context: toolContext,
|
|
220
222
|
id: toolId,
|
|
221
223
|
usage: rawResult.usage,
|
|
222
224
|
feedback: rawResult.feedback,
|
|
223
|
-
rawResult: rawResult
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
// whit thinking, we hask the agent to restart the conversation
|
|
228
|
-
// console.log('🤖',agent.name,'->',agent.tools[0]);
|
|
229
|
-
console.log("❌ Cette fonction n'existe pas !", agent.name, functionCallParams.function.name);
|
|
230
|
-
return {
|
|
231
|
-
feedback: `Humm, cette fonction "${functionCallParams.function.name}" n'existe pas!`,
|
|
232
|
-
name: functionCallParams.function.name,
|
|
233
|
-
content: `Cette fonction "${functionCallParams.function.name}" n'existe pas, tu ne dois plus l'appeler et TU DOIS répondre à la question.`
|
|
225
|
+
rawResult: rawResult
|
|
234
226
|
};
|
|
235
227
|
}
|
|
228
|
+
console.log("❌ Cette fonction n'existe pas !", agent?.name, toolName);
|
|
229
|
+
return {
|
|
230
|
+
feedback: `Humm, cette fonction "${toolName}" n'existe pas!`,
|
|
231
|
+
name: toolName,
|
|
232
|
+
content: `Cette fonction "${toolName}" n'existe pas, tu ne dois plus l'appeler et TU DOIS répondre à la question.`
|
|
233
|
+
};
|
|
236
234
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.885",
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prebuild": "npm version patch --no-git-tag-version",
|
|
12
|
-
"build": "tsc",
|
|
12
|
+
"build": "tsc && cp mupdf-extract.mjs dist/",
|
|
13
13
|
"test": "jest --silent",
|
|
14
14
|
"test:quiet": "jest --testPathIgnorePatterns=agent* --silent tests",
|
|
15
15
|
"test:verbose": "jest --testPathIgnorePatterns=agent* --verbose tests",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"hnswlib-node": "^3.0.0",
|
|
33
33
|
"jsdom": "^26.0.0",
|
|
34
34
|
"minisearch": "^7.1.0",
|
|
35
|
+
"mupdf": "^1.27.0",
|
|
35
36
|
"natural": "^8.1.0",
|
|
36
37
|
"openai": "^5.23.2",
|
|
37
38
|
"simple-git": "^3.27.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.semantic = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const prompts_1 = require("./prompts");
|
|
6
|
-
exports.semantic = {
|
|
7
|
-
name: "semantic",
|
|
8
|
-
model: "LOW",
|
|
9
|
-
publicDescription: "Agent spécialisé dans l’extraction sémantique structurée",
|
|
10
|
-
instructions: prompts_1.semanticPrompt,
|
|
11
|
-
tools: [],
|
|
12
|
-
downstreamAgents: []
|
|
13
|
-
};
|
|
14
|
-
//instructions: [semanticPrompt, semanticStructurePrompt],
|
|
15
|
-
//
|
|
16
|
-
// go back to semantic once the task is done
|
|
17
|
-
// add the transfer tool to point to downstreamAgents
|
|
18
|
-
const agents = (0, utils_1.injectTransferTools)([exports.semantic]);
|
|
19
|
-
exports.default = agents;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy Implementation - Chat Completions API (beta.chat.completions)
|
|
3
|
-
*
|
|
4
|
-
* ⚠️ Cette implémentation utilise openai.beta.chat.completions.stream (ancienne API)
|
|
5
|
-
* Pour les nouveaux projets, Responses API (responses.ts) est recommandée.
|
|
6
|
-
*
|
|
7
|
-
* Code optimisé depuis execute.ts original avec les améliorations suivantes:
|
|
8
|
-
* - OPTIM: Helpers centralisés (accumulateUsageTokens, stepsToActions)
|
|
9
|
-
* - BUG FIX: executionResultMerge fusionne actions correctement (corrigé dans types.ts)
|
|
10
|
-
* - BUG FIX: moreThinkin supprimé (obsolète, reasoning_effort fait le job)
|
|
11
|
-
* - BUG FIX: Suppression de la boucle do...while(moreThinkin)
|
|
12
|
-
* - BUG FIX: Suppression de la ligne reasoning_effort dupliquée (ligne 425 originale)
|
|
13
|
-
*
|
|
14
|
-
* TODO [Optimisation future]: Remplacer la boucle for séquentielle par batchProcessToolCalls
|
|
15
|
-
* pour exploiter pleinement parallel_tool_calls et réduire la latence
|
|
16
|
-
*/
|
|
17
|
-
import { AgentConfig, AgenticContext, ExecuteAgentResult, ExecutionResult } from "../types";
|
|
18
|
-
import { ReadCompletionsStreamOptions, ExecuteAgentSetParams } from "./shared";
|
|
19
|
-
export declare function readCompletionsStream(params: ReadCompletionsStreamOptions): Promise<ExecutionResult>;
|
|
20
|
-
/**
|
|
21
|
-
* Parameters for executing an agent set
|
|
22
|
-
*/
|
|
23
|
-
export interface ExecuteAgentSetParamsLegacy {
|
|
24
|
-
enrichWithMemory?: (role: string, agent: AgentConfig, context: AgenticContext) => Promise<string>;
|
|
25
|
-
query: string;
|
|
26
|
-
home?: string;
|
|
27
|
-
thinking?: boolean;
|
|
28
|
-
model?: string;
|
|
29
|
-
stdout: any;
|
|
30
|
-
messages?: any[];
|
|
31
|
-
verbose?: boolean;
|
|
32
|
-
json?: boolean;
|
|
33
|
-
schema?: any;
|
|
34
|
-
debug?: boolean;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Executes a set of agents to process a user query
|
|
38
|
-
*
|
|
39
|
-
* OPTIMIZED: Sans boucle do...while(moreThinkin), reasoning_effort fait le job
|
|
40
|
-
*/
|
|
41
|
-
export declare function executeAgentSet(agentSet: AgentConfig[], context: AgenticContext, params: ExecuteAgentSetParams): Promise<ExecutionResult>;
|
|
42
|
-
export declare function executeAgent(agentSet: AgentConfig[], params: ExecuteAgentSetParams): Promise<ExecuteAgentResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Executes a simple query without agent orchestration or tool handling
|
|
45
|
-
*/
|
|
46
|
-
export declare function executeQuery(params: ExecuteAgentSetParams): Promise<ExecuteAgentResult>;
|