huronvalley21 commited on
Commit
9fceda9
·
verified ·
1 Parent(s): b17c3a1

Upload mythos/message.py

Browse files
Files changed (1) hide show
  1. mythos/message.py +48 -0
mythos/message.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Message passing system for Mythos agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+ from datetime import datetime, timezone
7
+ from enum import Enum
8
+ from typing import Any, Optional
9
+
10
+ from pydantic import BaseModel, Field
11
+
12
+
13
+ class MessageType(str, Enum):
14
+ """Types of messages agents can exchange."""
15
+
16
+ TASK = "task" # A task to be performed
17
+ RESPONSE = "response" # Result of a task
18
+ QUERY = "query" # Information request
19
+ BROADCAST = "broadcast" # Message to all agents
20
+ SYSTEM = "system" # System-level message
21
+ MEMORY = "memory" # Memory update/retrieval
22
+
23
+
24
+ class Message(BaseModel):
25
+ """A typed message exchanged between agents in a Pantheon."""
26
+
27
+ id: str = Field(default_factory=lambda: str(uuid.uuid4()))
28
+ type: MessageType
29
+ sender: str # Agent name or "system"
30
+ recipient: str # Agent name or "broadcast"
31
+ content: str
32
+ metadata: dict[str, Any] = Field(default_factory=dict)
33
+ timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
34
+ parent_id: Optional[str] = None # For threading/replies
35
+ priority: int = 5 # 1 (highest) to 10 (lowest)
36
+
37
+ def reply(self, content: str, msg_type: MessageType = MessageType.RESPONSE) -> Message:
38
+ """Create a reply message."""
39
+ return Message(
40
+ type=msg_type,
41
+ sender="", # Will be set by the agent
42
+ recipient=self.sender,
43
+ content=content,
44
+ parent_id=self.id,
45
+ )
46
+
47
+ def __str__(self) -> str:
48
+ return f"[{self.type.value.upper()}] {self.sender} -> {self.recipient}: {self.content[:80]}"