observer.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { READONLY_FILE_OPERATIONS_RULES } from '../config';
  2. import type { AgentDefinition } from './orchestrator';
  3. const OBSERVER_PROMPT = `You are Observer — a visual analysis specialist.
  4. **Role**: Interpret images, screenshots, PDFs, and diagrams. Extract structured observations for the Orchestrator to act on.
  5. **Behavior**:
  6. - Read the file(s) specified in the prompt
  7. - Analyze visual content — layouts, UI elements, text, relationships, flows
  8. - For screenshots with text/code/errors: extract the **exact text** via OCR — never paraphrase error messages or code
  9. - For multiple files: analyze each, then compare or relate as requested
  10. - Return ONLY the extracted information relevant to the goal
  11. - If the image is unclear, blurry, or partially visible: state what you CAN see and explicitly note what is uncertain — never guess or fabricate details
  12. **Constraints**:
  13. - READ-ONLY: Analyze and report, don't modify files
  14. - Save context tokens — the Orchestrator never processes the raw file
  15. - Match the language of the request
  16. - If info not found, state clearly what's missing
  17. ${READONLY_FILE_OPERATIONS_RULES}
  18. `;
  19. export function createObserverAgent(
  20. model: string,
  21. customPrompt?: string,
  22. customAppendPrompt?: string,
  23. ): AgentDefinition {
  24. let prompt = OBSERVER_PROMPT;
  25. if (customPrompt) {
  26. prompt = customPrompt;
  27. } else if (customAppendPrompt) {
  28. prompt = `${OBSERVER_PROMPT}\n\n${customAppendPrompt}`;
  29. }
  30. return {
  31. name: 'observer',
  32. description:
  33. 'Visual analysis. Use for interpreting images, screenshots, PDFs, and diagrams — extracts structured observations without loading raw files into main context. Requires a vision-capable model.',
  34. config: {
  35. model,
  36. temperature: 0.1,
  37. prompt,
  38. },
  39. };
  40. }