MCPcopy Create free account
hub / github.com/Roy3838/Observer / generateAgentFromSimpleConfig

Function generateAgentFromSimpleConfig

app/src/utils/agentTemplateManager.ts:178–218  ·  view source on GitHub ↗
(
  config: SimpleConfig
)

Source from the content-addressed store, hash-verified

176}
177
178export function generateAgentFromSimpleConfig(
179 config: SimpleConfig
180): { agent: CompleteAgent; code: string } {
181
182 const comments = [
183 '// This code was auto-generated by the Simple Agent Creator.',
184 '// You can edit it to add more complex logic.',
185 ].join('\n');
186
187 const systemPrompt = config.agentData.system_prompt || '';
188 const ctx: SensorContext = {
189 hasScreen: /\$SCREEN(?![A-Z_])/.test(systemPrompt),
190 hasCamera: /\$CAMERA(?![A-Z_])/.test(systemPrompt),
191 };
192
193 let toolCode = Array.from(config.selectedTools.entries())
194 .map(([tool, data]) => TOOL_CODE_SNIPPETS[tool](data, ctx).trim())
195 .join('\n\n');
196
197 if (config.condition.enabled && config.condition.keyword) {
198 const safeKeyword = JSON.stringify(config.condition.keyword.toLowerCase()).slice(1, -1);
199 const indentedToolCode = ` ${toolCode.replace(/\n/g, '\n ')}`;
200 toolCode = `if (response.toLowerCase().includes('${safeKeyword}')) {\n${indentedToolCode}\n}`;
201 }
202
203 const finalCode = `${comments}\n\n${toolCode}`;
204
205 const agent: CompleteAgent = {
206 id: config.agentData.id || `agent_${Date.now()}`,
207 name: config.agentData.name || 'My New Agent',
208 description: config.agentData.description || 'An agent created with the Simple Creator.',
209 model_name: config.agentData.model_name || '',
210 system_prompt: config.agentData.system_prompt || '',
211 loop_interval_seconds: config.agentData.loop_interval_seconds || 60,
212 };
213
214 return {
215 agent,
216 code: finalCode,
217 };
218}

Callers 1

handleSimpleCreatorNextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected