MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / MeshGraph

Class MeshGraph

masfactory/components/composed_graph/mesh_graph.py:21–154  ·  view source on GitHub ↗

Multi-agent mesh composite component with round-robin discussion. A composite component that creates a Loop with multiple agents taking turns responding in round-robin order. Uses standard masfactory components internally.

Source from the content-addressed store, hash-verified

19
20
21class MeshGraph(Loop):
22 """Multi-agent mesh composite component with round-robin discussion.
23
24 A composite component that creates a Loop with multiple agents taking turns
25 responding in round-robin order. Uses standard masfactory components internally.
26 """
27
28 def __init__(
29 self,
30 name: str,
31 agents: list[NodeTemplate],
32 model: Model,
33 graph_instructions: str = "",
34 max_iterations: int = 10,
35 shared_memory: HistoryMemory | None = None,
36 terminate_condition_function: Callable | None = None,
37 pull_keys: dict | None = None,
38 push_keys: dict | None = None,
39 attributes: dict | None = None,
40 ):
41 """Create a MeshGraph composite component.
42
43 Args:
44 name: Name of this mesh graph.
45 agents: List of Agent NodeTemplates to include in the mesh.
46 model: Model adapter for agents.
47 graph_instructions: Shared instructions prepended to all agents.
48 max_iterations: Maximum number of loop iterations.
49 shared_memory: Optional shared HistoryMemory. Auto-created if None.
50 terminate_condition_function: Custom termination predicate.
51 pull_keys: Attribute pull rule for this loop.
52 push_keys: Attribute push rule for this loop.
53 attributes: Initial loop attributes.
54 """
55 self._agent_templates = agents
56 self._model = model
57 self._graph_instructions = graph_instructions
58
59 # Create shared memory if not provided
60 self._shared_memory = shared_memory or HistoryMemory(top_k=100, memory_size=100)
61
62 # Extract agent names
63 self._agent_names = [
64 tpl.prototype_config.get("role_name", f"agent_{i}")
65 for i, tpl in enumerate(agents)
66 ]
67
68 # Default termination: check for "FINAL ANSWER"
69 if terminate_condition_function is None:
70 terminate_condition_function = self._default_terminate_condition
71
72 super().__init__(
73 name=name,
74 max_iterations=max_iterations,
75 terminate_condition_function=terminate_condition_function,
76 pull_keys=pull_keys,
77 push_keys=push_keys,
78 attributes=attributes,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected