@ax-llm/ax 19.0.1 → 19.0.2
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/index.cjs +3 -3
- package/index.cjs.map +1 -1
- package/index.global.js +3 -3
- package/index.global.js.map +1 -1
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/ax-agent.md +1 -1
- package/skills/ax-llm.md +1 -1
package/index.global.js
CHANGED
|
@@ -690,7 +690,7 @@ ${o}
|
|
|
690
690
|
### Responder output fields
|
|
691
691
|
The responder is looking to produce the following output fields: ${s}
|
|
692
692
|
|
|
693
|
-
###
|
|
693
|
+
### Functions for context analysis and responding
|
|
694
694
|
- \`await llmQuery(query:string, context:object|array|string) : string\` \u2014 Have a sub agent work on a part of the task for you when the context is too large or complex to handle in a single turn. Its a way to divide and conquer but do not overuse it.
|
|
695
695
|
|
|
696
696
|
- \`await llmQuery([{ query:string, context:object|array|string }, ...]) : string\` \u2014 A batched version of \`llmQuery\` that allows you to make multiple queries in parallel. Use this to speed up processing when you have many items to analyze. Sub-agent calls have a call limit of ${r}. Oversized values are truncated automatically.
|
|
@@ -699,7 +699,7 @@ The responder is looking to produce the following output fields: ${s}
|
|
|
699
699
|
|
|
700
700
|
- \`ask_clarification(...args)\` \u2014 Signal that more user input is needed and provide clarification arguments for the responder. Requires at least one argument. Execution ends after calling it.
|
|
701
701
|
${n.hasInspectRuntime?"\n- `await inspect_runtime() : string` \u2014 Returns a compact snapshot of all user-defined variables in the runtime session (name, type, size, preview). Use this to re-ground yourself when the action log is large instead of re-reading previous outputs.\n":""}${n.agents&&n.agents.length>0?`
|
|
702
|
-
### Available
|
|
702
|
+
### Available Agents Functions
|
|
703
703
|
The following agents are pre-loaded under the \`agents\` namespace. Call them for specialized tasks:
|
|
704
704
|
${n.agents.map(l=>`- \`await agents.${l.name}(${hc(l.parameters)})\` \u2014 ${l.description}`).join(`
|
|
705
705
|
`)}
|
|
@@ -782,7 +782,7 @@ ${e.output}${e.actorFieldsOutput}`).join(`
|
|
|
782
782
|
} catch { preview = String(v).slice(0, 80); }
|
|
783
783
|
return k + ': ' + type + (size ? ' (' + size + ')' : '') + ' = ' + preview;
|
|
784
784
|
}).join('\\n') || '(no user variables)';
|
|
785
|
-
})()`}var bc=50,rm=5e3,om=8,Ic=10,sm=2,qr=class i{ai;program;actorProgram;responderProgram;agents;agentFunctions;debug;options;rlmConfig;runtime;actorFieldNames;sharedFieldNames;globalSharedFieldNames;excludedSharedFields;excludedAgents;excludedAgentFunctions;actorDescription;responderDescription;recursionForwardOptions;actorForwardOptions;responderForwardOptions;activeAbortControllers=new Set;_stopRequested=!1;func;_parentSharedFields=new Set;_parentSharedAgents=new Set;_parentSharedAgentFunctions=new Set;constructor({ai:e,agentIdentity:t,signature:n},r){let{debug:o,contextFields:s,runtime:a,maxLlmCalls:l,maxRuntimeChars:u,maxBatchedLlmQueryConcurrency:c,maxTurns:p,trajectoryPruning:d,contextManagement:m,actorFields:g,actorCallback:h,mode:f,recursionOptions:y,actorOptions:x,responderOptions:A}=r;this.ai=e,this.agents=r.agents?.local,this.agentFunctions=r.functions?.local??[],this.debug=o,this.options=r,this.runtime=a??new Vt,this.rlmConfig={contextFields:s,sharedFields:r.fields?.shared,runtime:this.runtime,maxLlmCalls:l,maxRuntimeChars:u,maxBatchedLlmQueryConcurrency:c,maxTurns:p,trajectoryPruning:d,contextManagement:m,actorFields:g,actorCallback:h,mode:f},this.recursionForwardOptions=y;let{description:R,...b}=x??{},{description:T,...O}=A??{};this.actorDescription=R,this.actorForwardOptions=b,this.responderDescription=T,this.responderForwardOptions=O;let{agents:N,fields:M,functions:U,...B}=r;this.program=new Se(n,B);let $=this.agents;for(let H of $??[]){let Q=H.getFunction().name;this.program.register(H,Q)}t&&(this.func={name:cm(t.name),description:t.description,parameters:this._buildFuncParameters(),func:async()=>{throw new Error("Use getFunction() to get a callable wrapper")}});let I=this.program.getSignature().getInputFields();for(let H of s)if(!I.some(Q=>Q.name===H))throw new Error(`RLM contextField "${H}" not found in signature`);if(this.program.getSignature().getDescription())throw new Error("AxAgent does not support signature-level descriptions. Use setActorDescription() and/or setResponderDescription() to customize the actor and responder prompts independently.");let k=this.program.getSignature().getOutputFields(),E=g??[];this.actorFieldNames=E;for(let H of E)if(!k.some(Q=>Q.name===H))throw new Error(`RLM actorField "${H}" not found in output signature`);let F=r.fields?.shared??[];this.sharedFieldNames=F;for(let H of F)if(!I.some(Q=>Q.name===H))throw new Error(`sharedField "${H}" not found in signature input fields`);this.excludedSharedFields=r.fields?.excluded??[];let v=r.fields?.globallyShared??[];this.globalSharedFieldNames=v;for(let H of v)if(!I.some(Q=>Q.name===H))throw new Error(`globalSharedField "${H}" not found in signature input fields`);let P=r.agents?.shared??[],j=r.agents?.globallyShared??[];this.excludedAgents=r.agents?.excluded??[];let L=r.functions?.shared??[],K=r.functions?.globallyShared??[];this.excludedAgentFunctions=r.functions?.excluded??[];let ie=new Set(["agents","llmQuery","final","ask_clarification"]);for(let H of[...this.agentFunctions,...L,...K]){let Q=H.namespace??"utils";if(ie.has(Q))throw new Error(`Agent function namespace "${Q}" is reserved`)}if(F.length>0&&$){let H=I.filter(Q=>F.includes(Q.name));for(let Q of $){if(!(Q instanceof i))continue;let oe=new Set(Q.getExcludedSharedFields()),pe=H.filter(Ie=>!oe.has(Ie.name));pe.length!==0&&Q._extendForSharedFields(pe,s)}}if(P.length>0&&$)for(let H of $)H instanceof i&&H._extendForSharedAgents(P);if(v.length>0&&$){let H=I.filter(Q=>v.includes(Q.name));for(let Q of $){if(!(Q instanceof i))continue;let oe=new Set(Q.getExcludedSharedFields()),pe=H.filter(Ie=>!oe.has(Ie.name));pe.length!==0&&Q._extendForGlobalSharedFields(pe,s)}}if(j.length>0&&$)for(let H of $)H instanceof i&&H._extendForGlobalSharedAgents(j);if(L.length>0&&$)for(let H of $)H instanceof i&&H._extendForSharedAgentFunctions(L);if(K.length>0&&$)for(let H of $)H instanceof i&&H._extendForGlobalSharedAgentFunctions(K);this._buildSplitPrograms(),this.program.register(this.actorProgram,"actor"),this.program.register(this.responderProgram,"responder")}_buildSplitPrograms(){let e=this.program.getSignature().getInputFields(),t=this.rlmConfig.contextFields,n=[...this.sharedFieldNames,...this.globalSharedFieldNames],r=e.filter(x=>t.includes(x.name)),o=e.filter(x=>!t.includes(x.name)&&!n.includes(x.name)),s=this.program.getSignature().getOutputFields(),a=s.filter(x=>this.actorFieldNames.includes(x.name)),l=s.filter(x=>!this.actorFieldNames.includes(x.name)),u=xe().addInputFields(o).input("contextMetadata",xe.string("Metadata about pre-loaded context variables (type and size)")).input("actionLog",xe.string("Chronological trace of code executions or actions and their outputs so far")).output("javascriptCode",xe.code("JavaScript code to execute in runtime session"));a.length>0&&(u=u.addOutputFields(a));let c=u.build(),p=xe().addInputFields(o).input("contextData",xe.json("Context data to help synthesize the final answer.")).addOutputFields(l).build(),d=this.rlmConfig.maxLlmCalls??bc,m=this.rlmConfig.maxTurns??Ic,g=this.agents?.map(x=>{let A=x.getFunction();return{name:A.name,description:A.description,parameters:A.parameters}})??[],h=this.agentFunctions.map(x=>({name:x.name,description:x.description,parameters:x.parameters,returns:x.returns,namespace:x.namespace??"utils"})),f=vs(this.actorDescription,r,l,{runtimeUsageInstructions:this.runtime.getUsageInstructions(),maxLlmCalls:d,maxTurns:m,hasInspectRuntime:!!this.rlmConfig.contextManagement?.stateInspection,agents:g,agentFunctions:h}),y=Ss(this.responderDescription,r);this.actorProgram=new Se(c,{...this._genOptions,description:f}),this.responderProgram=new Se(p,{...this._genOptions,description:y})}_extendForSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e){if(r.some(a=>a.name===s.name)){if(this._parentSharedFields.has(s.name))throw new Error(`Duplicate shared field "${s.name}" \u2014 already propagated from a parent`);continue}this._parentSharedFields.add(s.name),n.addInputField(s),o=!0}o&&this.program.setSignature(n);for(let s of e)t.includes(s.name)&&!this.rlmConfig.contextFields.includes(s.name)&&this.rlmConfig.contextFields.push(s.name);this._buildSplitPrograms(),this.func&&(this.func.parameters=this._buildFuncParameters())}_extendForSharedAgents(e){if(e.length===0)return;let t=new Set((this.agents??[]).map(o=>o.getFunction().name)),n=new Set(this.excludedAgents),r=[];for(let o of e){let s=o.getFunction().name;if(!n.has(s)){if(t.has(s)){if(this._parentSharedAgents.has(s))throw new Error(`Duplicate shared agent "${s}" \u2014 already propagated from a parent`);continue}this._parentSharedAgents.add(s),t.add(s),r.push(o)}}if(r.length!==0){this.agents=[...this.agents??[],...r];for(let o of r){let s=o.getFunction().name;this.program.register(o,s)}this._buildSplitPrograms()}}_extendForGlobalSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e){if(r.some(a=>a.name===s.name)){if(this._parentSharedFields.has(s.name))throw new Error(`Duplicate shared field "${s.name}" \u2014 already propagated from a parent`);continue}this._parentSharedFields.add(s.name),n.addInputField(s),o=!0}o&&this.program.setSignature(n);for(let s of e)t.includes(s.name)&&!this.rlmConfig.contextFields.includes(s.name)&&this.rlmConfig.contextFields.push(s.name);for(let s of e)this.sharedFieldNames.includes(s.name)||this.sharedFieldNames.push(s.name);if(this._buildSplitPrograms(),this.func&&(this.func.parameters=this._buildFuncParameters()),this.agents)for(let s of this.agents){if(!(s instanceof i))continue;let a=new Set(s.getExcludedSharedFields()),l=e.filter(u=>!a.has(u.name));l.length!==0&&s._extendForGlobalSharedFields(l,t)}}_extendForGlobalSharedAgents(e){let t=this.agents?this.agents.filter(n=>n instanceof i):[];this._extendForSharedAgents(e);for(let n of t)n._extendForGlobalSharedAgents(e)}_extendForSharedAgentFunctions(e){if(e.length===0)return;let t=new Set(this.agentFunctions.map(o=>`${o.namespace??"utils"}.${o.name}`)),n=new Set(this.excludedAgentFunctions),r=[];for(let o of e){if(n.has(o.name))continue;let s=`${o.namespace??"utils"}.${o.name}`;if(t.has(s)){if(this._parentSharedAgentFunctions.has(s))throw new Error(`Duplicate shared agent function "${s}" \u2014 already propagated from a parent`);continue}this._parentSharedAgentFunctions.add(s),t.add(s),r.push(o)}r.length!==0&&(this.agentFunctions=[...this.agentFunctions,...r],this._buildSplitPrograms())}_extendForGlobalSharedAgentFunctions(e){let t=this.agents?this.agents.filter(n=>n instanceof i):[];this._extendForSharedAgentFunctions(e);for(let n of t)n._extendForGlobalSharedAgentFunctions(e)}stop(){this._stopRequested=!0;for(let e of this.activeAbortControllers)e.abort("Stopped by user");this.program.stop(),this.actorProgram.stop(),this.responderProgram.stop()}getId(){return this.program.getId()}setId(e){this.program.setId(e)}namedPrograms(){return this.program.namedPrograms()}getTraces(){return this.program.getTraces()}setDemos(e,t){this.program.setDemos(e,t)}getUsage(){return this.program.getUsage()}resetUsage(){this.program.resetUsage()}getFunction(){if(!this.func)throw new Error("getFunction() requires agentIdentity to be set in the constructor");let e=this.forward.bind(this);return{...this.func,func:async(r,o)=>{let s=this.ai??o?.ai;if(!s)throw new Error("AI service is required to run the agent");let a=await e(s,r,o),u=this.program.getSignature().getOutputFields();return Object.keys(a).map(p=>{let d=u.find(m=>m.name===p);return d?`${d.title}: ${a[p]}`:`${p}: ${a[p]}`}).join(`
|
|
785
|
+
})()`}var bc=50,rm=5e3,om=8,Ic=10,sm=2,qr=class i{ai;program;actorProgram;responderProgram;agents;agentFunctions;debug;options;rlmConfig;runtime;actorFieldNames;sharedFieldNames;globalSharedFieldNames;excludedSharedFields;excludedAgents;excludedAgentFunctions;actorDescription;responderDescription;recursionForwardOptions;actorForwardOptions;responderForwardOptions;activeAbortControllers=new Set;_stopRequested=!1;func;_parentSharedFields=new Set;_parentSharedAgents=new Set;_parentSharedAgentFunctions=new Set;constructor({ai:e,agentIdentity:t,signature:n},r){let{debug:o,contextFields:s,runtime:a,maxLlmCalls:l,maxRuntimeChars:u,maxBatchedLlmQueryConcurrency:c,maxTurns:p,trajectoryPruning:d,contextManagement:m,actorFields:g,actorCallback:h,mode:f,recursionOptions:y,actorOptions:x,responderOptions:A}=r;this.ai=e,this.agents=r.agents?.local,this.agentFunctions=r.functions?.local??[],this.debug=o,this.options=r,this.runtime=a??new Vt,this.rlmConfig={contextFields:s,sharedFields:r.fields?.shared,runtime:this.runtime,maxLlmCalls:l,maxRuntimeChars:u,maxBatchedLlmQueryConcurrency:c,maxTurns:p,trajectoryPruning:d,contextManagement:m,actorFields:g,actorCallback:h,mode:f},this.recursionForwardOptions=y;let{description:R,...b}=x??{},{description:T,...O}=A??{};this.actorDescription=R,this.actorForwardOptions=b,this.responderDescription=T,this.responderForwardOptions=O;let{agents:N,fields:M,functions:U,...B}=r;this.program=new Se(n,B);let $=this.agents;for(let H of $??[]){let Q=H.getFunction().name;this.program.register(H,Q)}t&&(this.func={name:cm(t.name),description:t.description,parameters:this._buildFuncParameters(),func:async()=>{throw new Error("Use getFunction() to get a callable wrapper")}});let I=this.program.getSignature().getInputFields();for(let H of s)if(!I.some(Q=>Q.name===H))throw new Error(`RLM contextField "${H}" not found in signature`);if(this.program.getSignature().getDescription())throw new Error("AxAgent does not support signature-level descriptions. Use setActorDescription() and/or setResponderDescription() to customize the actor and responder prompts independently.");let k=this.program.getSignature().getOutputFields(),E=g??[];this.actorFieldNames=E;for(let H of E)if(!k.some(Q=>Q.name===H))throw new Error(`RLM actorField "${H}" not found in output signature`);let F=r.fields?.shared??[];this.sharedFieldNames=F;for(let H of F)if(!I.some(Q=>Q.name===H))throw new Error(`sharedField "${H}" not found in signature input fields`);this.excludedSharedFields=r.fields?.excluded??[];let v=r.fields?.globallyShared??[];this.globalSharedFieldNames=v;for(let H of v)if(!I.some(Q=>Q.name===H))throw new Error(`globalSharedField "${H}" not found in signature input fields`);let P=r.agents?.shared??[],j=r.agents?.globallyShared??[];this.excludedAgents=r.agents?.excluded??[];let L=r.functions?.shared??[],K=r.functions?.globallyShared??[];this.excludedAgentFunctions=r.functions?.excluded??[];let ie=new Set(["agents","llmQuery","final","ask_clarification"]);for(let H of[...this.agentFunctions,...L,...K]){let Q=H.namespace??"utils";if(ie.has(Q))throw new Error(`Agent function namespace "${Q}" is reserved`)}if(F.length>0&&$){let H=I.filter(Q=>F.includes(Q.name));for(let Q of $){if(!(Q instanceof i))continue;let oe=new Set(Q.getExcludedSharedFields()),pe=H.filter(Ie=>!oe.has(Ie.name));pe.length!==0&&Q._extendForSharedFields(pe,s)}}if(P.length>0&&$)for(let H of $)H instanceof i&&H._extendForSharedAgents(P);if(v.length>0&&$){let H=I.filter(Q=>v.includes(Q.name));for(let Q of $){if(!(Q instanceof i))continue;let oe=new Set(Q.getExcludedSharedFields()),pe=H.filter(Ie=>!oe.has(Ie.name));pe.length!==0&&Q._extendForGlobalSharedFields(pe,s)}}if(j.length>0&&$)for(let H of $)H instanceof i&&H._extendForGlobalSharedAgents(j);if(L.length>0&&$)for(let H of $)H instanceof i&&H._extendForSharedAgentFunctions(L);if(K.length>0&&$)for(let H of $)H instanceof i&&H._extendForGlobalSharedAgentFunctions(K);this._buildSplitPrograms(),this.program.register(this.actorProgram,"actor"),this.program.register(this.responderProgram,"responder")}_buildSplitPrograms(){let e=this.program.getSignature().getInputFields(),t=this.rlmConfig.contextFields,n=[...this.sharedFieldNames,...this.globalSharedFieldNames],r=e.filter(x=>t.includes(x.name)),o=e.filter(x=>!t.includes(x.name)&&!n.includes(x.name)),s=this.program.getSignature().getOutputFields(),a=s.filter(x=>this.actorFieldNames.includes(x.name)),l=s.filter(x=>!this.actorFieldNames.includes(x.name)),u=xe().addInputFields(o).input("contextMetadata",xe.string("Metadata about pre-loaded context variables (type and size)")).input("actionLog",xe.string("Chronological trace of code executions or actions and their outputs so far")).output("javascriptCode",xe.code("JavaScript code to execute in runtime session"));a.length>0&&(u=u.addOutputFields(a));let c=u.build(),p=xe().addInputFields(o).input("contextData",xe.json("Context data to help synthesize the final answer.")).addOutputFields(l).build(),d=this.rlmConfig.maxLlmCalls??bc,m=this.rlmConfig.maxTurns??Ic,g=this.agents?.map(x=>{let A=x.getFunction();return{name:A.name,description:A.description,parameters:A.parameters}})??[],h=this.agentFunctions.map(x=>({name:x.name,description:x.description,parameters:x.parameters,returns:x.returns,namespace:x.namespace??"utils"})),f=vs(this.actorDescription,r,l,{runtimeUsageInstructions:this.runtime.getUsageInstructions(),maxLlmCalls:d,maxTurns:m,hasInspectRuntime:!!this.rlmConfig.contextManagement?.stateInspection,agents:g,agentFunctions:h}),y=Ss(this.responderDescription,r);this.actorProgram=new Se(c,{...this._genOptions,description:f}),this.responderProgram=new Se(p,{...this._genOptions,description:y})}_extendForSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e){if(r.some(a=>a.name===s.name)){if(this._parentSharedFields.has(s.name))throw new Error(`Duplicate shared field "${s.name}" \u2014 already propagated from a parent`);continue}this._parentSharedFields.add(s.name),n.addInputField(s),o=!0}o&&this.program.setSignature(n);for(let s of e)t.includes(s.name)&&!this.rlmConfig.contextFields.includes(s.name)&&this.rlmConfig.contextFields.push(s.name);this._buildSplitPrograms(),this.func&&(this.func.parameters=this._buildFuncParameters())}_extendForSharedAgents(e){if(e.length===0)return;let t=new Set((this.agents??[]).map(o=>o.getFunction().name)),n=new Set(this.excludedAgents),r=[];for(let o of e){if(o===this)continue;let s=o.getFunction().name;if(!n.has(s)){if(t.has(s)){if(this._parentSharedAgents.has(s))throw new Error(`Duplicate shared agent "${s}" \u2014 already propagated from a parent`);continue}this._parentSharedAgents.add(s),t.add(s),r.push(o)}}if(r.length!==0){this.agents=[...this.agents??[],...r];for(let o of r){let s=o.getFunction().name;this.program.register(o,s)}this._buildSplitPrograms()}}_extendForGlobalSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e){if(r.some(a=>a.name===s.name)){if(this._parentSharedFields.has(s.name))throw new Error(`Duplicate shared field "${s.name}" \u2014 already propagated from a parent`);continue}this._parentSharedFields.add(s.name),n.addInputField(s),o=!0}o&&this.program.setSignature(n);for(let s of e)t.includes(s.name)&&!this.rlmConfig.contextFields.includes(s.name)&&this.rlmConfig.contextFields.push(s.name);for(let s of e)this.sharedFieldNames.includes(s.name)||this.sharedFieldNames.push(s.name);if(this._buildSplitPrograms(),this.func&&(this.func.parameters=this._buildFuncParameters()),this.agents)for(let s of this.agents){if(!(s instanceof i))continue;let a=new Set(s.getExcludedSharedFields()),l=e.filter(u=>!a.has(u.name));l.length!==0&&s._extendForGlobalSharedFields(l,t)}}_extendForGlobalSharedAgents(e){let t=this.agents?this.agents.filter(n=>n instanceof i):[];this._extendForSharedAgents(e);for(let n of t)n._extendForGlobalSharedAgents(e)}_extendForSharedAgentFunctions(e){if(e.length===0)return;let t=new Set(this.agentFunctions.map(o=>`${o.namespace??"utils"}.${o.name}`)),n=new Set(this.excludedAgentFunctions),r=[];for(let o of e){if(n.has(o.name))continue;let s=`${o.namespace??"utils"}.${o.name}`;if(t.has(s)){if(this._parentSharedAgentFunctions.has(s))throw new Error(`Duplicate shared agent function "${s}" \u2014 already propagated from a parent`);continue}this._parentSharedAgentFunctions.add(s),t.add(s),r.push(o)}r.length!==0&&(this.agentFunctions=[...this.agentFunctions,...r],this._buildSplitPrograms())}_extendForGlobalSharedAgentFunctions(e){let t=this.agents?this.agents.filter(n=>n instanceof i):[];this._extendForSharedAgentFunctions(e);for(let n of t)n._extendForGlobalSharedAgentFunctions(e)}stop(){this._stopRequested=!0;for(let e of this.activeAbortControllers)e.abort("Stopped by user");this.program.stop(),this.actorProgram.stop(),this.responderProgram.stop()}getId(){return this.program.getId()}setId(e){this.program.setId(e)}namedPrograms(){return this.program.namedPrograms()}getTraces(){return this.program.getTraces()}setDemos(e,t){this.program.setDemos(e,t)}getUsage(){return this.program.getUsage()}resetUsage(){this.program.resetUsage()}getFunction(){if(!this.func)throw new Error("getFunction() requires agentIdentity to be set in the constructor");let e=this.forward.bind(this);return{...this.func,func:async(r,o)=>{let s=this.ai??o?.ai;if(!s)throw new Error("AI service is required to run the agent");let a=await e(s,r,o),u=this.program.getSignature().getOutputFields();return Object.keys(a).map(p=>{let d=u.find(m=>m.name===p);return d?`${d.title}: ${a[p]}`:`${p}: ${a[p]}`}).join(`
|
|
786
786
|
`)}}}getExcludedSharedFields(){return this.excludedSharedFields}getExcludedAgents(){return this.excludedAgents}getExcludedAgentFunctions(){return this.excludedAgentFunctions}getSignature(){return this.program.getSignature()}setSignature(e){this.program.setSignature(e)}applyOptimization(e){this.program.applyOptimization?.(e)}async _runActorLoop(e,t,n,r){let o=this.rlmConfig,s=this.runtime,a=n?.debug??this.debug??e?.getOptions()?.debug??!1,l={},u={},c;Array.isArray(t)?c=t.filter(D=>D.role==="user").reduce((D,Z)=>({...D,...Z.values}),{}):c=t;let p=[...this.sharedFieldNames,...this.globalSharedFieldNames];for(let[D,Z]of Object.entries(c))o.contextFields.includes(D)?l[D]=Z:p.includes(D)||(u[D]=Z);let d={};for(let D of p)D in c&&(d[D]=c[D]),D in l&&(d[D]=l[D]);for(let D of o.contextFields)if(!(D in l))throw new Error(`RLM contextField "${D}" is missing from input values`);let m=o.maxLlmCalls??bc,g=o.maxRuntimeChars??rm,h=Math.max(1,o.maxBatchedLlmQueryConcurrency??om),f=o.maxTurns??Ic,y=0,x=Math.floor(m*.8),A=this.recursionForwardOptions?.maxDepth??sm,R=Math.max(0,A),{maxDepth:b,...T}=this.recursionForwardOptions??{},{functions:O,description:N,mem:M,sessionId:U,...B}=n??{},$={...this.recursionForwardOptions??{},maxDepth:Math.max(0,R-1)},I=["context"],k=xe().input("task",xe.string("Task for recursive analysis")).input("context",xe.json("Optional context for the recursive task")).output("answer",xe.string("Answer from recursive analysis")).build(),F=(o.mode??"simple")==="advanced"&&($.maxDepth??0)>0?"advanced":"simple",v;R>0&&(F==="advanced"?v=new i({signature:k},{debug:a,...o,agents:{local:this.agents},functions:{local:this.agentFunctions},contextFields:I,actorFields:void 0,recursionOptions:$,actorOptions:this.actorForwardOptions,responderOptions:this.responderForwardOptions}):v=new Se(k,$));let P=D=>{if(D==null)return"";if(typeof D=="string")return Ct(D,g);try{return Ct(JSON.stringify(D),g)}catch{return Ct(String(D),g)}},j=async(D,Z)=>{if(!Array.isArray(D)&&typeof D=="object"&&D!==null&&"query"in D)return j(D.query,D.context??Z);if(r?.aborted)throw new Fe("rlm-llm-query",r.reason?String(r.reason):"Aborted");if(Array.isArray(D))return lm(D,h,async ge=>{try{return await j(ge.query,ge.context)}catch(J){if(J instanceof Fe)throw J;return`[ERROR] ${J instanceof Error?J.message:String(J)}`}});let le=await(async(ge,J)=>{let te=J===void 0?void 0:typeof J=="string"?Ct(J,g):J;if(y++,y>m)return`[ERROR] Sub-query budget exhausted (${m}/${m}). Use the data you have already accumulated to produce your final answer.`;if(R<=0||!v)return`[ERROR] Recursion depth limit reached (${A}).`;let ne=3,Ae;for(let ye=0;ye<ne;ye++)try{let ce=await v.forward(e,{task:ge,...te!==void 0?{context:te}:F==="advanced"?{context:""}:{}},{...B,...T,abortSignal:r,debug:a});return P(ce.answer)}catch(ce){if(Ae=ce,!im(ce)||ye>=ne-1)throw ce;let ut=Math.min(6e4,1e3*Math.pow(2,ye));await new Promise((ft,Je)=>{let Ye=!1,Ke,tt=()=>{r&&Ke&&r.removeEventListener("abort",Ke)},wt=setTimeout(()=>{Ye||(Ye=!0,tt(),ft())},ut);if(r){if(Ke=()=>{Ye||(Ye=!0,clearTimeout(wt),tt(),Je(new Fe("rlm-llm-query-retry-backoff",r.reason?String(r.reason):"Aborted during retry backoff")))},r.aborted){Ke();return}r.addEventListener("abort",Ke,{once:!0})}})}throw Ae})(D,Z);return y===x?`${le}
|
|
787
787
|
[WARNING] ${y}/${m} sub-queries used. Plan to wrap up soon.`:le},L=this.buildRuntimeGlobals(r,d,e),K,ie=(D,Z)=>{if(Z.length===0)throw new Error(`${D}() requires at least one argument`);K={type:D,args:Z}},H=(...D)=>ie("final",D),Q=(...D)=>ie("ask_clarification",D),pe=["llmQuery","agents","final","ask_clarification",...[...new Set(this.agentFunctions.map(D=>D.namespace??"utils"))],...o.contextManagement?.stateInspection?["inspect_runtime"]:[],...o.contextFields,...Object.keys(L)],Ie=o.contextManagement?.stateInspection?async()=>{try{let D=yc(pe),Z=await Re.execute(D,{signal:r,reservedNames:pe});return typeof Z=="string"?Z:String(Z)}catch(D){return`[inspect_runtime error: ${D instanceof Error?D.message:String(D)}]`}}:void 0,re=()=>s.createSession({...l,llmQuery:j,final:H,ask_clarification:Q,...Ie?{inspect_runtime:Ie}:{},...L}),be="[The JavaScript runtime was restarted; all global state was lost and must be recreated if needed.]",Re=re(),Te=!1,ke=D=>D instanceof Error&&D.message==="Session is closed",w=D=>D instanceof Error&&D.message==="Execution timed out",_=D=>{if(D===void 0)return"(no output)";if(typeof D=="string")return Ct(D||"(no output)",g);try{return Ct(JSON.stringify(D,null,2),g)}catch{return Ct(String(D),g)}},S=D=>{let Z=D,ae=Z?.name??"Error",ue=Z?.message??String(D),le=[`${ae}: ${ue}`];if(Z?.data!==void 0)try{le.push(`Data: ${JSON.stringify(Z.data,null,2)}`)}catch{le.push(`Data: ${String(Z.data)}`)}if(Z?.cause!==void 0){let ge=(J,te)=>{if(te>4)return"[cause chain truncated]";let ne=J,Ae=ne?.name??"Error",ye=ne?.message??String(J),ce=[`${Ae}: ${ye}`];if(ne?.data!==void 0)try{ce.push(`Data: ${JSON.stringify(ne.data,null,2)}`)}catch{ce.push(`Data: ${String(ne.data)}`)}return ne?.cause!==void 0&&ce.push(`Caused by: ${ge(ne.cause,te+1)}`),ce.join(`
|
|
788
788
|
`)};le.push(`Caused by: ${ge(Z.cause,1)}`)}return Ct(le.join(`
|