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

Function generateAgentFromSimpleConfig

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

Source from the content-addressed store, hash-verified

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

Callers 1

handleSimpleCreatorNextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected