( baseSystemPrompt: string, referenceData: AgentReferenceData[] )
| 478 | * @returns Enhanced system prompt with agent context |
| 479 | */ |
| 480 | export function buildSystemPromptWithAgentContext( |
| 481 | baseSystemPrompt: string, |
| 482 | referenceData: AgentReferenceData[] |
| 483 | ): string { |
| 484 | let systemPrompt = baseSystemPrompt; |
| 485 | |
| 486 | if (referenceData.length > 0) { |
| 487 | systemPrompt += "\n\n=== REFERENCED AGENTS ===\n"; |
| 488 | systemPrompt += "The user has referenced the following agents for editing/improvement:\n\n"; |
| 489 | |
| 490 | referenceData.forEach(data => { |
| 491 | const { reference, agent, code, memory, recentRuns } = data; |
| 492 | |
| 493 | if (!agent) { |
| 494 | systemPrompt += `## @${reference.agentId} - AGENT NOT FOUND\n`; |
| 495 | systemPrompt += `The user referenced @${reference.agentId} but this agent doesn't exist.\n\n`; |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | systemPrompt += `## @${reference.agentId} - ${agent.name}\n`; |
| 500 | systemPrompt += `Description: ${agent.description}\n`; |
| 501 | systemPrompt += `Model: ${agent.model_name}\n`; |
| 502 | systemPrompt += `Loop Interval: ${agent.loop_interval_seconds}s\n\n`; |
| 503 | |
| 504 | // Add system prompt |
| 505 | systemPrompt += `### System Prompt:\n`; |
| 506 | systemPrompt += `${agent.system_prompt}\n\n`; |
| 507 | |
| 508 | // Add code if available |
| 509 | if (code) { |
| 510 | systemPrompt += `### Code:\n`; |
| 511 | systemPrompt += `\`\`\`python\n${code}\n\`\`\`\n\n`; |
| 512 | } |
| 513 | |
| 514 | // Add memory if not empty |
| 515 | if (memory.trim()) { |
| 516 | systemPrompt += `### Memory:\n`; |
| 517 | systemPrompt += `${memory.substring(0, 500)}${memory.length > 500 ? '...' : ''}\n\n`; |
| 518 | } |
| 519 | |
| 520 | // Add recent performance data |
| 521 | if (recentRuns.length > 0) { |
| 522 | systemPrompt += `### Recent Performance (last ${recentRuns.length} runs):\n`; |
| 523 | |
| 524 | const successCount = recentRuns.filter(run => !run.hasError).length; |
| 525 | systemPrompt += `Success Rate: ${successCount}/${recentRuns.length}\n`; |
| 526 | |
| 527 | if (recentRuns.some(run => run.duration)) { |
| 528 | const avgDuration = recentRuns |
| 529 | .filter(run => run.duration) |
| 530 | .reduce((sum, run) => sum + (run.duration || 0), 0) / recentRuns.length; |
| 531 | systemPrompt += `Average Duration: ${avgDuration.toFixed(1)}s\n`; |
| 532 | } |
| 533 | |
| 534 | // Add detailed run information |
| 535 | recentRuns.forEach((run, i) => { |
| 536 | systemPrompt += `\n#### Run ${i + 1} (${new Date(run.startTime).toLocaleString()}):\n`; |
| 537 | systemPrompt += `Status: ${run.hasError ? 'FAILED' : 'SUCCESS'}\n`; |
nothing calls this directly
no outgoing calls
no test coverage detected