@inkeep/agents-sdk 0.18.0 → 0.19.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/README.md +15 -15
- package/dist/index.cjs +376 -346
- package/dist/index.d.cts +126 -119
- package/dist/index.d.ts +126 -119
- package/dist/index.js +363 -344
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getLogger, apiFetch, CredentialReferenceApiInsertSchema, MCPToolConfigSchema, createDatabaseClient, getProject } from '@inkeep/agents-core';
|
|
2
|
-
|
|
2
|
+
export { ANTHROPIC_MODELS, GOOGLE_MODELS, OPENAI_MODELS } from '@inkeep/agents-core';
|
|
3
|
+
import { isZodSchema, convertZodToJsonSchemaWithPreview, convertZodToJsonSchema } from '@inkeep/agents-core/utils/schema-conversion';
|
|
3
4
|
import fs from 'fs';
|
|
4
5
|
import { builtinModules } from 'module';
|
|
5
6
|
import path from 'path';
|
|
@@ -28,9 +29,16 @@ var ArtifactComponent = class {
|
|
|
28
29
|
__publicField(this, "initialized", false);
|
|
29
30
|
__publicField(this, "id");
|
|
30
31
|
this.id = config.id || generateIdFromName(config.name);
|
|
32
|
+
let processedProps;
|
|
33
|
+
if (config.props && isZodSchema(config.props)) {
|
|
34
|
+
processedProps = convertZodToJsonSchemaWithPreview(config.props);
|
|
35
|
+
} else {
|
|
36
|
+
processedProps = config.props;
|
|
37
|
+
}
|
|
31
38
|
this.config = {
|
|
32
39
|
...config,
|
|
33
|
-
id: this.id
|
|
40
|
+
id: this.id,
|
|
41
|
+
props: processedProps
|
|
34
42
|
};
|
|
35
43
|
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
36
44
|
this.tenantId = "default";
|
|
@@ -43,7 +51,7 @@ var ArtifactComponent = class {
|
|
|
43
51
|
"ArtifactComponent constructor initialized"
|
|
44
52
|
);
|
|
45
53
|
}
|
|
46
|
-
// Set context (tenantId, projectId, and baseURL) from external source (agent,
|
|
54
|
+
// Set context (tenantId, projectId, and baseURL) from external source (agent, agent, CLI, etc)
|
|
47
55
|
setContext(tenantId, projectId, baseURL) {
|
|
48
56
|
this.tenantId = tenantId;
|
|
49
57
|
this.projectId = projectId;
|
|
@@ -169,9 +177,16 @@ var DataComponent = class {
|
|
|
169
177
|
__publicField(this, "initialized", false);
|
|
170
178
|
__publicField(this, "id");
|
|
171
179
|
this.id = config.id || generateIdFromName(config.name);
|
|
180
|
+
let processedProps;
|
|
181
|
+
if (config.props && isZodSchema(config.props)) {
|
|
182
|
+
processedProps = convertZodToJsonSchema(config.props);
|
|
183
|
+
} else {
|
|
184
|
+
processedProps = config.props;
|
|
185
|
+
}
|
|
172
186
|
this.config = {
|
|
173
187
|
...config,
|
|
174
|
-
id: this.id
|
|
188
|
+
id: this.id,
|
|
189
|
+
props: processedProps
|
|
175
190
|
};
|
|
176
191
|
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
177
192
|
this.tenantId = "default";
|
|
@@ -184,7 +199,7 @@ var DataComponent = class {
|
|
|
184
199
|
"DataComponent constructor initialized"
|
|
185
200
|
);
|
|
186
201
|
}
|
|
187
|
-
// Set context (tenantId, projectId, and baseURL) from external source (sub-agent,
|
|
202
|
+
// Set context (tenantId, projectId, and baseURL) from external source (sub-agent, agent, CLI, etc)
|
|
188
203
|
setContext(tenantId, projectId, baseURL) {
|
|
189
204
|
this.tenantId = tenantId;
|
|
190
205
|
this.projectId = projectId;
|
|
@@ -460,8 +475,8 @@ var FunctionTool = class {
|
|
|
460
475
|
for (const dep in deps) {
|
|
461
476
|
if (deps[dep] === false) {
|
|
462
477
|
delete deps[dep];
|
|
478
|
+
throw new Error(`Dependency \x1B[1;32m${dep}\x1B[0m used in function tool \x1B[1;32m${config.name}\x1B[0m is neither installed nor in dependencies object.`);
|
|
463
479
|
}
|
|
464
|
-
throw new Error(`Dependency \x1B[1;32m${dep}\x1B[0m used in function tool \x1B[1;32m${config.name}\x1B[0m is neither installed nor in dependencies object.`);
|
|
465
480
|
}
|
|
466
481
|
this.config.dependencies = deps;
|
|
467
482
|
}
|
|
@@ -537,7 +552,7 @@ var Tool = class {
|
|
|
537
552
|
"Tool constructor initialized"
|
|
538
553
|
);
|
|
539
554
|
}
|
|
540
|
-
// Set context (tenantId, projectId, and baseURL) from external source (agent,
|
|
555
|
+
// Set context (tenantId, projectId, and baseURL) from external source (agent, agent, CLI, etc)
|
|
541
556
|
setContext(tenantId, projectId, baseURL) {
|
|
542
557
|
this.tenantId = tenantId;
|
|
543
558
|
this.projectId = projectId;
|
|
@@ -692,7 +707,7 @@ function normalizeAgentCanUseType(value, fallbackName) {
|
|
|
692
707
|
throw new Error(`Invalid AgentCanUseType: expected Tool or AgentMcpConfig, got ${typeof value}`);
|
|
693
708
|
}
|
|
694
709
|
|
|
695
|
-
// src/
|
|
710
|
+
// src/subAgent.ts
|
|
696
711
|
var logger6 = getLogger("agent");
|
|
697
712
|
function resolveGetter(value) {
|
|
698
713
|
if (typeof value === "function") {
|
|
@@ -721,7 +736,7 @@ var SubAgent = class {
|
|
|
721
736
|
"Agent constructor initialized"
|
|
722
737
|
);
|
|
723
738
|
}
|
|
724
|
-
// Set context (tenantId, projectId, and baseURL) from external source (
|
|
739
|
+
// Set context (tenantId, projectId, and baseURL) from external source (agent, CLI, etc)
|
|
725
740
|
setContext(tenantId, projectId, baseURL) {
|
|
726
741
|
this.tenantId = tenantId;
|
|
727
742
|
this.projectId = projectId;
|
|
@@ -1439,28 +1454,28 @@ var SubAgent = class {
|
|
|
1439
1454
|
}
|
|
1440
1455
|
}
|
|
1441
1456
|
};
|
|
1442
|
-
var logger7 = getLogger("
|
|
1443
|
-
async function
|
|
1457
|
+
var logger7 = getLogger("agentFullClient");
|
|
1458
|
+
async function updateFullAgentViaAPI(tenantId, projectId, apiUrl, agentId, agentData) {
|
|
1444
1459
|
logger7.info(
|
|
1445
1460
|
{
|
|
1446
1461
|
tenantId,
|
|
1447
1462
|
projectId,
|
|
1448
|
-
|
|
1463
|
+
agentId,
|
|
1449
1464
|
apiUrl
|
|
1450
1465
|
},
|
|
1451
|
-
"Updating full
|
|
1466
|
+
"Updating full agent via API"
|
|
1452
1467
|
);
|
|
1453
|
-
const url = `${apiUrl}/tenants/${tenantId}/projects/${projectId}/
|
|
1468
|
+
const url = `${apiUrl}/tenants/${tenantId}/projects/${projectId}/agent/${agentId}`;
|
|
1454
1469
|
const response = await fetch(url, {
|
|
1455
1470
|
method: "PUT",
|
|
1456
1471
|
headers: {
|
|
1457
1472
|
"Content-Type": "application/json"
|
|
1458
1473
|
},
|
|
1459
|
-
body: JSON.stringify(
|
|
1474
|
+
body: JSON.stringify(agentData)
|
|
1460
1475
|
});
|
|
1461
1476
|
if (!response.ok) {
|
|
1462
1477
|
const errorText = await response.text();
|
|
1463
|
-
let errorMessage = `Failed to update
|
|
1478
|
+
let errorMessage = `Failed to update agent: ${response.status} ${response.statusText}`;
|
|
1464
1479
|
try {
|
|
1465
1480
|
const errorJson = JSON.parse(errorText);
|
|
1466
1481
|
if (errorJson.error) {
|
|
@@ -1476,29 +1491,29 @@ async function updateFullGraphViaAPI(tenantId, projectId, apiUrl, graphId, graph
|
|
|
1476
1491
|
status: response.status,
|
|
1477
1492
|
error: errorMessage
|
|
1478
1493
|
},
|
|
1479
|
-
"Failed to update
|
|
1494
|
+
"Failed to update agent via API"
|
|
1480
1495
|
);
|
|
1481
1496
|
throw new Error(errorMessage);
|
|
1482
1497
|
}
|
|
1483
1498
|
const result = await response.json();
|
|
1484
1499
|
logger7.info(
|
|
1485
1500
|
{
|
|
1486
|
-
|
|
1501
|
+
agentId
|
|
1487
1502
|
},
|
|
1488
|
-
"Successfully updated
|
|
1503
|
+
"Successfully updated agent via API"
|
|
1489
1504
|
);
|
|
1490
1505
|
return result.data;
|
|
1491
1506
|
}
|
|
1492
1507
|
|
|
1493
|
-
// src/
|
|
1494
|
-
var logger8 = getLogger("
|
|
1508
|
+
// src/agent.ts
|
|
1509
|
+
var logger8 = getLogger("agent");
|
|
1495
1510
|
function resolveGetter2(value) {
|
|
1496
1511
|
if (typeof value === "function") {
|
|
1497
1512
|
return value();
|
|
1498
1513
|
}
|
|
1499
1514
|
return value;
|
|
1500
1515
|
}
|
|
1501
|
-
var
|
|
1516
|
+
var Agent = class {
|
|
1502
1517
|
constructor(config) {
|
|
1503
1518
|
__publicField(this, "subAgents", []);
|
|
1504
1519
|
__publicField(this, "agentMap", /* @__PURE__ */ new Map());
|
|
@@ -1506,24 +1521,24 @@ var AgentGraph = class {
|
|
|
1506
1521
|
__publicField(this, "baseURL");
|
|
1507
1522
|
__publicField(this, "tenantId");
|
|
1508
1523
|
__publicField(this, "projectId");
|
|
1509
|
-
__publicField(this, "
|
|
1510
|
-
__publicField(this, "
|
|
1511
|
-
__publicField(this, "
|
|
1524
|
+
__publicField(this, "agentId");
|
|
1525
|
+
__publicField(this, "agentName");
|
|
1526
|
+
__publicField(this, "agentDescription");
|
|
1512
1527
|
__publicField(this, "initialized", false);
|
|
1513
1528
|
__publicField(this, "contextConfig");
|
|
1514
1529
|
// ContextConfigBuilder
|
|
1515
1530
|
__publicField(this, "credentials");
|
|
1516
1531
|
__publicField(this, "models");
|
|
1517
1532
|
__publicField(this, "statusUpdateSettings");
|
|
1518
|
-
__publicField(this, "
|
|
1533
|
+
__publicField(this, "agentPrompt");
|
|
1519
1534
|
__publicField(this, "stopWhen");
|
|
1520
1535
|
__publicField(this, "dbClient");
|
|
1521
1536
|
this.defaultSubAgent = config.defaultSubAgent;
|
|
1522
1537
|
this.tenantId = "default";
|
|
1523
1538
|
this.projectId = "default";
|
|
1524
|
-
this.
|
|
1525
|
-
this.
|
|
1526
|
-
this.
|
|
1539
|
+
this.agentId = config.id;
|
|
1540
|
+
this.agentName = config.name || this.agentId;
|
|
1541
|
+
this.agentDescription = config.description;
|
|
1527
1542
|
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
1528
1543
|
this.contextConfig = config.contextConfig;
|
|
1529
1544
|
this.credentials = resolveGetter2(config.credentials);
|
|
@@ -1533,12 +1548,12 @@ var AgentGraph = class {
|
|
|
1533
1548
|
url: dbUrl
|
|
1534
1549
|
});
|
|
1535
1550
|
this.statusUpdateSettings = config.statusUpdates;
|
|
1536
|
-
this.
|
|
1551
|
+
this.agentPrompt = config.agentPrompt;
|
|
1537
1552
|
this.stopWhen = config.stopWhen ? {
|
|
1538
1553
|
transferCountIs: config.stopWhen.transferCountIs
|
|
1539
1554
|
} : void 0;
|
|
1540
1555
|
this.subAgents = resolveGetter2(config.subAgents) || [];
|
|
1541
|
-
this.agentMap = new Map(this.subAgents.map((
|
|
1556
|
+
this.agentMap = new Map(this.subAgents.map((agent2) => [agent2.getId(), agent2]));
|
|
1542
1557
|
if (this.defaultSubAgent) {
|
|
1543
1558
|
this.subAgents.push(this.defaultSubAgent);
|
|
1544
1559
|
this.agentMap.set(this.defaultSubAgent.getId(), this.defaultSubAgent);
|
|
@@ -1548,12 +1563,12 @@ var AgentGraph = class {
|
|
|
1548
1563
|
}
|
|
1549
1564
|
logger8.info(
|
|
1550
1565
|
{
|
|
1551
|
-
|
|
1566
|
+
agentId: this.agentId,
|
|
1552
1567
|
tenantId: this.tenantId,
|
|
1553
1568
|
agentCount: this.subAgents.length,
|
|
1554
1569
|
defaultSubAgent: this.defaultSubAgent?.getName()
|
|
1555
1570
|
},
|
|
1556
|
-
"
|
|
1571
|
+
"Agent created"
|
|
1557
1572
|
);
|
|
1558
1573
|
}
|
|
1559
1574
|
/**
|
|
@@ -1562,14 +1577,14 @@ var AgentGraph = class {
|
|
|
1562
1577
|
*/
|
|
1563
1578
|
setConfig(tenantId, projectId, apiUrl) {
|
|
1564
1579
|
if (this.initialized) {
|
|
1565
|
-
throw new Error("Cannot set config after
|
|
1580
|
+
throw new Error("Cannot set config after agent has been initialized");
|
|
1566
1581
|
}
|
|
1567
1582
|
this.tenantId = tenantId;
|
|
1568
1583
|
this.projectId = projectId;
|
|
1569
1584
|
this.baseURL = apiUrl;
|
|
1570
|
-
for (const
|
|
1571
|
-
if (this.isInternalAgent(
|
|
1572
|
-
const internalAgent =
|
|
1585
|
+
for (const agent2 of this.subAgents) {
|
|
1586
|
+
if (this.isInternalAgent(agent2)) {
|
|
1587
|
+
const internalAgent = agent2;
|
|
1573
1588
|
if (internalAgent.setContext) {
|
|
1574
1589
|
internalAgent.setContext(tenantId, projectId, apiUrl);
|
|
1575
1590
|
}
|
|
@@ -1582,35 +1597,35 @@ var AgentGraph = class {
|
|
|
1582
1597
|
}
|
|
1583
1598
|
}
|
|
1584
1599
|
} else {
|
|
1585
|
-
const externalAgent2 =
|
|
1600
|
+
const externalAgent2 = agent2;
|
|
1586
1601
|
if (externalAgent2.setContext) {
|
|
1587
1602
|
externalAgent2.setContext(tenantId, apiUrl);
|
|
1588
1603
|
}
|
|
1589
1604
|
}
|
|
1590
1605
|
}
|
|
1591
1606
|
if (this.contextConfig?.setContext) {
|
|
1592
|
-
this.contextConfig.setContext(tenantId, projectId, this.
|
|
1607
|
+
this.contextConfig.setContext(tenantId, projectId, this.agentId, this.baseURL);
|
|
1593
1608
|
}
|
|
1594
1609
|
logger8.info(
|
|
1595
1610
|
{
|
|
1596
|
-
|
|
1611
|
+
agentId: this.agentId,
|
|
1597
1612
|
tenantId: this.tenantId,
|
|
1598
1613
|
projectId: this.projectId,
|
|
1599
1614
|
apiUrl: this.baseURL
|
|
1600
1615
|
},
|
|
1601
|
-
"
|
|
1616
|
+
"Agent configuration updated"
|
|
1602
1617
|
);
|
|
1603
1618
|
}
|
|
1604
1619
|
/**
|
|
1605
|
-
* Convert the
|
|
1620
|
+
* Convert the Agent to FullAgentDefinition format for the new agent endpoint
|
|
1606
1621
|
*/
|
|
1607
|
-
async
|
|
1622
|
+
async toFullAgentDefinition() {
|
|
1608
1623
|
const agentsObject = {};
|
|
1609
1624
|
const functionToolsObject = {};
|
|
1610
1625
|
const functionsObject = {};
|
|
1611
|
-
for (const
|
|
1612
|
-
if (this.isInternalAgent(
|
|
1613
|
-
const internalAgent =
|
|
1626
|
+
for (const agent2 of this.subAgents) {
|
|
1627
|
+
if (this.isInternalAgent(agent2)) {
|
|
1628
|
+
const internalAgent = agent2;
|
|
1614
1629
|
const transfers = internalAgent.getTransfers();
|
|
1615
1630
|
const delegates = internalAgent.getDelegates();
|
|
1616
1631
|
const tools = [];
|
|
@@ -1638,8 +1653,8 @@ var AgentGraph = class {
|
|
|
1638
1653
|
name: toolData.name,
|
|
1639
1654
|
description: toolData.description,
|
|
1640
1655
|
functionId: toolData.functionId,
|
|
1641
|
-
|
|
1642
|
-
// Include
|
|
1656
|
+
agentId: this.agentId
|
|
1657
|
+
// Include agentId for agent-scoped function tools
|
|
1643
1658
|
};
|
|
1644
1659
|
}
|
|
1645
1660
|
}
|
|
@@ -1680,7 +1695,7 @@ var AgentGraph = class {
|
|
|
1680
1695
|
type: "internal"
|
|
1681
1696
|
};
|
|
1682
1697
|
} else {
|
|
1683
|
-
const externalAgent2 =
|
|
1698
|
+
const externalAgent2 = agent2;
|
|
1684
1699
|
agentsObject[externalAgent2.getId()] = {
|
|
1685
1700
|
id: externalAgent2.getId(),
|
|
1686
1701
|
name: externalAgent2.getName(),
|
|
@@ -1693,9 +1708,9 @@ var AgentGraph = class {
|
|
|
1693
1708
|
}
|
|
1694
1709
|
}
|
|
1695
1710
|
return {
|
|
1696
|
-
id: this.
|
|
1697
|
-
name: this.
|
|
1698
|
-
description: this.
|
|
1711
|
+
id: this.agentId,
|
|
1712
|
+
name: this.agentName,
|
|
1713
|
+
description: this.agentDescription,
|
|
1699
1714
|
defaultSubAgentId: this.defaultSubAgent?.getId() || "",
|
|
1700
1715
|
subAgents: agentsObject,
|
|
1701
1716
|
contextConfig: this.contextConfig?.toObject(),
|
|
@@ -1703,7 +1718,7 @@ var AgentGraph = class {
|
|
|
1703
1718
|
...Object.keys(functionsObject).length > 0 && { functions: functionsObject },
|
|
1704
1719
|
models: this.models,
|
|
1705
1720
|
statusUpdates: this.statusUpdateSettings,
|
|
1706
|
-
|
|
1721
|
+
prompt: this.agentPrompt,
|
|
1707
1722
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1708
1723
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1709
1724
|
};
|
|
@@ -1712,13 +1727,13 @@ var AgentGraph = class {
|
|
|
1712
1727
|
* Initialize all tools in all agents (especially IPCTools that need MCP server URLs)
|
|
1713
1728
|
*/
|
|
1714
1729
|
async initializeAllTools() {
|
|
1715
|
-
logger8.info({
|
|
1730
|
+
logger8.info({ agentId: this.agentId }, "Initializing all tools in agent");
|
|
1716
1731
|
const toolInitPromises = [];
|
|
1717
|
-
for (const
|
|
1718
|
-
if (!
|
|
1732
|
+
for (const agent2 of this.subAgents) {
|
|
1733
|
+
if (!agent2.getTools) {
|
|
1719
1734
|
continue;
|
|
1720
1735
|
}
|
|
1721
|
-
const internalAgent =
|
|
1736
|
+
const internalAgent = agent2;
|
|
1722
1737
|
const agentTools = internalAgent.getTools();
|
|
1723
1738
|
for (const [toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1724
1739
|
if (toolInstance && typeof toolInstance === "object") {
|
|
@@ -1738,7 +1753,7 @@ var AgentGraph = class {
|
|
|
1738
1753
|
}
|
|
1739
1754
|
logger8.debug(
|
|
1740
1755
|
{
|
|
1741
|
-
subAgentId:
|
|
1756
|
+
subAgentId: agent2.getId(),
|
|
1742
1757
|
toolName,
|
|
1743
1758
|
toolType: toolInstance.constructor.name,
|
|
1744
1759
|
skipDbRegistration
|
|
@@ -1748,7 +1763,7 @@ var AgentGraph = class {
|
|
|
1748
1763
|
} catch (error) {
|
|
1749
1764
|
logger8.error(
|
|
1750
1765
|
{
|
|
1751
|
-
subAgentId:
|
|
1766
|
+
subAgentId: agent2.getId(),
|
|
1752
1767
|
toolName,
|
|
1753
1768
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1754
1769
|
},
|
|
@@ -1764,109 +1779,109 @@ var AgentGraph = class {
|
|
|
1764
1779
|
}
|
|
1765
1780
|
await Promise.all(toolInitPromises);
|
|
1766
1781
|
logger8.info(
|
|
1767
|
-
{
|
|
1782
|
+
{ agentId: this.agentId, toolCount: toolInitPromises.length },
|
|
1768
1783
|
"All tools initialized successfully"
|
|
1769
1784
|
);
|
|
1770
1785
|
}
|
|
1771
1786
|
/**
|
|
1772
|
-
* Initialize the
|
|
1787
|
+
* Initialize the agent and all agents in the backend using the new agent endpoint
|
|
1773
1788
|
*/
|
|
1774
1789
|
async init() {
|
|
1775
1790
|
if (this.initialized) {
|
|
1776
|
-
logger8.info({
|
|
1791
|
+
logger8.info({ agentId: this.agentId }, "Agent already initialized");
|
|
1777
1792
|
return;
|
|
1778
1793
|
}
|
|
1779
1794
|
logger8.info(
|
|
1780
1795
|
{
|
|
1781
|
-
|
|
1796
|
+
agentId: this.agentId,
|
|
1782
1797
|
agentCount: this.subAgents.length
|
|
1783
1798
|
},
|
|
1784
|
-
"Initializing agent
|
|
1799
|
+
"Initializing agent using new agent endpoint"
|
|
1785
1800
|
);
|
|
1786
1801
|
try {
|
|
1787
1802
|
await this.initializeAllTools();
|
|
1788
1803
|
await this.applyModelInheritance();
|
|
1789
|
-
const
|
|
1804
|
+
const agentDefinition = await this.toFullAgentDefinition();
|
|
1790
1805
|
logger8.info(
|
|
1791
1806
|
{
|
|
1792
|
-
|
|
1807
|
+
agentId: this.agentId,
|
|
1793
1808
|
mode: "api-client",
|
|
1794
1809
|
apiUrl: this.baseURL
|
|
1795
1810
|
},
|
|
1796
|
-
"Using API client to create/update
|
|
1811
|
+
"Using API client to create/update agent"
|
|
1797
1812
|
);
|
|
1798
|
-
const
|
|
1813
|
+
const createdAgent = await updateFullAgentViaAPI(
|
|
1799
1814
|
this.tenantId,
|
|
1800
1815
|
this.projectId,
|
|
1801
1816
|
this.baseURL,
|
|
1802
|
-
this.
|
|
1803
|
-
|
|
1817
|
+
this.agentId,
|
|
1818
|
+
agentDefinition
|
|
1804
1819
|
);
|
|
1805
1820
|
logger8.info(
|
|
1806
1821
|
{
|
|
1807
|
-
|
|
1808
|
-
agentCount: Object.keys(
|
|
1822
|
+
agentId: this.agentId,
|
|
1823
|
+
agentCount: Object.keys(createdAgent.subAgents || {}).length
|
|
1809
1824
|
},
|
|
1810
|
-
"Agent
|
|
1825
|
+
"Agent initialized successfully using agent endpoint"
|
|
1811
1826
|
);
|
|
1812
1827
|
this.initialized = true;
|
|
1813
1828
|
} catch (error) {
|
|
1814
1829
|
logger8.error(
|
|
1815
1830
|
{
|
|
1816
|
-
|
|
1831
|
+
agentId: this.agentId,
|
|
1817
1832
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1818
1833
|
},
|
|
1819
|
-
"Failed to initialize agent
|
|
1834
|
+
"Failed to initialize agent using agent endpoint"
|
|
1820
1835
|
);
|
|
1821
1836
|
throw error;
|
|
1822
1837
|
}
|
|
1823
1838
|
}
|
|
1824
1839
|
/**
|
|
1825
1840
|
* Legacy initialization method - kept for backward compatibility
|
|
1826
|
-
* Initialize the
|
|
1841
|
+
* Initialize the agent and all agents in the backend using individual endpoints
|
|
1827
1842
|
*/
|
|
1828
1843
|
async initLegacy() {
|
|
1829
1844
|
if (this.initialized) {
|
|
1830
|
-
logger8.info({
|
|
1845
|
+
logger8.info({ agentId: this.agentId }, "Agent already initialized");
|
|
1831
1846
|
return;
|
|
1832
1847
|
}
|
|
1833
1848
|
logger8.info(
|
|
1834
1849
|
{
|
|
1835
|
-
|
|
1850
|
+
agentId: this.agentId,
|
|
1836
1851
|
agentCount: this.subAgents.length
|
|
1837
1852
|
},
|
|
1838
|
-
"Initializing agent
|
|
1853
|
+
"Initializing agent"
|
|
1839
1854
|
);
|
|
1840
1855
|
try {
|
|
1841
1856
|
if (this.contextConfig) {
|
|
1842
1857
|
await this.contextConfig.init();
|
|
1843
1858
|
logger8.info(
|
|
1844
1859
|
{
|
|
1845
|
-
|
|
1860
|
+
agentId: this.agentId,
|
|
1846
1861
|
contextConfigId: this.contextConfig.getId()
|
|
1847
1862
|
},
|
|
1848
|
-
"Context configuration initialized for
|
|
1863
|
+
"Context configuration initialized for agent"
|
|
1849
1864
|
);
|
|
1850
1865
|
}
|
|
1851
|
-
const initPromises = this.subAgents.map(async (
|
|
1866
|
+
const initPromises = this.subAgents.map(async (agent2) => {
|
|
1852
1867
|
try {
|
|
1853
|
-
|
|
1854
|
-
await
|
|
1868
|
+
agent2.config.agentId = this.agentId;
|
|
1869
|
+
await agent2.init();
|
|
1855
1870
|
logger8.debug(
|
|
1856
1871
|
{
|
|
1857
|
-
subAgentId:
|
|
1858
|
-
|
|
1872
|
+
subAgentId: agent2.getId(),
|
|
1873
|
+
agentId: this.agentId
|
|
1859
1874
|
},
|
|
1860
|
-
"Agent initialized in
|
|
1875
|
+
"Agent initialized in agent"
|
|
1861
1876
|
);
|
|
1862
1877
|
} catch (error) {
|
|
1863
1878
|
logger8.error(
|
|
1864
1879
|
{
|
|
1865
|
-
subAgentId:
|
|
1866
|
-
|
|
1880
|
+
subAgentId: agent2.getId(),
|
|
1881
|
+
agentId: this.agentId,
|
|
1867
1882
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1868
1883
|
},
|
|
1869
|
-
"Failed to initialize agent in
|
|
1884
|
+
"Failed to initialize agent in agent"
|
|
1870
1885
|
);
|
|
1871
1886
|
throw error;
|
|
1872
1887
|
}
|
|
@@ -1879,18 +1894,18 @@ var AgentGraph = class {
|
|
|
1879
1894
|
this.initialized = true;
|
|
1880
1895
|
logger8.info(
|
|
1881
1896
|
{
|
|
1882
|
-
|
|
1897
|
+
agentId: this.agentId,
|
|
1883
1898
|
agentCount: this.subAgents.length
|
|
1884
1899
|
},
|
|
1885
|
-
"Agent
|
|
1900
|
+
"Agent initialized successfully"
|
|
1886
1901
|
);
|
|
1887
1902
|
} catch (error) {
|
|
1888
1903
|
logger8.error(
|
|
1889
1904
|
{
|
|
1890
|
-
|
|
1905
|
+
agentId: this.agentId,
|
|
1891
1906
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1892
1907
|
},
|
|
1893
|
-
"Failed to initialize agent
|
|
1908
|
+
"Failed to initialize agent"
|
|
1894
1909
|
);
|
|
1895
1910
|
throw error;
|
|
1896
1911
|
}
|
|
@@ -1901,11 +1916,11 @@ var AgentGraph = class {
|
|
|
1901
1916
|
async generate(input, options) {
|
|
1902
1917
|
await this._init();
|
|
1903
1918
|
if (!this.defaultSubAgent) {
|
|
1904
|
-
throw new Error("No default agent configured for this
|
|
1919
|
+
throw new Error("No default agent configured for this agent");
|
|
1905
1920
|
}
|
|
1906
1921
|
logger8.info(
|
|
1907
1922
|
{
|
|
1908
|
-
|
|
1923
|
+
agentId: this.agentId,
|
|
1909
1924
|
defaultSubAgent: this.defaultSubAgent.getName(),
|
|
1910
1925
|
conversationId: options?.conversationId
|
|
1911
1926
|
},
|
|
@@ -1920,18 +1935,18 @@ var AgentGraph = class {
|
|
|
1920
1935
|
async stream(input, options) {
|
|
1921
1936
|
await this._init();
|
|
1922
1937
|
if (!this.defaultSubAgent) {
|
|
1923
|
-
throw new Error("No default agent configured for this
|
|
1938
|
+
throw new Error("No default agent configured for this agent");
|
|
1924
1939
|
}
|
|
1925
1940
|
logger8.info(
|
|
1926
1941
|
{
|
|
1927
|
-
|
|
1942
|
+
agentId: this.agentId,
|
|
1928
1943
|
defaultSubAgent: this.defaultSubAgent.getName(),
|
|
1929
1944
|
conversationId: options?.conversationId
|
|
1930
1945
|
},
|
|
1931
1946
|
"Streaming response with default agent"
|
|
1932
1947
|
);
|
|
1933
|
-
const textStream = async function* (
|
|
1934
|
-
const response = await
|
|
1948
|
+
const textStream = async function* (agent2) {
|
|
1949
|
+
const response = await agent2.executeWithBackend(input, options);
|
|
1935
1950
|
const words = response.split(" ");
|
|
1936
1951
|
for (const word of words) {
|
|
1937
1952
|
yield `${word} `;
|
|
@@ -1948,22 +1963,22 @@ var AgentGraph = class {
|
|
|
1948
1963
|
return await this.stream(input, options);
|
|
1949
1964
|
}
|
|
1950
1965
|
/**
|
|
1951
|
-
* Run with a specific agent from the
|
|
1966
|
+
* Run with a specific agent from the agent
|
|
1952
1967
|
*/
|
|
1953
1968
|
async runWith(subAgentId, input, options) {
|
|
1954
1969
|
await this._init();
|
|
1955
|
-
const
|
|
1956
|
-
if (!
|
|
1957
|
-
throw new Error(`Agent '${subAgentId}' not found in
|
|
1970
|
+
const agent2 = this.getSubAgent(subAgentId);
|
|
1971
|
+
if (!agent2) {
|
|
1972
|
+
throw new Error(`Agent '${subAgentId}' not found in agent`);
|
|
1958
1973
|
}
|
|
1959
|
-
if (!this.isInternalAgent(
|
|
1974
|
+
if (!this.isInternalAgent(agent2)) {
|
|
1960
1975
|
throw new Error(
|
|
1961
1976
|
`Agent '${subAgentId}' is an external agent and cannot be run directly. External agents are only accessible via delegation.`
|
|
1962
1977
|
);
|
|
1963
1978
|
}
|
|
1964
1979
|
logger8.info(
|
|
1965
1980
|
{
|
|
1966
|
-
|
|
1981
|
+
agentId: this.agentId,
|
|
1967
1982
|
subAgentId,
|
|
1968
1983
|
conversationId: options?.conversationId
|
|
1969
1984
|
},
|
|
@@ -1972,7 +1987,7 @@ var AgentGraph = class {
|
|
|
1972
1987
|
const response = await this.executeWithBackend(input, options);
|
|
1973
1988
|
return {
|
|
1974
1989
|
finalOutput: response,
|
|
1975
|
-
agent,
|
|
1990
|
+
agent: agent2,
|
|
1976
1991
|
turnCount: 1,
|
|
1977
1992
|
usage: { inputTokens: 0, outputTokens: 0 },
|
|
1978
1993
|
metadata: {
|
|
@@ -1984,48 +1999,48 @@ var AgentGraph = class {
|
|
|
1984
1999
|
/**
|
|
1985
2000
|
* Get an agent by name (unified method for all agent types)
|
|
1986
2001
|
*/
|
|
1987
|
-
|
|
2002
|
+
getSubAgent(name) {
|
|
1988
2003
|
return this.agentMap.get(name);
|
|
1989
2004
|
}
|
|
1990
2005
|
/**
|
|
1991
|
-
* Add an agent to the
|
|
2006
|
+
* Add an agent to the agent
|
|
1992
2007
|
*/
|
|
1993
|
-
addSubAgent(
|
|
1994
|
-
this.subAgents.push(
|
|
1995
|
-
this.agentMap.set(
|
|
1996
|
-
if (this.models && this.isInternalAgent(
|
|
1997
|
-
this.propagateModelSettingsToAgent(
|
|
2008
|
+
addSubAgent(agent2) {
|
|
2009
|
+
this.subAgents.push(agent2);
|
|
2010
|
+
this.agentMap.set(agent2.getId(), agent2);
|
|
2011
|
+
if (this.models && this.isInternalAgent(agent2)) {
|
|
2012
|
+
this.propagateModelSettingsToAgent(agent2);
|
|
1998
2013
|
}
|
|
1999
2014
|
logger8.info(
|
|
2000
2015
|
{
|
|
2001
|
-
|
|
2002
|
-
subAgentId:
|
|
2003
|
-
agentType: this.isInternalAgent(
|
|
2016
|
+
agentId: this.agentId,
|
|
2017
|
+
subAgentId: agent2.getId(),
|
|
2018
|
+
agentType: this.isInternalAgent(agent2) ? "internal" : "external"
|
|
2004
2019
|
},
|
|
2005
|
-
"Agent added to
|
|
2020
|
+
"Agent added to agent"
|
|
2006
2021
|
);
|
|
2007
2022
|
}
|
|
2008
2023
|
/**
|
|
2009
|
-
* Remove an agent from the
|
|
2024
|
+
* Remove an agent from the agent
|
|
2010
2025
|
*/
|
|
2011
2026
|
removeSubAgent(id) {
|
|
2012
2027
|
const agentToRemove = this.agentMap.get(id);
|
|
2013
2028
|
if (agentToRemove) {
|
|
2014
2029
|
this.agentMap.delete(agentToRemove.getId());
|
|
2015
|
-
this.subAgents = this.subAgents.filter((
|
|
2030
|
+
this.subAgents = this.subAgents.filter((agent2) => agent2.getId() !== agentToRemove.getId());
|
|
2016
2031
|
logger8.info(
|
|
2017
2032
|
{
|
|
2018
|
-
|
|
2033
|
+
agentId: this.agentId,
|
|
2019
2034
|
subAgentId: agentToRemove.getId()
|
|
2020
2035
|
},
|
|
2021
|
-
"Agent removed from
|
|
2036
|
+
"Agent removed from agent"
|
|
2022
2037
|
);
|
|
2023
2038
|
return true;
|
|
2024
2039
|
}
|
|
2025
2040
|
return false;
|
|
2026
2041
|
}
|
|
2027
2042
|
/**
|
|
2028
|
-
* Get all agents in the
|
|
2043
|
+
* Get all agents in the agent
|
|
2029
2044
|
*/
|
|
2030
2045
|
getSubAgents() {
|
|
2031
2046
|
return this.subAgents;
|
|
@@ -2039,13 +2054,13 @@ var AgentGraph = class {
|
|
|
2039
2054
|
/**
|
|
2040
2055
|
* Set the default agent
|
|
2041
2056
|
*/
|
|
2042
|
-
|
|
2043
|
-
this.defaultSubAgent =
|
|
2044
|
-
this.addSubAgent(
|
|
2057
|
+
setDefaultSubAgent(agent2) {
|
|
2058
|
+
this.defaultSubAgent = agent2;
|
|
2059
|
+
this.addSubAgent(agent2);
|
|
2045
2060
|
logger8.info(
|
|
2046
2061
|
{
|
|
2047
|
-
|
|
2048
|
-
defaultSubAgent:
|
|
2062
|
+
agentId: this.agentId,
|
|
2063
|
+
defaultSubAgent: agent2.getId()
|
|
2049
2064
|
},
|
|
2050
2065
|
"Default agent updated"
|
|
2051
2066
|
);
|
|
@@ -2053,106 +2068,106 @@ var AgentGraph = class {
|
|
|
2053
2068
|
/**
|
|
2054
2069
|
* Get the default agent
|
|
2055
2070
|
*/
|
|
2056
|
-
|
|
2071
|
+
getDefaultSubAgent() {
|
|
2057
2072
|
return this.defaultSubAgent;
|
|
2058
2073
|
}
|
|
2059
2074
|
/**
|
|
2060
|
-
* Get the
|
|
2075
|
+
* Get the agent ID
|
|
2061
2076
|
*/
|
|
2062
2077
|
getId() {
|
|
2063
|
-
return this.
|
|
2078
|
+
return this.agentId;
|
|
2064
2079
|
}
|
|
2065
2080
|
getName() {
|
|
2066
|
-
return this.
|
|
2081
|
+
return this.agentName;
|
|
2067
2082
|
}
|
|
2068
2083
|
getDescription() {
|
|
2069
|
-
return this.
|
|
2084
|
+
return this.agentDescription;
|
|
2070
2085
|
}
|
|
2071
2086
|
getTenantId() {
|
|
2072
2087
|
return this.tenantId;
|
|
2073
2088
|
}
|
|
2074
2089
|
/**
|
|
2075
|
-
* Get the
|
|
2090
|
+
* Get the agent's model settingsuration
|
|
2076
2091
|
*/
|
|
2077
2092
|
getModels() {
|
|
2078
2093
|
return this.models;
|
|
2079
2094
|
}
|
|
2080
2095
|
/**
|
|
2081
|
-
* Set the
|
|
2096
|
+
* Set the agent's model settingsuration
|
|
2082
2097
|
*/
|
|
2083
2098
|
setModels(models) {
|
|
2084
2099
|
this.models = models;
|
|
2085
2100
|
}
|
|
2086
2101
|
/**
|
|
2087
|
-
* Get the
|
|
2102
|
+
* Get the agent's prompt configuration
|
|
2088
2103
|
*/
|
|
2089
|
-
|
|
2090
|
-
return this.
|
|
2104
|
+
getAgentPrompt() {
|
|
2105
|
+
return this.agentPrompt;
|
|
2091
2106
|
}
|
|
2092
2107
|
/**
|
|
2093
|
-
* Get the
|
|
2108
|
+
* Get the agent's stopWhen configuration
|
|
2094
2109
|
*/
|
|
2095
2110
|
getStopWhen() {
|
|
2096
2111
|
return this.stopWhen || { transferCountIs: 10 };
|
|
2097
2112
|
}
|
|
2098
2113
|
/**
|
|
2099
|
-
* Get the
|
|
2114
|
+
* Get the agent's status updates configuration
|
|
2100
2115
|
*/
|
|
2101
2116
|
getStatusUpdateSettings() {
|
|
2102
2117
|
return this.statusUpdateSettings;
|
|
2103
2118
|
}
|
|
2104
2119
|
/**
|
|
2105
|
-
* Get the summarizer model from the
|
|
2120
|
+
* Get the summarizer model from the agent's model settings
|
|
2106
2121
|
*/
|
|
2107
2122
|
getSummarizerModel() {
|
|
2108
2123
|
return this.models?.summarizer;
|
|
2109
2124
|
}
|
|
2110
2125
|
/**
|
|
2111
|
-
* Get
|
|
2126
|
+
* Get agent statistics
|
|
2112
2127
|
*/
|
|
2113
2128
|
getStats() {
|
|
2114
2129
|
return {
|
|
2115
2130
|
agentCount: this.subAgents.length,
|
|
2116
2131
|
defaultSubAgent: this.defaultSubAgent?.getName() || null,
|
|
2117
2132
|
initialized: this.initialized,
|
|
2118
|
-
|
|
2133
|
+
agentId: this.agentId,
|
|
2119
2134
|
tenantId: this.tenantId
|
|
2120
2135
|
};
|
|
2121
2136
|
}
|
|
2122
2137
|
/**
|
|
2123
|
-
* Validate the
|
|
2138
|
+
* Validate the agent configuration
|
|
2124
2139
|
*/
|
|
2125
2140
|
validate() {
|
|
2126
2141
|
const errors = [];
|
|
2127
2142
|
if (this.subAgents.length === 0) {
|
|
2128
|
-
errors.push("
|
|
2143
|
+
errors.push("Agent must contain at least one agent");
|
|
2129
2144
|
}
|
|
2130
2145
|
if (!this.defaultSubAgent) {
|
|
2131
|
-
errors.push("
|
|
2146
|
+
errors.push("Agent must have a default agent");
|
|
2132
2147
|
}
|
|
2133
2148
|
const names = /* @__PURE__ */ new Set();
|
|
2134
|
-
for (const
|
|
2135
|
-
const name =
|
|
2149
|
+
for (const agent2 of this.subAgents) {
|
|
2150
|
+
const name = agent2.getName();
|
|
2136
2151
|
if (names.has(name)) {
|
|
2137
2152
|
errors.push(`Duplicate agent name: ${name}`);
|
|
2138
2153
|
}
|
|
2139
2154
|
names.add(name);
|
|
2140
2155
|
}
|
|
2141
|
-
for (const
|
|
2142
|
-
if (!this.isInternalAgent(
|
|
2143
|
-
const transfers =
|
|
2156
|
+
for (const agent2 of this.subAgents) {
|
|
2157
|
+
if (!this.isInternalAgent(agent2)) continue;
|
|
2158
|
+
const transfers = agent2.getTransfers();
|
|
2144
2159
|
for (const transferAgent of transfers) {
|
|
2145
2160
|
if (!this.agentMap.has(transferAgent.getName())) {
|
|
2146
2161
|
errors.push(
|
|
2147
|
-
`Agent '${
|
|
2162
|
+
`Agent '${agent2.getName()}' has transfer to '${transferAgent.getName()}' which is not in the agent`
|
|
2148
2163
|
);
|
|
2149
2164
|
}
|
|
2150
2165
|
}
|
|
2151
|
-
const delegates =
|
|
2166
|
+
const delegates = agent2.getDelegates();
|
|
2152
2167
|
for (const delegateAgent of delegates) {
|
|
2153
2168
|
if (!this.agentMap.has(delegateAgent.getName())) {
|
|
2154
2169
|
errors.push(
|
|
2155
|
-
`Agent '${
|
|
2170
|
+
`Agent '${agent2.getName()}' has delegation to '${delegateAgent.getName()}' which is not in the agent`
|
|
2156
2171
|
);
|
|
2157
2172
|
}
|
|
2158
2173
|
}
|
|
@@ -2171,8 +2186,8 @@ var AgentGraph = class {
|
|
|
2171
2186
|
/**
|
|
2172
2187
|
* Type guard to check if an agent is an internal AgentInterface
|
|
2173
2188
|
*/
|
|
2174
|
-
isInternalAgent(
|
|
2175
|
-
return "getTransfers" in
|
|
2189
|
+
isInternalAgent(agent2) {
|
|
2190
|
+
return "getTransfers" in agent2 && typeof agent2.getTransfers === "function";
|
|
2176
2191
|
}
|
|
2177
2192
|
/**
|
|
2178
2193
|
* Get project-level model settingsuration defaults
|
|
@@ -2217,7 +2232,7 @@ var AgentGraph = class {
|
|
|
2217
2232
|
}
|
|
2218
2233
|
}
|
|
2219
2234
|
/**
|
|
2220
|
-
* Apply model inheritance hierarchy: Project ->
|
|
2235
|
+
* Apply model inheritance hierarchy: Project -> Agent -> Agent
|
|
2221
2236
|
*/
|
|
2222
2237
|
async applyModelInheritance() {
|
|
2223
2238
|
const projectModels = await this.getProjectModelDefaults();
|
|
@@ -2236,14 +2251,14 @@ var AgentGraph = class {
|
|
|
2236
2251
|
}
|
|
2237
2252
|
}
|
|
2238
2253
|
await this.applyStopWhenInheritance();
|
|
2239
|
-
for (const
|
|
2240
|
-
if (this.isInternalAgent(
|
|
2241
|
-
this.propagateModelSettingsToAgent(
|
|
2254
|
+
for (const agent2 of this.subAgents) {
|
|
2255
|
+
if (this.isInternalAgent(agent2)) {
|
|
2256
|
+
this.propagateModelSettingsToAgent(agent2);
|
|
2242
2257
|
}
|
|
2243
2258
|
}
|
|
2244
2259
|
}
|
|
2245
2260
|
/**
|
|
2246
|
-
* Apply stopWhen inheritance hierarchy: Project ->
|
|
2261
|
+
* Apply stopWhen inheritance hierarchy: Project -> Agent -> Agent
|
|
2247
2262
|
*/
|
|
2248
2263
|
async applyStopWhenInheritance() {
|
|
2249
2264
|
const projectStopWhen = await this.getProjectStopWhenDefaults();
|
|
@@ -2257,9 +2272,9 @@ var AgentGraph = class {
|
|
|
2257
2272
|
this.stopWhen.transferCountIs = 10;
|
|
2258
2273
|
}
|
|
2259
2274
|
if (projectStopWhen?.stepCountIs !== void 0) {
|
|
2260
|
-
for (const
|
|
2261
|
-
if (this.isInternalAgent(
|
|
2262
|
-
const internalAgent =
|
|
2275
|
+
for (const agent2 of this.subAgents) {
|
|
2276
|
+
if (this.isInternalAgent(agent2)) {
|
|
2277
|
+
const internalAgent = agent2;
|
|
2263
2278
|
if (!internalAgent.config.stopWhen) {
|
|
2264
2279
|
internalAgent.config.stopWhen = {};
|
|
2265
2280
|
}
|
|
@@ -2271,54 +2286,54 @@ var AgentGraph = class {
|
|
|
2271
2286
|
}
|
|
2272
2287
|
logger8.debug(
|
|
2273
2288
|
{
|
|
2274
|
-
|
|
2275
|
-
|
|
2289
|
+
agentId: this.agentId,
|
|
2290
|
+
agentStopWhen: this.stopWhen,
|
|
2276
2291
|
projectStopWhen
|
|
2277
2292
|
},
|
|
2278
|
-
"Applied stopWhen inheritance from project to
|
|
2293
|
+
"Applied stopWhen inheritance from project to agent"
|
|
2279
2294
|
);
|
|
2280
2295
|
}
|
|
2281
2296
|
/**
|
|
2282
|
-
* Propagate
|
|
2297
|
+
* Propagate agent-level model settings to agents (supporting partial inheritance)
|
|
2283
2298
|
*/
|
|
2284
|
-
propagateModelSettingsToAgent(
|
|
2299
|
+
propagateModelSettingsToAgent(agent2) {
|
|
2285
2300
|
if (this.models) {
|
|
2286
|
-
if (!
|
|
2287
|
-
|
|
2301
|
+
if (!agent2.config.models) {
|
|
2302
|
+
agent2.config.models = {};
|
|
2288
2303
|
}
|
|
2289
|
-
if (!
|
|
2290
|
-
|
|
2304
|
+
if (!agent2.config.models.base && this.models.base) {
|
|
2305
|
+
agent2.config.models.base = this.models.base;
|
|
2291
2306
|
}
|
|
2292
|
-
if (!
|
|
2293
|
-
|
|
2307
|
+
if (!agent2.config.models.structuredOutput && this.models.structuredOutput) {
|
|
2308
|
+
agent2.config.models.structuredOutput = this.models.structuredOutput;
|
|
2294
2309
|
}
|
|
2295
|
-
if (!
|
|
2296
|
-
|
|
2310
|
+
if (!agent2.config.models.summarizer && this.models.summarizer) {
|
|
2311
|
+
agent2.config.models.summarizer = this.models.summarizer;
|
|
2297
2312
|
}
|
|
2298
2313
|
}
|
|
2299
2314
|
}
|
|
2300
2315
|
/**
|
|
2301
|
-
* Immediately propagate
|
|
2316
|
+
* Immediately propagate agent-level models to all agents during construction
|
|
2302
2317
|
*/
|
|
2303
2318
|
propagateImmediateModelSettings() {
|
|
2304
|
-
for (const
|
|
2305
|
-
if (this.isInternalAgent(
|
|
2306
|
-
this.propagateModelSettingsToAgent(
|
|
2319
|
+
for (const agent2 of this.subAgents) {
|
|
2320
|
+
if (this.isInternalAgent(agent2)) {
|
|
2321
|
+
this.propagateModelSettingsToAgent(agent2);
|
|
2307
2322
|
}
|
|
2308
2323
|
}
|
|
2309
2324
|
}
|
|
2310
2325
|
/**
|
|
2311
2326
|
* Type guard to check if an agent is an external AgentInterface
|
|
2312
2327
|
*/
|
|
2313
|
-
isExternalAgent(
|
|
2314
|
-
return !this.isInternalAgent(
|
|
2328
|
+
isExternalAgent(agent2) {
|
|
2329
|
+
return !this.isInternalAgent(agent2);
|
|
2315
2330
|
}
|
|
2316
2331
|
/**
|
|
2317
2332
|
* Execute agent using the backend system instead of local runner
|
|
2318
2333
|
*/
|
|
2319
2334
|
async executeWithBackend(input, options) {
|
|
2320
2335
|
const normalizedMessages = this.normalizeMessages(input);
|
|
2321
|
-
const url = `${this.baseURL}/tenants/${this.tenantId}/
|
|
2336
|
+
const url = `${this.baseURL}/tenants/${this.tenantId}/agent/${this.agentId}/v1/chat/completions`;
|
|
2322
2337
|
logger8.info({ url }, "Executing with backend");
|
|
2323
2338
|
const requestBody = {
|
|
2324
2339
|
model: "gpt-4o-mini",
|
|
@@ -2355,7 +2370,7 @@ var AgentGraph = class {
|
|
|
2355
2370
|
const data = JSON.parse(responseText);
|
|
2356
2371
|
return data.result || data.choices?.[0]?.message?.content || "";
|
|
2357
2372
|
} catch (error) {
|
|
2358
|
-
throw new Error(`
|
|
2373
|
+
throw new Error(`Agent execution failed: ${error.message || "Unknown error"}`);
|
|
2359
2374
|
}
|
|
2360
2375
|
}
|
|
2361
2376
|
/**
|
|
@@ -2394,7 +2409,7 @@ var AgentGraph = class {
|
|
|
2394
2409
|
}
|
|
2395
2410
|
async saveToDatabase() {
|
|
2396
2411
|
try {
|
|
2397
|
-
const getUrl = `${this.baseURL}/tenants/${this.tenantId}/
|
|
2412
|
+
const getUrl = `${this.baseURL}/tenants/${this.tenantId}/agents/${this.agentId}`;
|
|
2398
2413
|
try {
|
|
2399
2414
|
const getResponse = await fetch(getUrl, {
|
|
2400
2415
|
method: "GET",
|
|
@@ -2403,7 +2418,7 @@ var AgentGraph = class {
|
|
|
2403
2418
|
}
|
|
2404
2419
|
});
|
|
2405
2420
|
if (getResponse.ok) {
|
|
2406
|
-
logger8.info({
|
|
2421
|
+
logger8.info({ agentId: this.agentId }, "Agent already exists in backend");
|
|
2407
2422
|
return;
|
|
2408
2423
|
}
|
|
2409
2424
|
if (getResponse.status !== 404) {
|
|
@@ -2414,16 +2429,16 @@ var AgentGraph = class {
|
|
|
2414
2429
|
throw error;
|
|
2415
2430
|
}
|
|
2416
2431
|
}
|
|
2417
|
-
logger8.info({
|
|
2418
|
-
const createUrl = `${this.baseURL}/tenants/${this.tenantId}/
|
|
2432
|
+
logger8.info({ agentId: this.agentId }, "Creating agent in backend");
|
|
2433
|
+
const createUrl = `${this.baseURL}/tenants/${this.tenantId}/agents`;
|
|
2419
2434
|
const createResponse = await fetch(createUrl, {
|
|
2420
2435
|
method: "POST",
|
|
2421
2436
|
headers: {
|
|
2422
2437
|
"Content-Type": "application/json"
|
|
2423
2438
|
},
|
|
2424
2439
|
body: JSON.stringify({
|
|
2425
|
-
id: this.
|
|
2426
|
-
name: this.
|
|
2440
|
+
id: this.agentId,
|
|
2441
|
+
name: this.agentName,
|
|
2427
2442
|
defaultSubAgentId: this.defaultSubAgent?.getId() || "",
|
|
2428
2443
|
contextConfigId: this.contextConfig?.getId(),
|
|
2429
2444
|
models: this.models
|
|
@@ -2433,25 +2448,25 @@ var AgentGraph = class {
|
|
|
2433
2448
|
throw new Error(`HTTP ${createResponse.status}: ${createResponse.statusText}`);
|
|
2434
2449
|
}
|
|
2435
2450
|
const createData = await createResponse.json();
|
|
2436
|
-
this.
|
|
2437
|
-
logger8.info({
|
|
2451
|
+
this.agentId = createData.data.id;
|
|
2452
|
+
logger8.info({ agent: createData.data }, "Agent created in backend");
|
|
2438
2453
|
} catch (error) {
|
|
2439
2454
|
throw new Error(
|
|
2440
|
-
`Failed to save
|
|
2455
|
+
`Failed to save agent to database: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2441
2456
|
);
|
|
2442
2457
|
}
|
|
2443
2458
|
}
|
|
2444
2459
|
async saveRelations() {
|
|
2445
2460
|
if (this.defaultSubAgent) {
|
|
2446
2461
|
try {
|
|
2447
|
-
const updateUrl = `${this.baseURL}/tenants/${this.tenantId}/
|
|
2462
|
+
const updateUrl = `${this.baseURL}/tenants/${this.tenantId}/agents/${this.agentId}`;
|
|
2448
2463
|
const updateResponse = await fetch(updateUrl, {
|
|
2449
2464
|
method: "PUT",
|
|
2450
2465
|
headers: {
|
|
2451
2466
|
"Content-Type": "application/json"
|
|
2452
2467
|
},
|
|
2453
2468
|
body: JSON.stringify({
|
|
2454
|
-
id: this.
|
|
2469
|
+
id: this.agentId,
|
|
2455
2470
|
defaultSubAgentId: this.defaultSubAgent.getId(),
|
|
2456
2471
|
contextConfigId: this.contextConfig?.getId()
|
|
2457
2472
|
})
|
|
@@ -2461,18 +2476,18 @@ var AgentGraph = class {
|
|
|
2461
2476
|
}
|
|
2462
2477
|
logger8.debug(
|
|
2463
2478
|
{
|
|
2464
|
-
|
|
2479
|
+
agentId: this.agentId,
|
|
2465
2480
|
defaultSubAgent: this.defaultSubAgent.getName()
|
|
2466
2481
|
},
|
|
2467
|
-
"
|
|
2482
|
+
"Agent relationships configured"
|
|
2468
2483
|
);
|
|
2469
2484
|
} catch (error) {
|
|
2470
2485
|
logger8.error(
|
|
2471
2486
|
{
|
|
2472
|
-
|
|
2487
|
+
agentId: this.agentId,
|
|
2473
2488
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2474
2489
|
},
|
|
2475
|
-
"Failed to update
|
|
2490
|
+
"Failed to update agent relationships"
|
|
2476
2491
|
);
|
|
2477
2492
|
throw error;
|
|
2478
2493
|
}
|
|
@@ -2480,21 +2495,21 @@ var AgentGraph = class {
|
|
|
2480
2495
|
}
|
|
2481
2496
|
async createAgentRelations() {
|
|
2482
2497
|
const allRelationPromises = [];
|
|
2483
|
-
for (const
|
|
2484
|
-
if (this.isInternalAgent(
|
|
2485
|
-
const transfers =
|
|
2498
|
+
for (const agent2 of this.subAgents) {
|
|
2499
|
+
if (this.isInternalAgent(agent2)) {
|
|
2500
|
+
const transfers = agent2.getTransfers();
|
|
2486
2501
|
for (const transferAgent of transfers) {
|
|
2487
2502
|
allRelationPromises.push(
|
|
2488
|
-
this.createInternalAgentRelation(
|
|
2503
|
+
this.createInternalAgentRelation(agent2, transferAgent, "transfer")
|
|
2489
2504
|
);
|
|
2490
2505
|
}
|
|
2491
|
-
const delegates =
|
|
2506
|
+
const delegates = agent2.getDelegates();
|
|
2492
2507
|
for (const delegate of delegates) {
|
|
2493
2508
|
if (delegate.type === "external") {
|
|
2494
|
-
allRelationPromises.push(this.createExternalAgentRelation(
|
|
2509
|
+
allRelationPromises.push(this.createExternalAgentRelation(agent2, delegate, "delegate"));
|
|
2495
2510
|
} else {
|
|
2496
2511
|
allRelationPromises.push(
|
|
2497
|
-
this.createInternalAgentRelation(
|
|
2512
|
+
this.createInternalAgentRelation(agent2, delegate, "delegate")
|
|
2498
2513
|
);
|
|
2499
2514
|
}
|
|
2500
2515
|
}
|
|
@@ -2511,7 +2526,7 @@ var AgentGraph = class {
|
|
|
2511
2526
|
logger8.error(
|
|
2512
2527
|
{
|
|
2513
2528
|
error: result.reason instanceof Error ? result.reason.message : "Unknown error",
|
|
2514
|
-
|
|
2529
|
+
agentId: this.agentId
|
|
2515
2530
|
},
|
|
2516
2531
|
"Failed to create agent relation"
|
|
2517
2532
|
);
|
|
@@ -2519,7 +2534,7 @@ var AgentGraph = class {
|
|
|
2519
2534
|
}
|
|
2520
2535
|
logger8.info(
|
|
2521
2536
|
{
|
|
2522
|
-
|
|
2537
|
+
agentId: this.agentId,
|
|
2523
2538
|
totalRelations: allRelationPromises.length,
|
|
2524
2539
|
successCount,
|
|
2525
2540
|
errorCount: errors.length
|
|
@@ -2538,7 +2553,7 @@ var AgentGraph = class {
|
|
|
2538
2553
|
"Content-Type": "application/json"
|
|
2539
2554
|
},
|
|
2540
2555
|
body: JSON.stringify({
|
|
2541
|
-
|
|
2556
|
+
agentId: this.agentId,
|
|
2542
2557
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2543
2558
|
targetSubAgentId: targetAgent.getId(),
|
|
2544
2559
|
relationType
|
|
@@ -2551,7 +2566,7 @@ var AgentGraph = class {
|
|
|
2551
2566
|
{
|
|
2552
2567
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2553
2568
|
targetSubAgentId: targetAgent.getId(),
|
|
2554
|
-
|
|
2569
|
+
agentId: this.agentId,
|
|
2555
2570
|
relationType
|
|
2556
2571
|
},
|
|
2557
2572
|
`${relationType} relation already exists, skipping creation`
|
|
@@ -2564,7 +2579,7 @@ var AgentGraph = class {
|
|
|
2564
2579
|
{
|
|
2565
2580
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2566
2581
|
targetSubAgentId: targetAgent.getId(),
|
|
2567
|
-
|
|
2582
|
+
agentId: this.agentId,
|
|
2568
2583
|
relationType
|
|
2569
2584
|
},
|
|
2570
2585
|
`${relationType} relation created successfully`
|
|
@@ -2574,7 +2589,7 @@ var AgentGraph = class {
|
|
|
2574
2589
|
{
|
|
2575
2590
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2576
2591
|
targetSubAgentId: targetAgent.getId(),
|
|
2577
|
-
|
|
2592
|
+
agentId: this.agentId,
|
|
2578
2593
|
relationType,
|
|
2579
2594
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2580
2595
|
},
|
|
@@ -2591,7 +2606,7 @@ var AgentGraph = class {
|
|
|
2591
2606
|
"Content-Type": "application/json"
|
|
2592
2607
|
},
|
|
2593
2608
|
body: JSON.stringify({
|
|
2594
|
-
|
|
2609
|
+
agentId: this.agentId,
|
|
2595
2610
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2596
2611
|
externalSubAgentId: externalAgent2.getId(),
|
|
2597
2612
|
relationType
|
|
@@ -2604,7 +2619,7 @@ var AgentGraph = class {
|
|
|
2604
2619
|
{
|
|
2605
2620
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2606
2621
|
externalSubAgentId: externalAgent2.getId(),
|
|
2607
|
-
|
|
2622
|
+
agentId: this.agentId,
|
|
2608
2623
|
relationType
|
|
2609
2624
|
},
|
|
2610
2625
|
`${relationType} relation already exists, skipping creation`
|
|
@@ -2619,7 +2634,7 @@ var AgentGraph = class {
|
|
|
2619
2634
|
{
|
|
2620
2635
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2621
2636
|
externalSubAgentId: externalAgent2.getId(),
|
|
2622
|
-
|
|
2637
|
+
agentId: this.agentId,
|
|
2623
2638
|
relationType
|
|
2624
2639
|
},
|
|
2625
2640
|
`${relationType} relation created successfully`
|
|
@@ -2629,7 +2644,7 @@ var AgentGraph = class {
|
|
|
2629
2644
|
{
|
|
2630
2645
|
sourceSubAgentId: sourceAgent.getId(),
|
|
2631
2646
|
externalSubAgentId: externalAgent2.getId(),
|
|
2632
|
-
|
|
2647
|
+
agentId: this.agentId,
|
|
2633
2648
|
relationType,
|
|
2634
2649
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2635
2650
|
},
|
|
@@ -2642,10 +2657,10 @@ var AgentGraph = class {
|
|
|
2642
2657
|
* Create external agents in the database
|
|
2643
2658
|
*/
|
|
2644
2659
|
async createExternalAgents() {
|
|
2645
|
-
const externalAgents2 = this.subAgents.filter((
|
|
2660
|
+
const externalAgents2 = this.subAgents.filter((agent2) => this.isExternalAgent(agent2));
|
|
2646
2661
|
logger8.info(
|
|
2647
2662
|
{
|
|
2648
|
-
|
|
2663
|
+
agentId: this.agentId,
|
|
2649
2664
|
externalAgentCount: externalAgents2.length
|
|
2650
2665
|
},
|
|
2651
2666
|
"Creating external agents in database"
|
|
@@ -2656,7 +2671,7 @@ var AgentGraph = class {
|
|
|
2656
2671
|
logger8.debug(
|
|
2657
2672
|
{
|
|
2658
2673
|
externalSubAgentId: externalAgent2.getId(),
|
|
2659
|
-
|
|
2674
|
+
agentId: this.agentId
|
|
2660
2675
|
},
|
|
2661
2676
|
"External agent created in database"
|
|
2662
2677
|
);
|
|
@@ -2664,7 +2679,7 @@ var AgentGraph = class {
|
|
|
2664
2679
|
logger8.error(
|
|
2665
2680
|
{
|
|
2666
2681
|
externalSubAgentId: externalAgent2.getId(),
|
|
2667
|
-
|
|
2682
|
+
agentId: this.agentId,
|
|
2668
2683
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2669
2684
|
},
|
|
2670
2685
|
"Failed to create external agent in database"
|
|
@@ -2676,7 +2691,7 @@ var AgentGraph = class {
|
|
|
2676
2691
|
await Promise.all(initPromises);
|
|
2677
2692
|
logger8.info(
|
|
2678
2693
|
{
|
|
2679
|
-
|
|
2694
|
+
agentId: this.agentId,
|
|
2680
2695
|
externalAgentCount: externalAgents2.length
|
|
2681
2696
|
},
|
|
2682
2697
|
"All external agents created successfully"
|
|
@@ -2684,7 +2699,7 @@ var AgentGraph = class {
|
|
|
2684
2699
|
} catch (error) {
|
|
2685
2700
|
logger8.error(
|
|
2686
2701
|
{
|
|
2687
|
-
|
|
2702
|
+
agentId: this.agentId,
|
|
2688
2703
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2689
2704
|
},
|
|
2690
2705
|
"Failed to create some external agents"
|
|
@@ -2943,8 +2958,8 @@ var Project = class {
|
|
|
2943
2958
|
__publicField(this, "models");
|
|
2944
2959
|
__publicField(this, "stopWhen");
|
|
2945
2960
|
__publicField(this, "sandboxConfig");
|
|
2946
|
-
__publicField(this, "
|
|
2947
|
-
__publicField(this, "
|
|
2961
|
+
__publicField(this, "agents", []);
|
|
2962
|
+
__publicField(this, "agentMap", /* @__PURE__ */ new Map());
|
|
2948
2963
|
__publicField(this, "credentialReferences", []);
|
|
2949
2964
|
__publicField(this, "projectTools", []);
|
|
2950
2965
|
__publicField(this, "projectDataComponents", []);
|
|
@@ -2957,11 +2972,11 @@ var Project = class {
|
|
|
2957
2972
|
this.models = config.models;
|
|
2958
2973
|
this.stopWhen = config.stopWhen;
|
|
2959
2974
|
this.sandboxConfig = config.sandboxConfig;
|
|
2960
|
-
if (config.
|
|
2961
|
-
this.
|
|
2962
|
-
this.
|
|
2963
|
-
for (const
|
|
2964
|
-
|
|
2975
|
+
if (config.agents) {
|
|
2976
|
+
this.agents = config.agents();
|
|
2977
|
+
this.agentMap = new Map(this.agents.map((agent2) => [agent2.getId(), agent2]));
|
|
2978
|
+
for (const agent2 of this.agents) {
|
|
2979
|
+
agent2.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
2965
2980
|
}
|
|
2966
2981
|
}
|
|
2967
2982
|
if (config.tools) {
|
|
@@ -2980,7 +2995,7 @@ var Project = class {
|
|
|
2980
2995
|
{
|
|
2981
2996
|
projectId: this.projectId,
|
|
2982
2997
|
tenantId: this.tenantId,
|
|
2983
|
-
|
|
2998
|
+
agentCount: this.agents.length
|
|
2984
2999
|
},
|
|
2985
3000
|
"Project created"
|
|
2986
3001
|
);
|
|
@@ -2999,8 +3014,8 @@ var Project = class {
|
|
|
2999
3014
|
if (models) {
|
|
3000
3015
|
this.models = models;
|
|
3001
3016
|
}
|
|
3002
|
-
for (const
|
|
3003
|
-
|
|
3017
|
+
for (const agent2 of this.agents) {
|
|
3018
|
+
agent2.setConfig(tenantId, this.projectId, apiUrl);
|
|
3004
3019
|
}
|
|
3005
3020
|
logger10.info(
|
|
3006
3021
|
{
|
|
@@ -3039,7 +3054,7 @@ var Project = class {
|
|
|
3039
3054
|
{
|
|
3040
3055
|
projectId: this.projectId,
|
|
3041
3056
|
tenantId: this.tenantId,
|
|
3042
|
-
|
|
3057
|
+
agentCount: this.agents.length
|
|
3043
3058
|
},
|
|
3044
3059
|
"Initializing project using full project endpoint"
|
|
3045
3060
|
);
|
|
@@ -3065,7 +3080,7 @@ var Project = class {
|
|
|
3065
3080
|
{
|
|
3066
3081
|
projectId: this.projectId,
|
|
3067
3082
|
tenantId: this.tenantId,
|
|
3068
|
-
|
|
3083
|
+
agentCount: Object.keys(createdProject.agent || {}).length
|
|
3069
3084
|
},
|
|
3070
3085
|
"Project initialized successfully using full project endpoint"
|
|
3071
3086
|
);
|
|
@@ -3142,47 +3157,50 @@ var Project = class {
|
|
|
3142
3157
|
}
|
|
3143
3158
|
return { credentials, usage };
|
|
3144
3159
|
}
|
|
3160
|
+
async getFullDefinition() {
|
|
3161
|
+
return await this.toFullProjectDefinition();
|
|
3162
|
+
}
|
|
3145
3163
|
/**
|
|
3146
|
-
* Get all
|
|
3164
|
+
* Get all agent in the project
|
|
3147
3165
|
*/
|
|
3148
|
-
|
|
3149
|
-
return this.
|
|
3166
|
+
getAgents() {
|
|
3167
|
+
return this.agents;
|
|
3150
3168
|
}
|
|
3151
3169
|
/**
|
|
3152
|
-
* Get
|
|
3170
|
+
* Get an agent by ID
|
|
3153
3171
|
*/
|
|
3154
|
-
|
|
3155
|
-
return this.
|
|
3172
|
+
getAgent(id) {
|
|
3173
|
+
return this.agentMap.get(id);
|
|
3156
3174
|
}
|
|
3157
3175
|
/**
|
|
3158
|
-
* Add
|
|
3176
|
+
* Add an agent to the project
|
|
3159
3177
|
*/
|
|
3160
|
-
|
|
3161
|
-
this.
|
|
3162
|
-
this.
|
|
3163
|
-
|
|
3178
|
+
addAgent(agent2) {
|
|
3179
|
+
this.agents.push(agent2);
|
|
3180
|
+
this.agentMap.set(agent2.getId(), agent2);
|
|
3181
|
+
agent2.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
3164
3182
|
logger10.info(
|
|
3165
3183
|
{
|
|
3166
3184
|
projectId: this.projectId,
|
|
3167
|
-
|
|
3185
|
+
agentId: agent2.getId()
|
|
3168
3186
|
},
|
|
3169
|
-
"
|
|
3187
|
+
"Agent added to project"
|
|
3170
3188
|
);
|
|
3171
3189
|
}
|
|
3172
3190
|
/**
|
|
3173
|
-
* Remove
|
|
3191
|
+
* Remove an agent from the project
|
|
3174
3192
|
*/
|
|
3175
|
-
|
|
3176
|
-
const
|
|
3177
|
-
if (
|
|
3178
|
-
this.
|
|
3179
|
-
this.
|
|
3193
|
+
removeAgent(id) {
|
|
3194
|
+
const agentToRemove = this.agentMap.get(id);
|
|
3195
|
+
if (agentToRemove) {
|
|
3196
|
+
this.agentMap.delete(id);
|
|
3197
|
+
this.agents = this.agents.filter((agent2) => agent2.getId() !== id);
|
|
3180
3198
|
logger10.info(
|
|
3181
3199
|
{
|
|
3182
3200
|
projectId: this.projectId,
|
|
3183
|
-
|
|
3201
|
+
agentId: id
|
|
3184
3202
|
},
|
|
3185
|
-
"
|
|
3203
|
+
"Agent removed from project"
|
|
3186
3204
|
);
|
|
3187
3205
|
return true;
|
|
3188
3206
|
}
|
|
@@ -3195,7 +3213,7 @@ var Project = class {
|
|
|
3195
3213
|
return {
|
|
3196
3214
|
projectId: this.projectId,
|
|
3197
3215
|
tenantId: this.tenantId,
|
|
3198
|
-
|
|
3216
|
+
agentCount: this.agents.length,
|
|
3199
3217
|
initialized: this.initialized
|
|
3200
3218
|
};
|
|
3201
3219
|
}
|
|
@@ -3210,18 +3228,18 @@ var Project = class {
|
|
|
3210
3228
|
if (!this.projectName) {
|
|
3211
3229
|
errors.push("Project must have a name");
|
|
3212
3230
|
}
|
|
3213
|
-
const
|
|
3214
|
-
for (const
|
|
3215
|
-
const id =
|
|
3216
|
-
if (
|
|
3217
|
-
errors.push(`Duplicate
|
|
3231
|
+
const agentIds = /* @__PURE__ */ new Set();
|
|
3232
|
+
for (const agent2 of this.agents) {
|
|
3233
|
+
const id = agent2.getId();
|
|
3234
|
+
if (agentIds.has(id)) {
|
|
3235
|
+
errors.push(`Duplicate agent ID: ${id}`);
|
|
3218
3236
|
}
|
|
3219
|
-
|
|
3237
|
+
agentIds.add(id);
|
|
3220
3238
|
}
|
|
3221
|
-
for (const
|
|
3222
|
-
const
|
|
3223
|
-
if (!
|
|
3224
|
-
errors.push(...
|
|
3239
|
+
for (const agent2 of this.agents) {
|
|
3240
|
+
const agentValidation = agent2.validate();
|
|
3241
|
+
if (!agentValidation.valid) {
|
|
3242
|
+
errors.push(...agentValidation.errors.map((error) => `Agent '${agent2.getId()}': ${error}`));
|
|
3225
3243
|
}
|
|
3226
3244
|
}
|
|
3227
3245
|
return {
|
|
@@ -3233,7 +3251,7 @@ var Project = class {
|
|
|
3233
3251
|
* Convert the Project to FullProjectDefinition format
|
|
3234
3252
|
*/
|
|
3235
3253
|
async toFullProjectDefinition() {
|
|
3236
|
-
const
|
|
3254
|
+
const agentsObject = {};
|
|
3237
3255
|
const toolsObject = {};
|
|
3238
3256
|
const functionToolsObject = {};
|
|
3239
3257
|
const functionsObject = {};
|
|
@@ -3241,12 +3259,12 @@ var Project = class {
|
|
|
3241
3259
|
const artifactComponentsObject = {};
|
|
3242
3260
|
const credentialReferencesObject = {};
|
|
3243
3261
|
const credentialUsageMap = {};
|
|
3244
|
-
for (const
|
|
3245
|
-
const
|
|
3246
|
-
|
|
3247
|
-
const
|
|
3248
|
-
if (
|
|
3249
|
-
for (const credential2 of
|
|
3262
|
+
for (const agent2 of this.agents) {
|
|
3263
|
+
const agentDefinition = await agent2.toFullAgentDefinition();
|
|
3264
|
+
agentsObject[agent2.getId()] = agentDefinition;
|
|
3265
|
+
const agentCredentials = agent2.credentials;
|
|
3266
|
+
if (agentCredentials && Array.isArray(agentCredentials)) {
|
|
3267
|
+
for (const credential2 of agentCredentials) {
|
|
3250
3268
|
if (credential2?.__type === "credential-ref") {
|
|
3251
3269
|
continue;
|
|
3252
3270
|
}
|
|
@@ -3261,15 +3279,15 @@ var Project = class {
|
|
|
3261
3279
|
credentialUsageMap[credential2.id] = [];
|
|
3262
3280
|
}
|
|
3263
3281
|
credentialUsageMap[credential2.id].push({
|
|
3264
|
-
type: "
|
|
3265
|
-
id:
|
|
3282
|
+
type: "agent",
|
|
3283
|
+
id: agent2.getId()
|
|
3266
3284
|
});
|
|
3267
3285
|
}
|
|
3268
3286
|
}
|
|
3269
3287
|
}
|
|
3270
|
-
const
|
|
3271
|
-
if (
|
|
3272
|
-
const contextVariables =
|
|
3288
|
+
const agentContextConfig = agent2.contextConfig;
|
|
3289
|
+
if (agentContextConfig) {
|
|
3290
|
+
const contextVariables = agentContextConfig.getContextVariables?.() || agentContextConfig.contextVariables;
|
|
3273
3291
|
if (contextVariables) {
|
|
3274
3292
|
for (const [key, variable] of Object.entries(contextVariables)) {
|
|
3275
3293
|
if (variable?.credential) {
|
|
@@ -3298,7 +3316,7 @@ var Project = class {
|
|
|
3298
3316
|
credentialUsageMap[credId].push({
|
|
3299
3317
|
type: "contextVariable",
|
|
3300
3318
|
id: key,
|
|
3301
|
-
|
|
3319
|
+
agentId: agent2.getId()
|
|
3302
3320
|
});
|
|
3303
3321
|
}
|
|
3304
3322
|
} else if (variable?.credentialReferenceId) {
|
|
@@ -3309,17 +3327,17 @@ var Project = class {
|
|
|
3309
3327
|
credentialUsageMap[credId].push({
|
|
3310
3328
|
type: "contextVariable",
|
|
3311
3329
|
id: key,
|
|
3312
|
-
|
|
3330
|
+
agentId: agent2.getId()
|
|
3313
3331
|
});
|
|
3314
3332
|
}
|
|
3315
3333
|
}
|
|
3316
3334
|
}
|
|
3317
3335
|
}
|
|
3318
|
-
for (const
|
|
3319
|
-
if (
|
|
3336
|
+
for (const subAgent2 of agent2.getSubAgents()) {
|
|
3337
|
+
if (subAgent2.type === "external") {
|
|
3320
3338
|
continue;
|
|
3321
3339
|
}
|
|
3322
|
-
const agentTools =
|
|
3340
|
+
const agentTools = subAgent2.getTools();
|
|
3323
3341
|
for (const [, toolInstance] of Object.entries(agentTools)) {
|
|
3324
3342
|
const actualTool = toolInstance;
|
|
3325
3343
|
const toolId = actualTool.getId();
|
|
@@ -3373,7 +3391,7 @@ var Project = class {
|
|
|
3373
3391
|
}
|
|
3374
3392
|
}
|
|
3375
3393
|
}
|
|
3376
|
-
const subAgentDataComponents =
|
|
3394
|
+
const subAgentDataComponents = subAgent2.getDataComponents?.();
|
|
3377
3395
|
if (subAgentDataComponents) {
|
|
3378
3396
|
for (const dataComponent2 of subAgentDataComponents) {
|
|
3379
3397
|
let dataComponentId;
|
|
@@ -3401,18 +3419,19 @@ var Project = class {
|
|
|
3401
3419
|
}
|
|
3402
3420
|
}
|
|
3403
3421
|
}
|
|
3404
|
-
const subAgentArtifactComponents =
|
|
3422
|
+
const subAgentArtifactComponents = subAgent2.getArtifactComponents();
|
|
3405
3423
|
if (subAgentArtifactComponents) {
|
|
3406
3424
|
for (const artifactComponent2 of subAgentArtifactComponents) {
|
|
3407
3425
|
let artifactComponentId;
|
|
3408
3426
|
let artifactComponentName;
|
|
3409
3427
|
let artifactComponentDescription;
|
|
3410
3428
|
let artifactComponentProps;
|
|
3411
|
-
if (artifactComponent2.getId) {
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3429
|
+
if ("getId" in artifactComponent2 && typeof artifactComponent2.getId === "function") {
|
|
3430
|
+
const component = artifactComponent2;
|
|
3431
|
+
artifactComponentId = component.getId();
|
|
3432
|
+
artifactComponentName = component.getName();
|
|
3433
|
+
artifactComponentDescription = component.getDescription() || "";
|
|
3434
|
+
artifactComponentProps = component.getProps() || {};
|
|
3416
3435
|
} else {
|
|
3417
3436
|
artifactComponentId = artifactComponent2.id || (artifactComponent2.name ? artifactComponent2.name.toLowerCase().replace(/\s+/g, "-") : "");
|
|
3418
3437
|
artifactComponentName = artifactComponent2.name || "";
|
|
@@ -3512,7 +3531,7 @@ var Project = class {
|
|
|
3512
3531
|
models: this.models,
|
|
3513
3532
|
stopWhen: this.stopWhen,
|
|
3514
3533
|
sandboxConfig: this.sandboxConfig,
|
|
3515
|
-
|
|
3534
|
+
agents: agentsObject,
|
|
3516
3535
|
tools: toolsObject,
|
|
3517
3536
|
functions: Object.keys(functionsObject).length > 0 ? functionsObject : void 0,
|
|
3518
3537
|
dataComponents: Object.keys(dataComponentsObject).length > 0 ? dataComponentsObject : void 0,
|
|
@@ -3525,8 +3544,8 @@ var Project = class {
|
|
|
3525
3544
|
};
|
|
3526
3545
|
|
|
3527
3546
|
// src/builderFunctions.ts
|
|
3528
|
-
function
|
|
3529
|
-
return new
|
|
3547
|
+
function agent(config) {
|
|
3548
|
+
return new Agent(config);
|
|
3530
3549
|
}
|
|
3531
3550
|
function project(config) {
|
|
3532
3551
|
return new Project(config);
|
|
@@ -3698,7 +3717,7 @@ var ExternalAgent = class {
|
|
|
3698
3717
|
throw error;
|
|
3699
3718
|
}
|
|
3700
3719
|
}
|
|
3701
|
-
// Set context (tenantId and baseURL) from external source (
|
|
3720
|
+
// Set context (tenantId and baseURL) from external source (agent, CLI, etc)
|
|
3702
3721
|
setContext(tenantId, baseURL) {
|
|
3703
3722
|
this.tenantId = tenantId;
|
|
3704
3723
|
if (baseURL) {
|
|
@@ -3839,58 +3858,58 @@ var MaxTurnsExceededError = class extends AgentError {
|
|
|
3839
3858
|
var logger12 = getLogger("runner");
|
|
3840
3859
|
var Runner = class _Runner {
|
|
3841
3860
|
/**
|
|
3842
|
-
* Run
|
|
3861
|
+
* Run an agent until completion, handling transfers and tool calls
|
|
3843
3862
|
* Similar to OpenAI's Runner.run() pattern
|
|
3844
|
-
* NOTE: This now requires
|
|
3863
|
+
* NOTE: This now requires an agent instead of an agent
|
|
3845
3864
|
*/
|
|
3846
|
-
static async run(
|
|
3865
|
+
static async run(agent2, messages, options) {
|
|
3847
3866
|
const maxTurns = options?.maxTurns || 10;
|
|
3848
3867
|
let turnCount = 0;
|
|
3849
3868
|
const messageHistory = _Runner.normalizeToMessageHistory(messages);
|
|
3850
3869
|
const allToolCalls = [];
|
|
3851
3870
|
logger12.info(
|
|
3852
3871
|
{
|
|
3853
|
-
|
|
3854
|
-
defaultSubAgent:
|
|
3872
|
+
agentId: agent2.getId(),
|
|
3873
|
+
defaultSubAgent: agent2.getDefaultSubAgent()?.getName(),
|
|
3855
3874
|
maxTurns,
|
|
3856
3875
|
initialMessageCount: messageHistory.length
|
|
3857
3876
|
},
|
|
3858
|
-
"Starting
|
|
3877
|
+
"Starting agent run"
|
|
3859
3878
|
);
|
|
3860
3879
|
while (turnCount < maxTurns) {
|
|
3861
3880
|
logger12.debug(
|
|
3862
3881
|
{
|
|
3863
|
-
|
|
3882
|
+
agentId: agent2.getId(),
|
|
3864
3883
|
turnCount,
|
|
3865
3884
|
messageHistoryLength: messageHistory.length
|
|
3866
3885
|
},
|
|
3867
3886
|
"Starting turn"
|
|
3868
3887
|
);
|
|
3869
|
-
const response = await
|
|
3888
|
+
const response = await agent2.generate(messageHistory, options);
|
|
3870
3889
|
turnCount++;
|
|
3871
3890
|
logger12.info(
|
|
3872
3891
|
{
|
|
3873
|
-
|
|
3892
|
+
agentId: agent2.getId(),
|
|
3874
3893
|
turnCount,
|
|
3875
3894
|
responseLength: response.length
|
|
3876
3895
|
},
|
|
3877
|
-
"
|
|
3896
|
+
"Agent generation completed"
|
|
3878
3897
|
);
|
|
3879
3898
|
return {
|
|
3880
3899
|
finalOutput: response,
|
|
3881
|
-
agent:
|
|
3900
|
+
agent: agent2.getDefaultSubAgent() || {},
|
|
3882
3901
|
turnCount,
|
|
3883
3902
|
usage: { inputTokens: 0, outputTokens: 0 },
|
|
3884
3903
|
metadata: {
|
|
3885
3904
|
toolCalls: allToolCalls,
|
|
3886
3905
|
transfers: []
|
|
3887
|
-
//
|
|
3906
|
+
// Agent handles transfers internally
|
|
3888
3907
|
}
|
|
3889
3908
|
};
|
|
3890
3909
|
}
|
|
3891
3910
|
logger12.error(
|
|
3892
3911
|
{
|
|
3893
|
-
|
|
3912
|
+
agentId: agent2.getId(),
|
|
3894
3913
|
maxTurns,
|
|
3895
3914
|
finalTurnCount: turnCount
|
|
3896
3915
|
},
|
|
@@ -3899,43 +3918,43 @@ var Runner = class _Runner {
|
|
|
3899
3918
|
throw new MaxTurnsExceededError(maxTurns);
|
|
3900
3919
|
}
|
|
3901
3920
|
/**
|
|
3902
|
-
* Stream
|
|
3921
|
+
* Stream an agent's response
|
|
3903
3922
|
*/
|
|
3904
|
-
static async stream(
|
|
3923
|
+
static async stream(agent2, messages, options) {
|
|
3905
3924
|
logger12.info(
|
|
3906
3925
|
{
|
|
3907
|
-
|
|
3908
|
-
defaultSubAgent:
|
|
3926
|
+
agentId: agent2.getId(),
|
|
3927
|
+
defaultSubAgent: agent2.getDefaultSubAgent()?.getName()
|
|
3909
3928
|
},
|
|
3910
|
-
"Starting
|
|
3929
|
+
"Starting agent stream"
|
|
3911
3930
|
);
|
|
3912
|
-
return
|
|
3931
|
+
return agent2.stream(messages, options);
|
|
3913
3932
|
}
|
|
3914
3933
|
/**
|
|
3915
|
-
* Execute multiple
|
|
3934
|
+
* Execute multiple agent in parallel and return the first successful result
|
|
3916
3935
|
*/
|
|
3917
|
-
static async
|
|
3918
|
-
if (
|
|
3919
|
-
throw new Error("No
|
|
3936
|
+
static async raceAgents(agent2, messages, options) {
|
|
3937
|
+
if (agent2.length === 0) {
|
|
3938
|
+
throw new Error("No agent provided for race");
|
|
3920
3939
|
}
|
|
3921
3940
|
logger12.info(
|
|
3922
3941
|
{
|
|
3923
|
-
|
|
3924
|
-
|
|
3942
|
+
agentCount: agent2.length,
|
|
3943
|
+
agentIds: agent2.map((g) => g.getId())
|
|
3925
3944
|
},
|
|
3926
|
-
"Starting
|
|
3945
|
+
"Starting agent race"
|
|
3927
3946
|
);
|
|
3928
|
-
const promises =
|
|
3947
|
+
const promises = agent2.map(async (agent3, index) => {
|
|
3929
3948
|
try {
|
|
3930
|
-
const result2 = await _Runner.run(
|
|
3949
|
+
const result2 = await _Runner.run(agent3, messages, options);
|
|
3931
3950
|
return { ...result2, raceIndex: index };
|
|
3932
3951
|
} catch (error) {
|
|
3933
3952
|
logger12.error(
|
|
3934
3953
|
{
|
|
3935
|
-
|
|
3954
|
+
agentId: agent3.getId(),
|
|
3936
3955
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
3937
3956
|
},
|
|
3938
|
-
"
|
|
3957
|
+
"Agent failed in race"
|
|
3939
3958
|
);
|
|
3940
3959
|
throw error;
|
|
3941
3960
|
}
|
|
@@ -3943,10 +3962,10 @@ var Runner = class _Runner {
|
|
|
3943
3962
|
const result = await Promise.race(promises);
|
|
3944
3963
|
logger12.info(
|
|
3945
3964
|
{
|
|
3946
|
-
|
|
3965
|
+
winningAgentId: result.agentId || "unknown",
|
|
3947
3966
|
raceIndex: result.raceIndex
|
|
3948
3967
|
},
|
|
3949
|
-
"
|
|
3968
|
+
"Agent race completed"
|
|
3950
3969
|
);
|
|
3951
3970
|
return result;
|
|
3952
3971
|
}
|
|
@@ -3963,14 +3982,14 @@ var Runner = class _Runner {
|
|
|
3963
3982
|
return [messages];
|
|
3964
3983
|
}
|
|
3965
3984
|
/**
|
|
3966
|
-
* Validate
|
|
3985
|
+
* Validate agent configuration before running
|
|
3967
3986
|
*/
|
|
3968
|
-
static
|
|
3987
|
+
static validateAgent(agent2) {
|
|
3969
3988
|
const errors = [];
|
|
3970
|
-
if (!
|
|
3971
|
-
errors.push("
|
|
3989
|
+
if (!agent2.getId()) {
|
|
3990
|
+
errors.push("Agent ID is required");
|
|
3972
3991
|
}
|
|
3973
|
-
const defaultSubAgent =
|
|
3992
|
+
const defaultSubAgent = agent2.getDefaultSubAgent();
|
|
3974
3993
|
if (!defaultSubAgent) {
|
|
3975
3994
|
errors.push("Default agent is required");
|
|
3976
3995
|
} else {
|
|
@@ -3981,12 +4000,12 @@ var Runner = class _Runner {
|
|
|
3981
4000
|
errors.push("Default agent instructions are required");
|
|
3982
4001
|
}
|
|
3983
4002
|
}
|
|
3984
|
-
const
|
|
3985
|
-
if (
|
|
3986
|
-
errors.push("
|
|
4003
|
+
const subAgents = agent2.getSubAgents();
|
|
4004
|
+
if (subAgents.length === 0) {
|
|
4005
|
+
errors.push("Agent must contain at least one subagent");
|
|
3987
4006
|
}
|
|
3988
|
-
for (const
|
|
3989
|
-
if (!
|
|
4007
|
+
for (const subAgent2 of subAgents) {
|
|
4008
|
+
if (!subAgent2.getName()) {
|
|
3990
4009
|
errors.push(`Agent missing name`);
|
|
3991
4010
|
}
|
|
3992
4011
|
}
|
|
@@ -3996,23 +4015,23 @@ var Runner = class _Runner {
|
|
|
3996
4015
|
};
|
|
3997
4016
|
}
|
|
3998
4017
|
/**
|
|
3999
|
-
* Get execution statistics for
|
|
4018
|
+
* Get execution statistics for an agent
|
|
4000
4019
|
*/
|
|
4001
|
-
static async getExecutionStats(
|
|
4002
|
-
const
|
|
4003
|
-
const defaultSubAgent =
|
|
4020
|
+
static async getExecutionStats(agent2, messages, options) {
|
|
4021
|
+
const subAgents = agent2.getSubAgents();
|
|
4022
|
+
const defaultSubAgent = agent2.getDefaultSubAgent();
|
|
4004
4023
|
const messageCount = Array.isArray(messages) ? messages.length : 1;
|
|
4005
4024
|
return {
|
|
4006
4025
|
estimatedTurns: Math.min(Math.max(messageCount, 1), options?.maxTurns || 10),
|
|
4007
4026
|
estimatedTokens: messageCount * 100,
|
|
4008
4027
|
// Rough estimate
|
|
4009
|
-
|
|
4028
|
+
subAgentCount: subAgents.length,
|
|
4010
4029
|
defaultSubAgent: defaultSubAgent?.getName()
|
|
4011
4030
|
};
|
|
4012
4031
|
}
|
|
4013
4032
|
};
|
|
4014
4033
|
var run = Runner.run.bind(Runner);
|
|
4015
4034
|
var stream = Runner.stream.bind(Runner);
|
|
4016
|
-
var
|
|
4035
|
+
var raceAgents = Runner.raceAgents.bind(Runner);
|
|
4017
4036
|
|
|
4018
|
-
export {
|
|
4037
|
+
export { ArtifactComponent, DataComponent, ExternalAgent, FunctionTool, Project, Runner, SubAgent, Tool, agent, agentMcp, artifactComponent, createEnvironmentSettings, createFullProjectViaAPI, credential, credentialRef, dataComponent, deleteFullProjectViaAPI, externalAgent, externalAgents, functionTool, getFullProjectViaAPI, isCredentialReference, mcpServer, mcpTool, project, raceAgents, registerEnvironmentSettings, run, stream, subAgent, transfer, updateFullProjectViaAPI };
|