@@ -14,6 +14,7 @@ import { AgentRunner } from './executor/AgentRunner'
1414import { decodeBase64string } from './utils/base64converter'
1515import { validateToken } from './utils/validator'
1616import { getHandlers } from './executor/AgentFunctions'
17+ import { LLMGatedRunner } from './executor/LlmGatedRunner'
1718
1819configDotenv ( )
1920let wsUrl : string = process . env . WS_URL as string
@@ -62,7 +63,7 @@ function connectToManagerWebSocket() {
6263 const managerInterface = new ManagerInterface ( rpcChannel )
6364 const txListener = new TxListener ( )
6465
65- const agentRunners : Array < AgentRunner > = [ ]
66+ const agentRunners : Array < any > = [ ]
6667
6768 rpcChannel . on ( 'methodCall' , ( method , args ) => {
6869 agentRunners . forEach ( ( runner , index ) => {
@@ -71,14 +72,58 @@ function connectToManagerWebSocket() {
7172 } )
7273
7374 const topicHandler = new RpcTopicHandler ( managerInterface , txListener )
75+
76+ // LLM settings extractor from configurations
77+ function applyFnSettingsFromConfigurations ( message : any ) {
78+ if ( ! message ?. configurations ) return
79+ globalState . functionLLMSettings = { }
80+ message . configurations . forEach ( ( cfg : any ) => {
81+ const act = cfg ?. action || { }
82+ if ( act . function_name ) {
83+ globalState . functionLLMSettings [ act . function_name ] = {
84+ enabled : ! ! act . llm_enabled ,
85+ userPrefText : act . llm_user_preferences_text || '' ,
86+ prefs : act . llm_preferences || undefined ,
87+ }
88+ }
89+ } )
90+ console . log ( '[INIT] LLM settings for:' , Object . keys ( globalState . functionLLMSettings ) )
91+ }
92+
93+ // loads the system prompt
94+ function applySystemPromptFromMessage ( message : any , logCtx : string ) {
95+ const prompt = message ?. agentConfig ?. system_prompt ?? message ?. config ?. system_prompt
96+
97+ if ( typeof prompt === 'string' && prompt . length && prompt !== globalState . systemPrompt ) {
98+ globalState . systemPrompt = prompt
99+ }
100+ }
101+
74102 rpcChannel . on ( 'event' , ( topic , message ) => {
103+ // initial payload containing configs
104+ if ( topic === 'initial_config' ) {
105+ applySystemPromptFromMessage ( message , 'initial_config' )
106+ applyFnSettingsFromConfigurations ( message )
107+ return
108+ }
109+
110+ // config updates from manager
111+ if ( topic === 'config_updated' ) {
112+ applyFnSettingsFromConfigurations ( message )
113+ applySystemPromptFromMessage ( message , 'initial_config' )
114+ }
115+
75116 if ( topic == 'instance_count' ) {
117+ applySystemPromptFromMessage ( message , 'initial_config' )
118+ applyFnSettingsFromConfigurations ( message )
119+
76120 globalRootKeyBuffer . value = message . rootKeyBuffer
77121 globalState . agentName = message . agentName
78122 Array ( message . instanceCount )
79123 . fill ( '' )
80124 . forEach ( async ( item , index ) => {
81- const runner = new AgentRunner ( managerInterface , txListener )
125+ const coreRunner = new AgentRunner ( managerInterface , txListener )
126+ const runner = new LLMGatedRunner ( coreRunner )
82127 await runner . remakeContext ( index )
83128 agentRunners . push ( runner )
84129 } )
0 commit comments