MCPcopy Create free account
hub / github.com/Louisym/MiniCC / AgentMessage

Class AgentMessage

tutorials/13_multi_agent_coordination.py:126–155  ·  view source on GitHub ↗

Agent 间传递的消息

Source from the content-addressed store, hash-verified

124
125@dataclass
126class AgentMessage:
127 """Agent 间传递的消息"""
128 from_agent: str
129 to_agent: str
130 msg_type: MessageType
131 content: str
132 timestamp: float = 0.0
133
134 def __post_init__(self):
135 if self.timestamp == 0.0:
136 self.timestamp = time.time()
137
138 def to_dict(self) -> dict:
139 return {
140 "from": self.from_agent,
141 "to": self.to_agent,
142 "type": self.msg_type.value,
143 "content": self.content,
144 "timestamp": self.timestamp,
145 }
146
147 @staticmethod
148 def from_dict(data: dict) -> "AgentMessage":
149 return AgentMessage(
150 from_agent=data["from"],
151 to_agent=data["to"],
152 msg_type=MessageType(data["type"]),
153 content=data["content"],
154 timestamp=data.get("timestamp", 0.0),
155 )
156
157
158# ============================================================

Callers 4

from_dictMethod · 0.85
process_messagesMethod · 0.85
assign_taskMethod · 0.85
shutdown_allMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected