@memberjunction/ai-agents 2.122.2 → 2.123.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.
@@ -53,6 +53,7 @@ class BaseAgent {
53
53
  this._allProgressSteps = [];
54
54
  this._subAgentRuns = [];
55
55
  this._payloadManager = new PayloadManager_1.PayloadManager();
56
+ this._effectiveActions = [];
56
57
  this._validationRetryCount = 0;
57
58
  this._contextRecoveryAttempts = 0;
58
59
  this.MAX_RECOVERY_ATTEMPTS = 1;
@@ -566,7 +567,7 @@ class BaseAgent {
566
567
  const agentType = config.agentType;
567
568
  const systemPrompt = config.systemPrompt;
568
569
  const childPrompt = config.childPrompt;
569
- const promptTemplateData = await this.gatherPromptTemplateData(params.agent, params.contextUser, params.data);
570
+ const promptTemplateData = await this.gatherPromptTemplateData(params.agent, params.contextUser, params.data, params.actionChanges);
570
571
  const promptParams = new ai_core_plus_1.AIPromptParams();
571
572
  if (systemPrompt) {
572
573
  promptParams.prompt = systemPrompt;
@@ -1605,7 +1606,7 @@ The context is now within limits. Please retry your request with the recovered c
1605
1606
  content: `Sub-agent '${subAgent.name}' result:\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`
1606
1607
  };
1607
1608
  }
1608
- async gatherPromptTemplateData(agent, _contextUser, extraData) {
1609
+ async gatherPromptTemplateData(agent, _contextUser, extraData, actionChanges) {
1609
1610
  try {
1610
1611
  const engine = aiengine_1.AIEngine.Instance;
1611
1612
  const activeSubAgents = engine.Agents.filter(a => a.ParentID === agent.ID && a.Status === 'Active')
@@ -1616,15 +1617,20 @@ The context is now within limits. Please retry your request with the recovered c
1616
1617
  activeAgentRelationships.forEach(ar => uniqueActiveSubAgentIDs.add(ar.SubAgentID));
1617
1618
  const uniqueActiveSubAgents = Array.from(uniqueActiveSubAgentIDs).map(id => engine.Agents.find(a => a.ID === id));
1618
1619
  const agentActions = engine.AgentActions.filter(aa => aa.AgentID === agent.ID && aa.Status === 'Active');
1619
- const actions = actions_1.ActionEngineServer.Instance.Actions.filter(a => agentActions.some(aa => aa.ActionID === a.ID));
1620
+ let actions = actions_1.ActionEngineServer.Instance.Actions.filter(a => agentActions.some(aa => aa.ActionID === a.ID));
1621
+ if (actionChanges?.length) {
1622
+ const isRoot = this._depth === 0;
1623
+ actions = this.applyActionChanges(actions, actionChanges, agent.ID, isRoot);
1624
+ }
1620
1625
  const activeActions = actions.filter(a => a.Status === 'Active');
1626
+ this._effectiveActions = activeActions;
1621
1627
  const contextData = {
1622
1628
  agentName: agent.Name,
1623
1629
  agentDescription: agent.Description,
1624
1630
  parentAgentName: agent.Parent ? agent.Parent.trim() : "",
1625
1631
  subAgentCount: uniqueActiveSubAgents.length,
1626
1632
  subAgentDetails: this.formatSubAgentDetails(uniqueActiveSubAgents),
1627
- actionCount: actions.length,
1633
+ actionCount: activeActions.length,
1628
1634
  actionDetails: this.formatActionDetails(activeActions),
1629
1635
  };
1630
1636
  if (extraData) {
@@ -1741,6 +1747,7 @@ The context is now within limits. Please retry your request with the recovered c
1741
1747
  this.logStatus(`🎯 Propagating effort level ${params.effortLevel} to sub-agent '${subAgentRequest.name}'`, true, params);
1742
1748
  }
1743
1749
  const parentStepCountsToPass = [...this._parentStepCounts, stepCount + 1];
1750
+ const subAgentActionChanges = this.filterActionChangesForSubAgent(params.actionChanges);
1744
1751
  const result = await runner.RunAgent({
1745
1752
  agent: subAgent,
1746
1753
  conversationMessages: subAgentMessages,
@@ -1761,6 +1768,7 @@ The context is now within limits. Please retry your request with the recovered c
1761
1768
  },
1762
1769
  context: params.context,
1763
1770
  verbose: params.verbose,
1771
+ actionChanges: subAgentActionChanges,
1764
1772
  onAgentRunCreated: async (agentRunId) => {
1765
1773
  stepEntity.TargetLogID = agentRunId;
1766
1774
  await stepEntity.Save();
@@ -1876,6 +1884,67 @@ The context is now within limits. Please retry your request with the recovered c
1876
1884
  const agentType = aiengine_1.AIEngine.Instance.AgentTypes.find(at => at.ID === typeID);
1877
1885
  return agentType?.Name || 'Unknown';
1878
1886
  }
1887
+ doesChangeScopeApply(scope, agentId, isRoot, agentIds) {
1888
+ switch (scope) {
1889
+ case 'global':
1890
+ return true;
1891
+ case 'root':
1892
+ return isRoot;
1893
+ case 'all-subagents':
1894
+ return !isRoot;
1895
+ case 'specific':
1896
+ return agentIds?.includes(agentId) ?? false;
1897
+ default:
1898
+ return false;
1899
+ }
1900
+ }
1901
+ applyActionChanges(baseActions, actionChanges, agentId, isRoot) {
1902
+ let actions = [...baseActions];
1903
+ for (const change of actionChanges) {
1904
+ if (!this.doesChangeScopeApply(change.scope, agentId, isRoot, change.agentIds)) {
1905
+ continue;
1906
+ }
1907
+ if (change.mode === 'add') {
1908
+ for (const actionId of change.actionIds) {
1909
+ if (!actions.some(a => a.ID === actionId)) {
1910
+ const actionToAdd = actions_1.ActionEngineServer.Instance.Actions.find(a => a.ID === actionId);
1911
+ if (actionToAdd) {
1912
+ actions.push(actionToAdd);
1913
+ }
1914
+ else {
1915
+ (0, core_1.LogStatus)(`Action with ID '${actionId}' not found in ActionEngineServer - skipping add`);
1916
+ }
1917
+ }
1918
+ }
1919
+ }
1920
+ else if (change.mode === 'remove') {
1921
+ actions = actions.filter(a => !change.actionIds.includes(a.ID));
1922
+ }
1923
+ }
1924
+ return actions;
1925
+ }
1926
+ filterActionChangesForSubAgent(actionChanges) {
1927
+ if (!actionChanges?.length) {
1928
+ return undefined;
1929
+ }
1930
+ const filtered = [];
1931
+ for (const change of actionChanges) {
1932
+ switch (change.scope) {
1933
+ case 'root':
1934
+ continue;
1935
+ case 'global':
1936
+ filtered.push(change);
1937
+ break;
1938
+ case 'all-subagents':
1939
+ filtered.push({ ...change, scope: 'global' });
1940
+ break;
1941
+ case 'specific':
1942
+ filtered.push(change);
1943
+ break;
1944
+ }
1945
+ }
1946
+ return filtered.length > 0 ? filtered : undefined;
1947
+ }
1879
1948
  getValueListItems(valueListID) {
1880
1949
  return null;
1881
1950
  }
@@ -3124,6 +3193,9 @@ The context is now within limits. Please retry your request with the recovered c
3124
3193
  }
3125
3194
  const actionEngine = actions_1.ActionEngineServer.Instance;
3126
3195
  const agentActions = aiengine_1.AIEngine.Instance.AgentActions.filter(aa => aa.AgentID === params.agent.ID);
3196
+ const effectiveActions = this._effectiveActions.length > 0
3197
+ ? this._effectiveActions
3198
+ : actionEngine.Actions.filter(a => agentActions.some(aa => aa.ActionID === a.ID));
3127
3199
  try {
3128
3200
  const currentPayload = previousDecision?.newPayload || previousDecision?.previousPayload || params.payload;
3129
3201
  await this.AgentTypeInstance.PreProcessActionStep(actions, currentPayload, this.AgentTypeState, previousDecision, params);
@@ -3135,9 +3207,9 @@ The context is now within limits. Please retry your request with the recovered c
3135
3207
  const baseStepNumber = (this._agentRun.Steps?.length || 0) + 1;
3136
3208
  let lastStep = undefined;
3137
3209
  const actionPromises = actions.map(async (aa) => {
3138
- const actionEntity = actionEngine.Actions.find(a => a.Name === aa.name && agentActions.some(agentAction => agentAction.ActionID === a.ID));
3210
+ const actionEntity = effectiveActions.find(a => a.Name === aa.name);
3139
3211
  if (!actionEntity) {
3140
- throw new Error(`Action "${aa.name}" Not Found for Agent "${params.agent.Name}"`);
3212
+ throw new Error(`Action "${aa.name}" Not Found for Agent "${params.agent.Name}". Available actions: ${effectiveActions.map(a => a.Name).join(', ')}`);
3141
3213
  }
3142
3214
  const actionInputData = {
3143
3215
  actionName: aa.name,