@ax-llm/ax 18.0.10 → 18.0.11
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 +1 -1
- package/index.cjs.map +1 -1
- package/index.global.js +1 -1
- package/index.global.js.map +1 -1
- package/index.js +1 -1
- 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.cjs
CHANGED
|
@@ -780,7 +780,7 @@ ${e.output}${e.actorFieldsOutput}`).join(`
|
|
|
780
780
|
} catch { preview = String(v).slice(0, 80); }
|
|
781
781
|
return k + ': ' + type + (size ? ' (' + size + ')' : '') + ' = ' + preview;
|
|
782
782
|
}).join('\\n') || '(no user variables)';
|
|
783
|
-
})()`}var Cu=50,Lp=5e3,$p=8,Tu=10,Gp=2,Pr=class i{ai;program;actorProgram;responderProgram;functions;agents;debug;options;rlmConfig;runtime;actorFieldNames;sharedFieldNames;excludedSharedFields;actorDescription;responderDescription;recursionForwardOptions;actorForwardOptions;responderForwardOptions;activeAbortControllers=new Set;_stopRequested=!1;func;_parentSharedFields=new Set;constructor({ai:e,agentIdentity:t,signature:n,agents:r,functions:o},s){let{debug:a,contextFields:l,runtime:u,maxLlmCalls:c,maxRuntimeChars:p,maxBatchedLlmQueryConcurrency:d,maxTurns:m,trajectoryPruning:g,contextManagement:h,actorFields:f,actorCallback:y,mode:x,recursionOptions:A,actorOptions:w,responderOptions:I}=s;this.ai=e,this.agents=r,this.functions=o,this.debug=a,this.options=s,this.runtime=u??new jt,this.rlmConfig={contextFields:l,sharedFields:s.sharedFields,runtime:this.runtime,maxLlmCalls:c,maxRuntimeChars:p,maxBatchedLlmQueryConcurrency:d,maxTurns:m,trajectoryPruning:g,contextManagement:h,actorFields:f,actorCallback:y,mode:x},this.recursionForwardOptions=A;let{description:T,...S}=w??{},{description:_,...P}=I??{};this.actorDescription=T,this.actorForwardOptions=S,this.responderDescription=_,this.responderForwardOptions=P,this.program=new we(n,{...s});for(let G of r??[]){let F=G.getFunction().name;this.program.register(G,F)}t&&(this.func={name:qp(t.name),description:t.description,parameters:this._buildFuncParameters(),func:async()=>{throw new Error("Use getFunction() to get a callable wrapper")}});let $=this.program.getSignature().getInputFields();for(let G of l)if(!$.some(F=>F.name===G))throw new Error(`RLM contextField "${G}" 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 U=this.program.getSignature().getOutputFields(),K=f??[];this.actorFieldNames=K;for(let G of K)if(!U.some(F=>F.name===G))throw new Error(`RLM actorField "${G}" not found in output signature`);let O=s.sharedFields??[];this.sharedFieldNames=O;for(let G of O)if(!$.some(F=>F.name===G))throw new Error(`sharedField "${G}" not found in signature input fields`);if(this.excludedSharedFields=s.excludeSharedFields??[],O.length>0&&r){let G=$.filter(F=>O.includes(F.name));for(let F of r){if(!(F instanceof i))continue;let J=new Set(F.getExcludedSharedFields()),M=G.filter(D=>!J.has(D.name));M.length!==0&&F._extendForSharedFields(M,l)}}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,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=he().addInputFields(o).input("contextMetadata",he.string("Metadata about pre-loaded context variables (type and size)")).input("actionLog",he.string("Chronological trace of code executions or actions and their outputs so far")).output("javascriptCode",he.code("JavaScript code to execute in runtime session"));a.length>0&&(u=u.addOutputFields(a));let c=u.build(),p=he().addInputFields(o).input("contextData",he.json("Context data to help synthesize the final answer.")).addOutputFields(l).build(),d=this.rlmConfig.maxLlmCalls??Cu,m=this.rlmConfig.maxTurns??Tu,g=this.agents?.map(x=>{let A=x.getFunction();return{name:A.name,description:A.description,parameters:A.parameters}})??[],h=this.collectFunctions().map(x=>({name:x.name,description:x.description,parameters:x.parameters})),f=us(this.actorDescription,r,l,{runtimeUsageInstructions:this.runtime.getUsageInstructions(),maxLlmCalls:d,maxTurns:m,hasInspectRuntime:!!this.rlmConfig.contextManagement?.stateInspection,agents:g,functions:h}),y=cs(this.responderDescription,r);this.actorProgram=new we(c,{...this.options,description:f}),this.responderProgram=new we(p,{...this.options,description:y})}_extendForSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e)r.some(a=>a.name===s.name)||(
|
|
783
|
+
})()`}var Cu=50,Lp=5e3,$p=8,Tu=10,Gp=2,Pr=class i{ai;program;actorProgram;responderProgram;functions;agents;debug;options;rlmConfig;runtime;actorFieldNames;sharedFieldNames;excludedSharedFields;actorDescription;responderDescription;recursionForwardOptions;actorForwardOptions;responderForwardOptions;activeAbortControllers=new Set;_stopRequested=!1;func;_parentSharedFields=new Set;constructor({ai:e,agentIdentity:t,signature:n,agents:r,functions:o},s){let{debug:a,contextFields:l,runtime:u,maxLlmCalls:c,maxRuntimeChars:p,maxBatchedLlmQueryConcurrency:d,maxTurns:m,trajectoryPruning:g,contextManagement:h,actorFields:f,actorCallback:y,mode:x,recursionOptions:A,actorOptions:w,responderOptions:I}=s;this.ai=e,this.agents=r,this.functions=o,this.debug=a,this.options=s,this.runtime=u??new jt,this.rlmConfig={contextFields:l,sharedFields:s.sharedFields,runtime:this.runtime,maxLlmCalls:c,maxRuntimeChars:p,maxBatchedLlmQueryConcurrency:d,maxTurns:m,trajectoryPruning:g,contextManagement:h,actorFields:f,actorCallback:y,mode:x},this.recursionForwardOptions=A;let{description:T,...S}=w??{},{description:_,...P}=I??{};this.actorDescription=T,this.actorForwardOptions=S,this.responderDescription=_,this.responderForwardOptions=P,this.program=new we(n,{...s});for(let G of r??[]){let F=G.getFunction().name;this.program.register(G,F)}t&&(this.func={name:qp(t.name),description:t.description,parameters:this._buildFuncParameters(),func:async()=>{throw new Error("Use getFunction() to get a callable wrapper")}});let $=this.program.getSignature().getInputFields();for(let G of l)if(!$.some(F=>F.name===G))throw new Error(`RLM contextField "${G}" 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 U=this.program.getSignature().getOutputFields(),K=f??[];this.actorFieldNames=K;for(let G of K)if(!U.some(F=>F.name===G))throw new Error(`RLM actorField "${G}" not found in output signature`);let O=s.sharedFields??[];this.sharedFieldNames=O;for(let G of O)if(!$.some(F=>F.name===G))throw new Error(`sharedField "${G}" not found in signature input fields`);if(this.excludedSharedFields=s.excludeSharedFields??[],O.length>0&&r){let G=$.filter(F=>O.includes(F.name));for(let F of r){if(!(F instanceof i))continue;let J=new Set(F.getExcludedSharedFields()),M=G.filter(D=>!J.has(D.name));M.length!==0&&F._extendForSharedFields(M,l)}}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,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=he().addInputFields(o).input("contextMetadata",he.string("Metadata about pre-loaded context variables (type and size)")).input("actionLog",he.string("Chronological trace of code executions or actions and their outputs so far")).output("javascriptCode",he.code("JavaScript code to execute in runtime session"));a.length>0&&(u=u.addOutputFields(a));let c=u.build(),p=he().addInputFields(o).input("contextData",he.json("Context data to help synthesize the final answer.")).addOutputFields(l).build(),d=this.rlmConfig.maxLlmCalls??Cu,m=this.rlmConfig.maxTurns??Tu,g=this.agents?.map(x=>{let A=x.getFunction();return{name:A.name,description:A.description,parameters:A.parameters}})??[],h=this.collectFunctions().map(x=>({name:x.name,description:x.description,parameters:x.parameters})),f=us(this.actorDescription,r,l,{runtimeUsageInstructions:this.runtime.getUsageInstructions(),maxLlmCalls:d,maxTurns:m,hasInspectRuntime:!!this.rlmConfig.contextManagement?.stateInspection,agents:g,functions:h}),y=cs(this.responderDescription,r);this.actorProgram=new we(c,{...this.options,description:f}),this.responderProgram=new we(p,{...this.options,description:y})}_extendForSharedFields(e,t){let n=this.program.getSignature(),r=n.getInputFields(),o=!1;for(let s of e)r.some(a=>a.name===s.name)||(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())}collectFunctions(){let e=[];if(this.functions)for(let t of this.functions)typeof t=="object"&&"func"in t&&e.push(t);return 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(`
|
|
784
784
|
`)}}}getExcludedSharedFields(){return this.excludedSharedFields}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(v=>v.role==="user").reduce((v,j)=>({...v,...j.values}),{}):c=t;let p=this.sharedFieldNames;for(let[v,j]of Object.entries(c))o.contextFields.includes(v)?l[v]=j:p.includes(v)||(u[v]=j);let d={};for(let v of p)v in c&&(d[v]=c[v]),v in l&&(d[v]=l[v]);for(let v of o.contextFields)if(!(v in l))throw new Error(`RLM contextField "${v}" is missing from input values`);let m=o.maxLlmCalls??Cu,g=o.maxRuntimeChars??Lp,h=Math.max(1,o.maxBatchedLlmQueryConcurrency??$p),f=o.maxTurns??Tu,y=0,x=Math.floor(m*.8),A=this.recursionForwardOptions?.maxDepth??Gp,w=Math.max(0,A),{maxDepth:I,...T}=this.recursionForwardOptions??{},{functions:S,description:_,mem:P,sessionId:$,...U}=n??{},K={...this.recursionForwardOptions??{},maxDepth:Math.max(0,w-1)},O=["context"],G=he().input("task",he.string("Task for recursive analysis")).input("context",he.json("Optional context for the recursive task")).output("answer",he.string("Answer from recursive analysis")).build(),J=(o.mode??"simple")==="advanced"&&(K.maxDepth??0)>0?"advanced":"simple",M;w>0&&(J==="advanced"?M=new i({signature:G,agents:this.agents,functions:this.functions},{debug:a,...o,contextFields:O,actorFields:void 0,recursionOptions:K,actorOptions:this.actorForwardOptions,responderOptions:this.responderForwardOptions}):M=new we(G,K));let D=v=>{if(v==null)return"";if(typeof v=="string")return It(v,g);try{return It(JSON.stringify(v),g)}catch{return It(String(v),g)}},Y=async(v,j)=>{if(!Array.isArray(v)&&typeof v=="object"&&v!==null&&"query"in v)return Y(v.query,v.context??j);if(r?.aborted)throw new Oe("rlm-llm-query",r.reason?String(r.reason):"Aborted");if(Array.isArray(v))return Bp(v,h,async le=>{try{return await Y(le.query,le.context)}catch(oe){if(oe instanceof Oe)throw oe;return`[ERROR] ${oe instanceof Error?oe.message:String(oe)}`}});let ie=await(async(le,oe)=>{let V=oe===void 0?void 0:typeof oe=="string"?It(oe,g):oe;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(w<=0||!M)return`[ERROR] Recursion depth limit reached (${A}).`;let W=3,ee;for(let fe=0;fe<W;fe++)try{let ue=await M.forward(e,{task:le,...V!==void 0?{context:V}:J==="advanced"?{context:""}:{}},{...U,...T,abortSignal:r,debug:a});return D(ue.answer)}catch(ue){if(ee=ue,!Dp(ue)||fe>=W-1)throw ue;let xe=Math.min(6e4,1e3*Math.pow(2,fe));await new Promise((st,mt)=>{let $e=!1,Ke,it=()=>{r&&Ke&&r.removeEventListener("abort",Ke)},ht=setTimeout(()=>{$e||($e=!0,it(),st())},xe);if(r){if(Ke=()=>{$e||($e=!0,clearTimeout(ht),it(),mt(new Oe("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 ee})(v,j);return y===x?`${ie}
|
|
785
785
|
[WARNING] ${y}/${m} sub-queries used. Plan to wrap up soon.`:ie},N=this.buildRuntimeGlobals(r,d),X,Ae=(v,j)=>{if(j.length===0)throw new Error(`${v}() requires at least one argument`);X={type:v,args:j}},ae=(...v)=>Ae("final",v),se=(...v)=>Ae("ask_clarification",v),re=["llmQuery","agents","final","ask_clarification",...o.contextManagement?.stateInspection?["inspect_runtime"]:[],...o.contextFields,...Object.keys(N)],Ie=o.contextManagement?.stateInspection?async()=>{try{let v=Iu(re),j=await Ce.execute(v,{signal:r,reservedNames:re});return typeof j=="string"?j:String(j)}catch(v){return`[inspect_runtime error: ${v instanceof Error?v.message:String(v)}]`}}:void 0,Le=()=>s.createSession({...l,llmQuery:Y,final:ae,ask_clarification:se,...Ie?{inspect_runtime:Ie}:{},...N}),ge="[The JavaScript runtime was restarted; all global state was lost and must be recreated if needed.]",Ce=Le(),je=!1,Fe=v=>v instanceof Error&&v.message==="Session is closed",Me=v=>v instanceof Error&&v.message==="Execution timed out",C=v=>{if(v===void 0)return"(no output)";if(typeof v=="string")return It(v||"(no output)",g);try{return It(JSON.stringify(v,null,2),g)}catch{return It(String(v),g)}},k=v=>{let j=v,te=j?.name??"Error",ne=j?.message??String(v),ie=[`${te}: ${ne}`];if(j?.data!==void 0)try{ie.push(`Data: ${JSON.stringify(j.data,null,2)}`)}catch{ie.push(`Data: ${String(j.data)}`)}if(j?.cause!==void 0){let le=(oe,V)=>{if(V>4)return"[cause chain truncated]";let W=oe,ee=W?.name??"Error",fe=W?.message??String(oe),ue=[`${ee}: ${fe}`];if(W?.data!==void 0)try{ue.push(`Data: ${JSON.stringify(W.data,null,2)}`)}catch{ue.push(`Data: ${String(W.data)}`)}return W?.cause!==void 0&&ue.push(`Caused by: ${le(W.cause,V+1)}`),ue.join(`
|
|
786
786
|
`)};ie.push(`Caused by: ${le(j.cause,1)}`)}return It(ie.join(`
|