Fix: update agents/chat_agent.py
Browse files- agents/chat_agent.py +30 -21
agents/chat_agent.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
| 1 |
"""
|
| 2 |
-
ChatAgent — Conversational
|
| 3 |
"""
|
| 4 |
-
import structlog
|
| 5 |
from typing import Dict
|
|
|
|
| 6 |
from .base_agent import BaseAgent
|
| 7 |
|
| 8 |
log = structlog.get_logger()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
You
|
| 12 |
-
Be
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
class ChatAgent(BaseAgent):
|
|
@@ -17,19 +20,25 @@ class ChatAgent(BaseAgent):
|
|
| 17 |
super().__init__("ChatAgent", ws_manager, ai_router)
|
| 18 |
|
| 19 |
async def run(self, task: str, context: Dict = {}, **kwargs) -> str:
|
| 20 |
-
session_id = kwargs.get("session_id",
|
| 21 |
-
task_id
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
]
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
ChatAgent — Conversational interface with streaming, Burmese support
|
| 3 |
"""
|
|
|
|
| 4 |
from typing import Dict
|
| 5 |
+
import structlog
|
| 6 |
from .base_agent import BaseAgent
|
| 7 |
|
| 8 |
log = structlog.get_logger()
|
| 9 |
|
| 10 |
+
CHAT_SYSTEM = """You are God Agent — an elite autonomous AI operating system.
|
| 11 |
+
You support both English and Burmese (မြန်မာဘာသာ) languages.
|
| 12 |
+
Be helpful, precise, and autonomous.
|
| 13 |
+
When users write in Burmese, respond in Burmese.
|
| 14 |
+
When discussing code, provide production-quality examples.
|
| 15 |
+
"""
|
| 16 |
|
| 17 |
|
| 18 |
class ChatAgent(BaseAgent):
|
|
|
|
| 20 |
super().__init__("ChatAgent", ws_manager, ai_router)
|
| 21 |
|
| 22 |
async def run(self, task: str, context: Dict = {}, **kwargs) -> str:
|
| 23 |
+
session_id = kwargs.get("session_id", "")
|
| 24 |
+
task_id = kwargs.get("task_id", "")
|
| 25 |
+
|
| 26 |
+
history = context.get("history", [])
|
| 27 |
+
messages = [{"role": "system", "content": CHAT_SYSTEM}]
|
| 28 |
+
|
| 29 |
+
for h in history[-10:]:
|
| 30 |
+
messages.append({"role": h.get("role", "user"), "content": h.get("content", "")})
|
| 31 |
+
|
| 32 |
+
messages.append({"role": "user", "content": task})
|
| 33 |
+
|
| 34 |
+
await self.emit_chat(session_id, "stream_start", {"agent": "ChatAgent", "status": "generating"})
|
| 35 |
+
|
| 36 |
+
response = await self.llm(messages, task_id=task_id, session_id=session_id)
|
| 37 |
+
|
| 38 |
+
await self.emit_chat(session_id, "stream_end", {
|
| 39 |
+
"agent": "ChatAgent",
|
| 40 |
+
"full_response": response,
|
| 41 |
+
"status": "complete",
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
return response
|