PYAE1994 commited on
Commit
2f78ff4
·
verified ·
1 Parent(s): b07943b

Fix: update agents/ui_agent.py

Browse files
Files changed (1) hide show
  1. agents/ui_agent.py +28 -14
agents/ui_agent.py CHANGED
@@ -1,19 +1,24 @@
1
  """
2
- UIAgent — UI generation and component suggestions via LLMRouter
3
  """
4
- import structlog
5
  from typing import Dict
 
6
  from .base_agent import BaseAgent
7
 
8
  log = structlog.get_logger()
9
 
10
- UI_SYSTEM = """You are a senior frontend engineer specializing in React, Next.js, and Tailwind CSS.
11
- Generate production-ready UI components with:
12
- - TypeScript types
13
- - Responsive design
14
- - Accessibility (ARIA)
 
 
 
15
  - Dark mode support
16
- - Clean, readable code"""
 
 
17
 
18
 
19
  class UIAgent(BaseAgent):
@@ -21,11 +26,20 @@ class UIAgent(BaseAgent):
21
  super().__init__("UIAgent", ws_manager, ai_router)
22
 
23
  async def run(self, task: str, context: Dict = {}, **kwargs) -> str:
24
- session_id = kwargs.get("session_id", context.get("session_id", ""))
25
- task_id = kwargs.get("task_id", context.get("task_id", ""))
26
- messages = [
 
 
 
27
  {"role": "system", "content": UI_SYSTEM},
28
- {"role": "user", "content": f"Create a UI component for: {task}"},
 
 
 
 
 
29
  ]
30
- await self.emit(task_id, "ui_generation_started", {"task": task[:100]}, session_id)
31
- return await self.ask_llm(messages=messages, task_id=task_id, session_id=session_id, temperature=0.5)
 
 
1
  """
2
+ UIAgent — UI component generation (React/Next.js/Tailwind)
3
  """
 
4
  from typing import Dict
5
+ import structlog
6
  from .base_agent import BaseAgent
7
 
8
  log = structlog.get_logger()
9
 
10
+ UI_SYSTEM = """You are an expert React/Next.js/Tailwind CSS UI engineer.
11
+ You generate beautiful, responsive, production-ready UI components.
12
+ Always use:
13
+ - TypeScript with proper types
14
+ - Tailwind CSS for styling
15
+ - shadcn/ui components when appropriate
16
+ - Framer Motion for animations
17
+ - Lucide React for icons
18
  - Dark mode support
19
+ - Mobile-first responsive design
20
+ - Accessibility (aria labels, semantic HTML)
21
+ """
22
 
23
 
24
  class UIAgent(BaseAgent):
 
26
  super().__init__("UIAgent", ws_manager, ai_router)
27
 
28
  async def run(self, task: str, context: Dict = {}, **kwargs) -> str:
29
+ session_id = kwargs.get("session_id", "")
30
+ task_id = kwargs.get("task_id", "")
31
+
32
+ await self.emit(task_id, "agent_start", {"agent": "UIAgent", "task": task[:80]}, session_id)
33
+
34
+ messages = [
35
  {"role": "system", "content": UI_SYSTEM},
36
+ {"role": "user", "content": (
37
+ f"Generate a complete, production-ready UI component for: {task}\n\n"
38
+ f"Requirements:\n"
39
+ f"- TypeScript\n- Tailwind CSS\n- Dark mode\n- Mobile responsive\n"
40
+ f"- Include all imports\n- Export as default"
41
+ )},
42
  ]
43
+ result = await self.llm(messages, task_id=task_id, session_id=session_id, temperature=0.3, max_tokens=6000)
44
+ await self.emit(task_id, "ui_generated", {"agent": "UIAgent"}, session_id)
45
+ return result