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

Method receive

tutorials/13_multi_agent_coordination.py:226–244  ·  view source on GitHub ↗

接收(并清空)收件箱中的所有消息。

(self, agent_name: str)

Source from the content-addressed store, hash-verified

224 json.dump(messages, f, ensure_ascii=False, indent=2)
225
226 def receive(self, agent_name: str) -> list[AgentMessage]:
227 """
228 接收(并清空)收件箱中的所有消息。
229 """
230 inbox_path = self._inbox_path(agent_name)
231 if not os.path.exists(inbox_path):
232 return []
233
234 with open(inbox_path, "r") as f:
235 try:
236 raw_messages = json.load(f)
237 except json.JSONDecodeError:
238 return []
239
240 # 清空收件箱
241 with open(inbox_path, "w") as f:
242 json.dump([], f)
243
244 return [AgentMessage.from_dict(m) for m in raw_messages]
245
246 def peek(self, agent_name: str) -> int:
247 """查看收件箱中有多少消息(不取出)"""

Callers 2

process_messagesMethod · 0.80
collect_resultsMethod · 0.80

Calls 3

_inbox_pathMethod · 0.95
loadMethod · 0.45
from_dictMethod · 0.45

Tested by

no test coverage detected